Hating this ->"Subscripted assignment dimension mismatch"

4 visualizaciones (últimos 30 días)
Maria
Maria el 9 de Oct. de 2014
Comentada: Star Strider el 10 de Oct. de 2014
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

Respuestas (3)

Image Analyst
Image Analyst el 9 de Oct. de 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 comentarios
Maria
Maria el 10 de Oct. de 2014
I mean some object (or region), sorry. The matrizcerostamaB give a black image with the same size of the biggest image and I want to put (or to paste, I don't know how can I say it) the smallest in, so I could use "corr2" to compare.
Image Analyst
Image Analyst el 10 de Oct. de 2014
Editada: Image Analyst el 10 de Oct. de 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.

Iniciar sesión para comentar.


Star Strider
Star Strider el 9 de Oct. de 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 comentarios
Maria
Maria el 10 de Oct. de 2014
I can't do this, but I think that they have the same size..
Error using zeros
Size inputs must be scalar.
Error in mismoobjeto (line 42)
SZ = size(zeros(firstrow:lastrow,firstcolumn:lastcolumn))
Star Strider
Star Strider el 10 de Oct. de 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.

Iniciar sesión para comentar.


Thorsten
Thorsten el 10 de Oct. de 2014
matrizcerostamaB(firstrow:firstrow+rowA-1,firstcolumn:firstcolumn+columnA-1)=imagenA;
  2 comentarios
Maria
Maria el 10 de Oct. de 2014
I did this before, and I do now again, but I've got the same error, "Subscripted assignment dimension mismatch." And I stil don't know why.
Iain
Iain el 10 de Oct. de 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]

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by