MATLAB: Regionprops didn’t work

image processingImage Processing Toolboxregionprops

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

Best Answer

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);