Reputation: 17
I was trying to turn a set of images to 2D grayscale image in order to do Surf feature extraction. In the set, some of the images are already in 2D scale so when I tried to run a loop. This error message happens: MAP must be a m x 3 array.
Here is my code:
for ii=1:numImages
img = readimage(imdsTrain,ii);
RGB = rgb2gray(img)
points = detectSURFFeatures(RGB);
[surf1, valid_points] = extractFeatures(RGB, points);
figure; imshow(RGB); hold on;
plot(valid_points.selectStrongest(10),'showOrientation',true);
title ('Ct-scan image with Surf feature')
end;
Is there any solution that can solve this problem?
Upvotes: 0
Views: 85
Reputation: 4164
Matlab's rgb2gray will fail if you give it a grayscale image (an image with only one color channel).
If you are sure that your images are either m x n X 3 or m x n x 1, you could check for the m x n x 3 case before attempting to do the rgb2gray. If your image is already a grayscale image no conversion is needed or can be done via rgb2gray.
Something like this:
img = readimage(imdsTrain,ii);
[rows, columns, colors] = size(img)
if colors > 1
RGB = rgb2gray(img)
end
Now getting the error MAP must be a m x 3 array suggests that whatever you supplied rgb2gray got interpreted as a colormap. So I would check if all your images are indeed three dimensions, as you are assumimg.
Upvotes: 1