How could I extract a defect from a semiconductor image?

I have this image of a semiconductor wafer and it has a defect in it which I need to detect using Matlab. I should detect only it, and not its background. I need to also measure its perimeter and area.
So far I have this code where I convert the original image to a binary image and then use dilation on it and then try to get its contour. When getting the perimeter and the area, I receive the outcome not only for the defect, but also for the rest of the image, which is not what I want. How can I extract the defect only so I can get only its area and perimeter?
The image:
fig3 = imread('figure3.png');
imshow(fig3);
title('Original image', 'FontSize', 18);
% Gray image
fig3Gray = rgb2gray(fig3);
% Binary image
BW3 = imbinarize(fig3Gray,0.5);
imshow(BW3);
title('Binary image', 'FontSize', 18);
se3 = strel('square',5);
% Dilation image
dilated3 = imdilate(BW3,sr);
imshow(dilated3);
title('Dilated image', 'FontSize', 18);
minus3 = ~(BW3-dilated3);
imshow(minus3);
title('Contour image', 'FontSize', 18);
imshowpair(minus3,BW3,'montage');
% Perimeter and Area calculation
Coon3 = bwconncomp(~BW3)
ANS3 = length(Coon3.PixelIdxList{1});
OUTPUT3 = regionprops(Coon3,'Perimeter','Area');
P3 = OUTPUT3.Perimeter
Area3 = OUTPUT3.Area

4 Comments

Is that dark, near-circular blob considered as the defect?
Yes, this blob is the defect. Everything else is not needed.
What do you want to assume?
  1. That the defect is known to be in the upper half of the image?
  2. That the defect has a certain aspect ratio?
  3. That you have another, "perfect" image that you can compare this one to?
You have to make some assumptions as to what defines a defect.
I want to assume that the image is in the uppr central half of the image and it has perimter and area. I want to find them and I want to get rid of the background so only the defect stays. Could you help me with that?

Sign in to comment.

Answers (2)

May be edge detection, then morpho operation easier in this case
result=~edge(binary_image,'sobel');
123.png
Please see bwareaopen and bwareafilt functions, which may helps you.
Hope you can easily segmnet the well distinct region.
If, as you said, being dark and in the upper half of the image are your ONLY criteria, then the code below will find those blobs and measure their areas and perimeters.
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
%===============================================================================
% Read in a demo image.
folder = pwd
baseFileName = 'figure3.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
fprintf('This image is RGB. I will change it to gray scale.\n');
grayImage = grayImage(:, :, 2);
end
% Display the original image.
subplot(2, 2, 1);
imshow(grayImage);
axis('on', 'image');
caption = sprintf('Original Image : "%s"', baseFileName);
title(caption, 'FontSize', fontSize);
impixelinfo;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.1, 1, 0.9], ...
'Name', 'Demo by Image Analyst', 'NumberTitle', 'Off');
% Display the original image's histogram.
subplot(2, 2, 2);
imhist(grayImage);
grid on;
title('Histogram of Gray Scale Image', 'FontSize', fontSize);
% Get dark stuff only.
binaryImage = grayImage < 50;
% Display the binary image.
subplot(2, 2, 3);
imshow(binaryImage);
axis('on', 'image');
caption = sprintf('Binary Image');
title(caption, 'FontSize', fontSize);
% Make area measurements.
[labeledImage, numBlobs] = bwlabel(binaryImage);
props = regionprops(labeledImage, 'Area', 'Centroid', 'Perimeter');
allreas = [props.Area]
centroids = vertcat(props.Centroid);
xCentroids = centroids(:, 1);
yCentroids = centroids(:, 2);
% Find out which blobs have a centroid in the upper half of the image.
inUpperHalf = find(yCentroids < rows / 2);
% Extract only those blobs.
binaryImage = ismember(labeledImage, inUpperHalf);
% Now re-measure.
[labeledImage, numBlobs] = bwlabel(binaryImage);
props = regionprops(labeledImage, 'Area', 'Centroid', 'Perimeter');
allreas = [props.Area]
allPerimeters = [props.Perimeter]
centroids = vertcat(props.Centroid);
xCentroids = centroids(:, 1);
yCentroids = centroids(:, 2);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
subplot(2, 2, 4);
imshow(coloredLabelsImage);
axis('on', 'image');
caption = sprintf('Upper Half Defects');
title(caption, 'FontSize', fontSize);
0000 Screenshot.png

Categories

Asked:

on 28 Dec 2019

Answered:

on 28 Dec 2019

Community Treasure Hunt

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

Start Hunting!