Hi, I am the beginer for doing simple image subtration to obtain defect image. Is it possible to make it only show the defect image if nothing difference wont show?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
CHEE HOON SEOW
le 15 Jan 2022
Commenté : Image Analyst
le 24 Jan 2022
clc
clear
close all
warning off;
x=imread('origin.jpg');
y=imread('capture.jpg');
[g, c, d]=size(x);
y=imresize(y,[g,c]);
subplot(1,3,1);
imshow(x);
title('origin image');
subplot(1,3,2);
imshow(y);
title('capture image');
subplot(1,3,3);
imshow(x-y);
title('defect occur if difference colour shown');

0 commentaires
Réponse acceptée
yanqi liu
le 17 Jan 2022
yes,sir
Is it possible to make it only show the defect image if nothing difference wont show?
may be add some judge rule,such as
clc
clear
close all
warning off;
x=imread('origin.jpg');
y=imread('capture.jpg');
[g, c, d]=size(x);
y=imresize(y,[g,c]);
subplot(1,3,1);
imshow(x);
title('origin image');
subplot(1,3,2);
imshow(y);
title('capture image');
bw = find((x-y) > 1);
if numel(bw) > 1
subplot(1,3,3);
imshow(x-y);
title('defect occur if difference colour shown');
end
2 commentaires
Plus de réponses (1)
Image Analyst
le 17 Jan 2022
I suggest you use imabsdiff().
diffImage = imabsdiff(x, y);
threshold = 5; % Images must be at least 5 gray levels different to be considered a defect.
mask = diffImage >= threshold;
imshow(mask)
% Get area of defects
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
7 commentaires
Image Analyst
le 24 Jan 2022
You keep forgetting to attach your original images. I'll check back tomorrow.
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!