开发者

Color Comparison of two images using matlab

Is it possible to compare the color of two images using Matlab if the two images are of different sizes?The problem that am facing is that, i want to detect the presence o开发者_运维百科f a colored patch in an image?


You could just compare normalized histograms (i.e., like a color probability distribution). If the large and small images are semantically identical, then their normalized histograms are similar.

If they are semantically different, then their histograms will likely differ.


Do you have the image processing toolbox? If so, you might approach the problem by taking the images, splitting them into their component color channels, resizing the individual channels, and re-assembling them into resized color images. I wrote a program to do that a while ago, and I recall the code looking something like this:

function imout = ResizeRGB(imin,height,width)
imout = zeros(height,width,3);

iminR = imin(:,:,1);
iminG = imin(:,:,2);
iminB = imin(:,:,3);

imoutR = imresize(iminR, [height width]);
imoutG = imresize(iminG, [height width]);
imoutB = imresize(iminB, [height width]);

imout(:,:,1) = imoutR;
imout(:,:,2) = imoutG;
imout(:,:,3) = imoutB;

(Since I don't have the IPT handy at the moment, that program should be considered pseudocode even though it's more or less in correct matlab syntax. I can't run it without the IPT, so I can't tell if it's buggy or not.)

Once you resize the images so that they have common dimensions, the problem becomes identical to the problem of comparing colors for two images of equal dimensions.

On the other hand, if you have a picture of the patch and a picture that may contain the patch, you might consider using a binary mask to threshold the results of a cross-correlation (xcorr2 in the IPT). For more information on that approach, there's a tutorial on the MathWorks website: http://www.mathworks.com/products/demos/image/cross_correlation/imreg.html


This would be a bit crude, but you could crop your images to the minimum common size if this will be sufficient for your application:

A = imread("image1.jpg");
B = imread("image2.jpg");

rows = min(size(A,1), size(B,1));
cols = min(size(A,2), size(B,2));

croppedA = A(1:rows, 1:cols, :);
croppedB = B(1:rows, 1:cols, :);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜