Info

此问题已关闭。 请重新打开它进行编辑或回答。

doubt regards of centroid

1 次查看(过去 30 天)
ajith
ajith 2013-8-22
关闭: MATLAB Answer Bot 2021-8-20
originalImage = imread('result1.png');
%originalImage=rgb2gray(originalImage);
binaryImage = originalImage>200;
labeledImage = bwlabel(binaryImage, 8);%labeled 0 as background & 1 as object
%D=regionprops(labeledImage,'all');
D=regionprops(labeledImage,'Centroid');
save('data.mat', 'D');
imshow(originalImage);
hold on;
but D shows the 40x1 struct in that centroid the all values of the centroid is different one by one how to find the correct centroid %plot(D); and also divide the 60degrees each how its possible sir

回答(2 个)

Laurent
Laurent 2013-8-22
It seems that your labeledImage contains 40 different objects. All of those objects will have a centroid and that's why you get a 40x1 struct.
To see if this is the case use
[labeledImage,NUM]=bwlabel(binaryImage, 8);
NUM will be the number of objects found.
What you can do is lower your threshold (200 in this case) so that you have only one object.
It all depends on what is exactly in your image, but if your object has values > 0 and every other pixel is 0, you could do
binaryImage = OriginalImage>0;
If you want a more specific answer, please show us your image.

Image Analyst
Image Analyst 2013-8-22
Try this, using the image you uploaded:
% Read in a standard MATLAB gray scale demo image.
folder = 'd:\Temporary stuff'; % You need to change this!!!!
baseFileName = '7_result1.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
grid on;
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
binaryImage = grayImage < 255;
% Display the original gray scale image.
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
measurements = regionprops(binaryImage, 'Centroid');
centroid = [measurements.Centroid]
% Plot a cross there.
hold on;
plot(centroid(1), centroid(2), 'r+', ...
'MarkerSize', 25, 'LineWidth', 3);
message = sprintf('The centroid is at (x,y) = (%.2f, %.2f)',...
centroid(1), centroid(2));
uiwait(msgbox(message));
  6 个评论
ajith
ajith 2013-9-4
sir how its possible to generate the 6 different binary images i need to divide that using the centroid point. would you please explain in example its most useful for me. Thank you sir for your kind replay
Image Analyst
Image Analyst 2013-9-4
编辑:Image Analyst 2013-9-4
I'll show you how to mask but I think you can do the 10th grade geometry to get the x and y coordinates of the sector yourself, right? The FAQ might help.
[rows, columns] = size(originalBinaryImage);
mask = poly2mask(x, y, rows, columns); % Pie shaped 60 degree sector.
binaryImageSingleSector = originalBinaryImage; % Initialize
binaryImageSingleSector(~mask) = false;
measurements = regionprops(binaryImageSingleSector);

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by