Hating this ->"Subscripted assignment dimension mismatch"
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I have two (or more) images and I need to know if the element that I fond in the first image is the same element of the next image (they are greyscale images). I've decided work using "corr2", but I need two matrix with the same size, so, I do an example (a short example) to see how can I compare an element too small with another bigger, and I think this:
function sameobject
A=imread('1.bmp');
A=A(:,:,1);
Abin=im2bw(A);
B=imread('3.bmp');
B=B(:,:,1);
Bbin=im2bw(B);
arrayA=regionprops(Abin,A,{'Image'});
arrayB=regionprops(Bbin,B,{'Image'});
imagenA=arrayA(1).Image;
% imshow(imagenA);
imagenB=arrayB(1).Image;
% figure, imshow(imagenB)
[rowsA,columnsA]=size(imagenA);
[rowsB,columnsB]=size(imagenB);
%I chose matrixB like an example (it's bigger)
matrizcerostamaB=zeros(rowsB,columnsB);
[rowsmatrizceros,columnsmatrizceros]=size(matrizcerostamaB);
firstrow=(rowsB/2)-(rowsA/2);
lastrow=(rowsB/2)+(rowssA/2);
firstcolumn=(columnsB/2)-(columnsA/2);
lastcolumn=(columnsB/2)+(columnsA/2);
%redondeo
firstrow=floor(firstrow);
firstcolumn=floor(firstcolumn);
lastrow=floor(lastrow);
lastcolumn=floor(lastcolumn);
matrizcerostamaB(firstrow:lastrow,firstcolumn:lastcolumn)=imagenA;
figure,imshow(matrizcerostamaB);
(I translate the name of the variables here to simplify...)
When I execute the code in Matlab, always have the same error:
Subscripted assignment dimension mismatch.
Error in sameobject (line 45)
matrizcerostamaB(firstrow:lastrow,firstcolumn:lastcolumn)=imagenA;
But I don't know why, the numbers to calculate sizes are ok, could you help me? Thank you very much
0 Commenti
Risposte (3)
Image Analyst
il 9 Ott 2014
What do you mean by element? Do you mean some object or region in the image? Or do you mean an array element, meaning a pixel value? What does the matrizcerostamaB() function do?
2 Commenti
Image Analyst
il 10 Ott 2014
Modificato: Image Analyst
il 10 Ott 2014
First of all you want to crop out the template from the second image. It doesn't matter if it's exactly the same size as its counterpart in the first image or not. Then use normxcor2() which is normalized cross correlation to see if that template exists in the first image, like in the attached demo. It can handle translation but not scaling and rotation of the template so if the template is (de)magnified or rotated then it's different and won't be found, which is what you'd expect because they are different. But for just a simple copy/paste type of replication, it works great. You need to use that because correlation won't work.
It's a common misperception that simple correlation will find templates in larger scenes , and I think I might have given a proof a long time ago here with some demo code disproving that. Simple correlation with xcorr2 is just the sum of the pixel products at each window position, while normalized cross correlation is like the average of the percentage matches for each pixel in the window.
Star Strider
il 9 Ott 2014
Your subscripts may not be doing what you believe they are doing.
Experiment with:
SZ = size(zeros(firstrow:lastrow,firstcolumn:lastcolumn))
SA = size(imagenA)
and see if there is a difference.
2 Commenti
Star Strider
il 10 Ott 2014
I apologise for the misstatement.
What I intended is:
SZ = [size(firstrow:lastrow,2); size(firstcolumn:lastcolumn,2)];
Those will tell you what the row and column sizes of your subscript ranges are. Compare them with ‘SA’ to see if they match the size of your image.
Thorsten
il 10 Ott 2014
matrizcerostamaB(firstrow:firstrow+rowA-1,firstcolumn:firstcolumn+columnA-1)=imagenA;
2 Commenti
Iain
il 10 Ott 2014
Before you call that line, check what firstrow, rowA, firstcolumn & columnA are, and check that the sums are being done in the order they're meant to be in.
I.e. if firstrow is 1, rowA is 10, then firstrow:... should give the result [1 2 3 4 5 6 7 8 9 10]
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!