Why regionprops didn't work?

21 views (last 30 days)
Andrea Vezzoli
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
John BG
John BG on 25 Dec 2016
please make the image available by attaching it to your question

Sign in to comment.

Accepted Answer

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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!