Comparing 2 images by subtracting pixels and what happen if rgb values goes negative?

5 views (last 30 days)
Hi,
I am wondering how do you go about comparing the pixels of each images with subtraction and return the image with higher pixel difference. If subtraction works but rgb values goes negative, will it just display a black screen?
  2 Comments
Gul Rukh Khan
Gul Rukh Khan on 8 Dec 2019
I wrote a code for the same, but still with a problem.
i have 10x10 matrix image.
for x=1:9
for y=1:9
r (x,y) = (aa(x,y)-(aa(x,y+1)));
x=x+1;
end
end
Image Analyst
Image Analyst on 8 Dec 2019
Gul, matrices and images are indexed (y, x), not (x,y). And you should not assign x to something when x is being assigned by the for statement. Start a new question if you still need help.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 5 Feb 2012
dhrye:
OK, look at your code very carefully:
image2 = 'image2.jpg';
% Display it.
imread(image2);
Now, does that look like how I told you to fix it? (Which is below)
image2 = imread('image2.jpg');
imshow(image2);
No, it does not. You're not displaying it because imread reads it in from a disk file, it does not display it in an axes like imshow does. And you're still having image2 be a character string despite me telling you to set it equal to the output of imread. Correct it and try again.
  3 Comments
Image Analyst
Image Analyst on 5 Feb 2012
Come on, you know better that that by now. You must copy and paste the actual red text error message. What you said is paraphrased. All I can say is that you're doing something unknown operation with some unknown images where the sizes of the images aren't the same.
dhrye
dhrye on 5 Feb 2012
alright. matlab's new to me and i really suck at programming. Thanks for the advice.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 4 Feb 2012
If you subtract one uint8() value from another uint8() value, and the result would abstractly be 0, then the uint8() data type will "saturate" the negative values to 0 (e.g., black on a grayscale image.)
If you convert the pixels to double precision before you do the subtraction, then the double precision result for any one pixel can be negative.
I do not think I quite understand what you mean about returning the image with the higher pixel difference?
Consider two cases. In the first case, the two images are exactly the same except that one pixel is 255 different than the other (e.g., a spot of white compared to a spot of black.) The total pixel difference would be 255 since the difference for all the other pixels is 0 (under the assumption that they are exactly the same.) Now in the second case, the two images are exactly the same except that 256 pixels differ by exactly 1 -- pretty much invisible if those pixels are scattered around. The total pixel difference would be 256 * 1 = 256 (under the assumption that they are exactly the same.) Now, which case has the higher pixel difference? The first case with its big 255 difference in one place, or the second because its total 256 invisible differences add up to more?
  14 Comments
YK Toh
YK Toh on 4 Jan 2013
dhrye, i am trying your code...got errors as below..not really understnad with this error, Pls help...tq~
Error using image Error using image Numeric or logical matrix required for image CData
Walter Roberson
Walter Roberson on 4 Jan 2013
What point is it happening at for you? The array that it is complaining about, what does class() of it show ?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!