필터 지우기
필터 지우기

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

조회 수: 2 (최근 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 CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by