Why regionprops didn't work?

11 Ansichten (letzte 30 Tage)
Andrea Vezzoli
Andrea Vezzoli am 25 Dez. 2016
Bearbeitet: Walter Roberson am 26 Dez. 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 Kommentar
John BG
John BG am 25 Dez. 2016
please make the image available by attaching it to your question

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 25 Dez. 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);

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by