Subtract average image from a series of images

N
N B · Jan 18, 2022 · 1.9K views
Question
I'm having some difficulty subtracting an averaged image from a series of images from which the average was obtained. The images have been obtained from a MP4 video file.   This is what i have done:   Ven23 = VideoReader('MyVideo23.MP4'); %Read in the video file Ven23frame1 = read(Ven23,1); % Read in the first frame of the video sumImage23 = im2double(Ven23frame1); %Double the accuracy of the frame for i=2:30 Ven23Frames= read(Ven23,i); sumImage23 = sumImage23 + im2double(Ven23Frames); end avgVen23= imshow(sumImage23/30); This all seems to work; I get an image which looks like the average. However, whenever I try to subtract this average image from any particular frame from the video I get this error: Undefined operator '-' for input arguments of type 'matlab.graphics.primitive.Image'.   Then I tried to save the average image and frames as bmp files, load them back in and subtract them. Doing this just returns a black screen. I also tried doubling the accuracy of the reloaded images to no avail.     I'm obviously doing something wrong and I would be grateful if anyone could point it out to me. Thanks.
Expert Answer
Profile picture of John Michell
John Michell PhD Expert
Answered Aug 30, 2026
In view of the error, I would suspect that you're trying to subtract your mean image from a variable called exactly image. Unfortunately, at the point where you're doing the subtraction, the variable image does not exist, so instead matlab calls the function image which returns an object of type 'matlab.graphics.primitive.Image'. Subtraction is not defined for that (a graphics object), hence the error message. At the same time, you probably have an upside down picture of a boy's head popping up in a figure.
 
 
In conclusion:
 
  1. you have a bug in that you're using a variable you've never defined. Can't help you more, since you didn't show that part of the code.
  2. do not name your variable image
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!