MATLAB Answers


How to subtract two images in matlab?

I have couple of images below which I want to subtract from each other. The images are taken from the same sample at different time frames. I want to notice the movement of the particles between those time frames. So I want to take out the part of the image that only contains the liquid particles. I want to subtract INTENSITY14.JPG from INTENSITY15.JPG. Ideally, the resultant image should look like SUBTRACT.JPG where the red dased box shows the part of the image which contains the liquid. But, I am getting the result as shown in S1.jpg which is undesirable. Below is my code. Any suggestions would be very much appreciated. Thank you.
a = imread('Intensity15.jpg');
b = imread('Intensity14.jpg');
dblSubtractedImage = double(a) - double(b);
imshow(dblSubtractedImage, []);

  댓글 수: 0

로그인 to comment.




답변 수: 1

 채택된 답변

Your code is successfully subtracting the two images. The reason your subtraction looks like that is because your two images are so closely correlated that whatever is left after subtraction is mostly noise. How did you get SUBTRACT.jpg? I don't see how you could get an image like that from subtracting a and b.

  댓글 수: 3

Hi Benjamin,
I found subtract.jpg by analyzing both the images manually, i.e. by repeatedly switching the images using the key board and noticing any changes. The red dashed box is the part of the image that changes when I carefully analyze both the images. I wanted to identify these changes using MATLAB where the change would be automatically detected and would be cropped into a separate image. Subtracting images is just a process that came on my mind. Is there any other way by which I can obtain the desired result? Thank you.
I see what you mean. The images are a bit different. Theoretically subtracting them should show that. Converting a and b to double makes the display look oversaturated. If you replace the last two lines with these lines:
dblSubtractedImage = (a) - (b);
The difference comes out a little more between the sections. I attached a figure. If I was doing showing the difference quantitatively, I might make a 2d pot that shows the correlation between each row of the two images. Something like this:
for i=1:650
or maybe if you want to correlate 10 rows at a time
for i=1:65
Hi Benjamin,
That helps a lot. Thank you.

로그인 to comment.

Translated by