Detect Shape in Image and How many times shapes come in Image

5 次查看(过去 30 天)
Hello Everyone, I hope you are doing well.
I have the following image i want to detect the shape in the image and count how many time shapes exist for example in image im_003002 (1) The peroidic shape which comes six time, i want to detect the shape and show the shapes exist 6 time in the image. similarly in im_005001 (1) the shapes comes 7 times
Can any body help me in this please

回答(1 个)

Image Analyst
Image Analyst 2022-3-27
Did you try bwlabel()? If mask is the second image with the slanted lines:
[labeledImage, count] = bwlabel(mask);
  7 个评论
Image Analyst
Image Analyst 2022-3-28
Here is my code with your image. You can see there are 7 regions.
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = pwd;
baseFileName = 'im_005001 (1).png';
% baseFileName = 'image_2732.png';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, '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
rgbImage = imread(fullFileName);
% 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(rgbImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
fprintf('It is not really gray scale like we expected - it is color\n');
% Extract the blue channel.
grayImage = rgbImage(:, :, 3);
else
grayImage = rgbImage;
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 1, 1);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
drawnow;
%--------------------------------------------------------------------------------------------------------
% Binarize the image to get a mask.
mask = imbinarize(grayImage);
% Display mask image.
subplot(2, 1, 2);
imshow(mask);
hold on;
impixelinfo;
axis('on', 'image');
drawnow;
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Count the number of slanted regions.
[labeledImage, numRegions] = bwlabel(mask);
% Tell the user
message = sprintf('Number of regions = %d', numRegions);
title(message, 'FontSize', fontSize, 'Interpreter', 'None');
uiwait(helpdlg(message))
Med Future
Med Future 2022-3-31
@Image Analyst Its not working on second image, I want it to work for the second image eg im_003002 (1)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by