Info

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

Error: Subscripted assignment dimension mismatch

1 view (last 30 days)
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 Comment
KSSV
KSSV on 1 Nov 2017
What is size of blobMeasurementsHue.Centroid and value of numberOfBlobs..?

Answers (2)

Mary Abbott
Mary Abbott on 3 Nov 2017
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 on 3 Nov 2017
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!