Hating this ->"Subscripted assignment dimension mismatch"

4 ビュー (過去 30 日間)
Maria
Maria 2014 年 10 月 9 日
コメント済み: Star Strider 2014 年 10 月 10 日
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

回答 (3 件)

Image Analyst
Image Analyst 2014 年 10 月 9 日
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 件のコメント
Maria
Maria 2014 年 10 月 10 日
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 2014 年 10 月 10 日
編集済み: Image Analyst 2014 年 10 月 10 日
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
Star Strider 2014 年 10 月 9 日
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 件のコメント
Maria
Maria 2014 年 10 月 10 日
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 2014 年 10 月 10 日
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
Thorsten 2014 年 10 月 10 日
matrizcerostamaB(firstrow:firstrow+rowA-1,firstcolumn:firstcolumn+columnA-1)=imagenA;
  2 件のコメント
Maria
Maria 2014 年 10 月 10 日
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 2014 年 10 月 10 日
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]

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by