Why regionprops didn't work?
21 views (last 30 days)
Show older comments
Andrea Vezzoli
on 25 Dec 2016
Edited: Walter Roberson
on 26 Dec 2016
Hi all,
I want to use regionprops function to detect a hole inside a grayscale image I wrote this code:
I=imread('nameimg')
I=im2bw(I)
g=regionprops(I,'centroid')
Why this code make this error:"Too many input argument"??????
Thanks all
1 Comment
Accepted Answer
Image Analyst
on 25 Dec 2016
Try this
grayImage = imread('nameimg.png');
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
binaryImage = im2bw(grayImage);
[labeledImage, numBlobs] = bwlabel(grayImage);
props = regionprops(labeledImage,'Centroid')
allCentroids = [props.Centroid];
xCentroids = allCentroids(1:2:end);
yCentroids = allCentroids(2:2:end);
See my tutorial for a full demo: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!