Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

The program is not working in the same way for all images...(

1 view (last 30 days)
hi. I am doing a project on matlab.steps are' 1. Two images are given. they are A and B. 2. It needs dividing the given images to 4 blocks 3. Comparing the different blocks of A and B. i hav written the following program for that. but they are not working in the same way for all the images. And dividing in to blocks is also different in different case. wats the proble, ?
function crop_to_blocks
a=imread('img1.tif'); a=imcrop(a,[0 0 800 800]); [r,c]=size(a); if (rem(r,2)==0) && (rem(c,2)==0);
block11=imcrop(a,[0 0 r/2 c/2]);
block12=imcrop(a,[0 c/2 r/2 c/2]);
block13=imcrop(a,[r/2 0 r/2 c/2]);
block14=imcrop(a,[r/2 c/2 r/2 c/2]);
subplot(2,2,1);imshow(block11);subplot(222);imshow(block13);subplot(223);imshow(block12);subplot(224);imshow(block14);
figure,imshow(a);
else
croped=imcrop(a,[0 0 r-1 c-1]);
[r,c]=size(croped);
block11=imcrop(a,[0 0 r/2 c/2]);
block12=imcrop(a,[0 c/2 r/2 c/2]);
block13=imcrop(a,[r/2 0 r/2 c/2]);
block14=imcrop(a,[r/2 c/2 r/2 c/2]);
subplot(2,2,1);imshow(block11);subplot(222);imshow(block13);subplot(223);imshow(block12);subplot(224);imshow(block14);
end b=imread('img3.tif'); b=imcrop(b,[0 0 800 800]); a=b; [r,c]=size(a); if (rem(r,2)==0) && (rem(c,2)==0);
block21=imcrop(a,[0 0 r/2 c/2]);
block22=imcrop(a,[0 c/2 r/2 c/2]);
block23=imcrop(a,[r/2 0 r/2 c/2]);
block24=imcrop(a,[r/2 c/2 r/2 c/2]);
subplot(2,2,1);imshow(block21);subplot(222);imshow(block23);subplot(223);imshow(block22);subplot(224);imshow(block24);
%figure,imshow(a);
else
croped=imcrop(a,[0 0 r-1 c-1]);
[r,c]=size(croped);
block21=imcrop(a,[0 0 r/2 c/2]);
block22=imcrop(a,[0 c/2 r/2 c/2]);
block23=imcrop(a,[r/2 0 r/2 c/2]);
block24=imcrop(a,[r/2 c/2 r/2 c/2]);
subplot(2,2,1);imshow(block21);subplot(222);imshow(block23);subplot(223);imshow(block22);subplot(224);imshow(block24);
end
if (block11==block21)
if (block12==block22)
if (block13==23)
if (block14==block24);
end
end
end
disp('NO_DIFFERENCE');
else
disp('NOT_MATCHED');
end
end

Answers (1)

Walter Roberson
Walter Roberson on 20 Mar 2011
You need to describe the difference between what you expect to see and what you actually see. If you are getting error messages, post copies of them and the sizes of all of the relevant variables. If your results do not match what you expect, then upload your images and your results and a drawing of what you do expect to an image-sharing site and post the links.
  1 Comment
Walter Roberson
Walter Roberson on 21 Mar 2011
Emailing me another copy of the program does not help: I can read the source here. Making copies of the images available would help.
I suspect that your problem is that one of your images is an indexed or grayscale image, and that the other image is an RGB (truecolor) image. When you take the size() of a 3 dimensional matrix and try to return the value in to just two variables (because you are expecting only rows and columns), the last output variable gets assigned a value which is the product of the sizes of all the remaining dimensions.

This question is closed.

Community Treasure Hunt

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

Start Hunting!