How to find the coordinate defect location in image any document to refer? Please help I am fyp student in mechanical engineering

2 ビュー (過去 30 日間)
clc
clear
close all
warning off;
x=imread('origin.jpg');
y=imread('capture.jpg');
diffImage = imabsdiff(x, y);
threshold = 5;
mask = diffImage >= threshold;
imshow(mask)
props = regionprops(mask, 'Area')
allAreas = [props.Area]
if ~isempty(props)
fprintf('Found %d defect areas.\n', length(props))
else
fprintf('Found no defect areas.\n')
end

採用された回答

DGM
DGM 2022 年 2 月 25 日
I'm going to assume that the attached image is the mask derived from x and y.
[mask map] = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/906590/image.png');
mask = rgb2gray(ind2rgb(mask,map))>0.5;
props = regionprops(mask, 'Area','centroid'); % you can get both
allAreas = [props.Area] % row vector of areas
allAreas = 1×2
275 86
allCentroid = vertcat(props.Centroid) % Mx2 array of centroids [x y]
allCentroid = 2×2
74.4255 107.2582 112.9884 258.4186
imshow(mask); hold on
plot(allCentroid(:,1),allCentroid(:,2),'kx') % mark the centroids
% same as before
if ~isempty(props)
fprintf('Found %d defect areas.\n', length(props))
else
fprintf('Found no defect areas.\n')
end
Found 2 defect areas.
  3 件のコメント
Image Analyst
Image Analyst 2022 年 2 月 25 日
@CHEE HOON SEOW then you should definitely check out my Image Segmentation Tutorial in my File Exchange.
CHEE HOON SEOW
CHEE HOON SEOW 2022 年 2 月 25 日
Thank you for reply appreaciate it.
I will read thought and understand the function code apply in the image segmentation tutorials.
Agains thanks for sharing

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by