Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Error: Subscripted assignment dimension mismatch

1 回表示 (過去 30 日間)
Tasneem Al-Tmimi
Tasneem Al-Tmimi 2017 年 11 月 1 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello, Am wondering if someone could help me in these lines ? Am working on an Image processing college project and I have these line to execute but it always shows the error above even I did the same thing for another part of the code and it works correctly
blobCentroid = zeros(numberOfBlobs,3);
blobCentroid(:,1) = [blobMeasurementsHue.Centroid]';
blobCentroid(:,2) = [blobMeasurementsSat.Centroid]';
blobCentroid(:,3) = [blobMeasurementsValue.Centroid]';
I can't check where is the exactly problem since it works with me for all other properties extracted from the
regionprops function
Where ,
blobMeasurementsHue = regionprops(labeledImage, hImage, 'all');
blobMeasurementsSat = regionprops(labeledImage, sImage, 'all');
blobMeasurementsValue = regionprops(labeledImage, vImage, 'all');
and the labeledImage is my segmented image, and hImage, sImage and vImage are my HSV Color space image separated.
  1 件のコメント
KSSV
KSSV 2017 年 11 月 1 日
What is size of blobMeasurementsHue.Centroid and value of numberOfBlobs..?

回答 (2 件)

Mary Abbott
Mary Abbott 2017 年 11 月 3 日
Hello,
The error indicates the dimensions of blobCentroid(:,1) and [blobMeasurementsHue.Centroid]', or one of the other assignments you are doing, are not the same. You can set a breakpoint at the line that is giving the error and, after execution stops at that line, use the "size" function to make sure the dimensions on both sides of the assignment match up.
size(blobCentroid(:,1))
size([blobMeasurementsHue.Centroid]')

Walter Roberson
Walter Roberson 2017 年 11 月 3 日
The Centroid property for each blob is a row vector of length (number of dimensions of input data) -- so for 2D arrays it would be a vector of length 2, for each blob; for 3D arrays it would be a vector of length 3.
[blobMeasurementsHue.Centroid]
pulls out those row vectors for each blob and does a horzcat() operation on them. That will get you a row vector (ndims * numblob) long. You then transpose that, getting a (ndims * numblob) column vector. You attempt to assign that into
blobCentroid = zeros(numberOfBlobs,3)
which is only numberOfBlobs long, not numberOfBlobs * ndims. It is not going to fit.
You should consider,
blobCentroid = zeros(numberOfBlobs, 2, 3);
blobCentroid(:,:,1) = horzcat(blobMeasurementsHue.Centroid);
I suggest, though, that you think a bit more about what you are calculating. When you use that form of regionprops, the locations of the blobs are determined by the first parameter, the labeled image, and the centroids are not going to change no matter what intensity values you pass in the second position. If you want the locations to change based on intensity values, you need to look at WeightedCentroid in which case the intensity at each point on the blob will act like a local mass -- so you would get like the "brightness center". Which, I would suggest to you, probably does not make any sense for Hue or Value, but maybe would have some meaning for Saturation. Hue is especially problematic for this, since Hue is like an angle, so hues "just before" 0 can have high hue values.

Community Treasure Hunt

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

Start Hunting!

Translated by