How can I compare the vector table values in matlab without using For loop?

I would like to compare pixel values of two images on vector table by converting them as black & with pictures. After executing simple code it turned out that all the pixel values had their range from 0(black) to around 256(white) and then I will subtract or compare of two corresponding pixels(which means in same location) to figure out how close each pixel value is between two images.
in order to make that code according to simple logic, it is clear than we can use 'for loop' for comparison. but it seems like the more we use 'for loop' in matlab code, the slower it becomes. therefore I just want to avoid 'for loop' if it is possible. is there any suggestion to implement this algorithm or code without 'for loop'??

1 Comment

Please use the standard upper/lower case, because it improves the readability. Thanks.
If you post your FOR-loop approach, we can suggest improvements much easier than after reading your text explanations.

Sign in to comment.

Answers (1)

Pixel values from 0 to 256 are unusual. 0 to 255 would be the UINT8 range.
I do not understand, what you exactly want. Do I understand correctly, that you have two gray-scale images of the same size and the type UINT8? And you want to determine the distance or the difference between the pixel values? Then:
img1 = uint8(rand(200, 100) * 255);
img2 = uint8(rand(200, 100) * 255);
difference = img1 - img2;
distance = abs(difference);

Categories

Find more on Scope Variables and Generate Names in Help Center and File Exchange

Asked:

seo
on 15 May 2013

Community Treasure Hunt

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

Start Hunting!