Segmenting a huge batch of images

5 Ansichten (letzte 30 Tage)
Swag Mane
Swag Mane am 4 Aug. 2021
Bearbeitet: Swag Mane am 1 Sep. 2021
I have a huge set of images taken from an SEM (a couple of thousands) and i want to automate the whole image processing...process: segmentation and extracting features are the main things to focus on right now.
The goal is to calculate the width of each ROI (i specified the ROI on the image). I count the number of pixels in each column for each ROI and divide by the scale to get the width per column.
Attached is a shitty example (i have even worse images) and my problem is of course with the shitty ones. The good images have nice histograms where you can easily differentiate between the regions just by looking at the histograms and a Otsu thresholding usually does the job. Some others have multimodal, overlapping or just a cluster#@$%. I don't know how to segment the areas when there are cracks, holes, scratches or anything similar. Sometimes the image looks tilted or upside down or the ROI has an L shape etc.
I am very new to image processing so explain like i'm 5.

Akzeptierte Antwort

Image Analyst
Image Analyst am 5 Aug. 2021
Try multithresh():
% 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 = 20;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
grayImage = imread('SampleDim.jpg');
% 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(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Extract the red channel (so the magenta lines will be white).
grayImage = grayImage(:, :, 1);
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(3, 3, 1);
imshow(grayImage, []);
axis('on', 'image');
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
hFig = gcf;
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
drawnow;
% Binarize
thresh = multithresh(grayImage,5);
thresh = [0, thresh, inf]
for k = 1 : length(thresh) - 1
fprintf('Getting mask between %d and %d.\n', thresh(k), thresh(k+1) - 1);
caption = sprintf('Mask between %d and %d', thresh(k), thresh(k+1) - 1);
mask = grayImage > thresh(k) & grayImage < thresh(k+1) - 1;
% Take only largest blobs.
mask = bwareaopen(mask, 5000);
% Display the image.
subplot(3, 3, k+1);
imshow(mask, []);
axis('on', 'image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
end
  4 Kommentare
Swag Mane
Swag Mane am 5 Aug. 2021
Bearbeitet: Swag Mane am 6 Aug. 2021
Usually I use img for image. I just used it this one time in my comment.
What i meant is: I want to exclude that black part from the thresholding calculation. I dont want the algorithm to consider those 0 pixels in the calculation. I dont even need that area segmented. If it was possible to crop images according to a random shape i would have actually done that beforehand.
In other words, i dont have a good grasp on what the multithresh() algorithm does behind the scenes so that why i'm saying "it will ruin the thresholding calculation"
I also changed the absolute boundaries for the thresholding value because i dont want zeros... and anything at 255 too
thresh=[1, thresh, 254];
  • Do you also think i need any other segmentation methods beyond thresholding to separate my ROIs?
I dont know much beyond the built in thresholding functions. I am guessing triangle thresholding would work with overlapping histograms. I looked into hysteresis thresholding too while checking out Canny edge detection. Of course, i dont understand much of it either.
And like i said, i have a huge data set and the code will most likely fail at certain "inevitably" bad images. (Check examples.zip)
Image Analyst
Image Analyst am 6 Aug. 2021
I'm pretty sure it doesn't matter if you include the dark pixels and have N+1 intensity ranges or exclude them and tell it you have N intensity ranges. Either way you get a set of thresholds and have to tell it which low and high threshold to use to segment the layer you want.
Once you have the layer, you can alter the mask if you want to, for example, fill in cracks with neighboring pixel intensities, include the cracks as zero in any computations. By default, only the intensity range is chosen by the thresholds and any dark holes or cracks/nooks/crannies/bays/incursions into the mask are excluded (not in the mask). Not sure what you want to do really. One way to get the mean thickness is to just scan the mask for that single particular layer and find the first and last row for each column. then subtract them to get the thickness, then take the mean of those.
[rows, columns] = size(mask);
mask = bwareafilt(mask, 1); % Take largest connected blob only, ignore small noise blobs.
firstRows = zeros(1, columns);
lastRows = zeros(1, columns);
for col = 1 : columns
fr = find(mask(:, col), 1, 'first')
if ~isempty(fr)
firstRows(col) = fr;
lastRows(col) = find(mask(:, col), 1, 'last')
end
end
% Get the thicknesses (or depths, widths, heights
% or whatever you want to call them) at every column.
thicknesses = lastRows - firstRows;
% Get the mean thickness.
goodIndexes = firstRows ~= 0;
meanThickness = mean(thicknesses(goodIndexes))

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by