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

3 ビュー (過去 30 日間)
Med Future
Med Future 2022 年 3 月 27 日
コメント済み: Med Future 2022 年 3 月 31 日
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
  2 件のコメント
KSSV
KSSV 2022 年 3 月 27 日
You have asked this question already.
Med Future
Med Future 2022 年 3 月 27 日
@KSSV, I can't get answer there that's why I asked again.

サインインしてコメントする。

回答 (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 Center および File ExchangeImage Processing Toolbox についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by