Detecting features in an image
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Atreya Danturthi
am 27 Jun. 2021
Beantwortet: Image Analyst
am 28 Jun. 2021
I have a .tiff image, which represents in-situ solidifcation sequence of an alloy (from melt). I have performed basic morphological operations, image segmentation and applied gaussian blur to even out the noise across the image. I need to detect the features (with white boundaries). Can give me any ideas on how I can go about it?
The findcircles function is not of any use as I do not have the required variables to use it.
I am attaching a sample image below. Any sorts of suggestions into this would be highly appreciated.
A small clarification in the question, the objects/features that I need to detect are the circular-type patterns present inside the external boundary.
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 27 Jun. 2021
The boundaries of the white squiggles are, of course, not precisely defined - it's kind of a judgment call. What I'd try is to first get a mask of the whole thing, separate from the background. Then run stdfilt() over the image to detect regions of high standard deviation (like the edge of the part and the squiggles. Then I'd threshold it to get the high StDev regions. Then I'd dilate the whole part mask and use it to erase the edge of the part. That will leave a binary image of only the squiggles. Try adjusting both the stdfilt() window size and your threshold value to get a good combination.
You may like my interactive threshold app in my File Exchange:
3 Kommentare
Weitere Antworten (1)
Image Analyst
am 28 Jun. 2021
Try this; Adapt as needed.
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
folder = pwd;
baseFileName = 'sample image latest.png';
grayImage = imread(baseFileName);
% 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.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = min(grayImage, [], 3);
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 3, 1);
imshow(grayImage, []);
axis('on', 'image');
title('Reference Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
hFig = gcf;
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
%--------------------------------------------------------------------------------------------------------
% Binarize the image.
% Get a mask of the whole part in the image.
% imhist(image1);
% grid on;
backgroundMask = ~imbinarize(grayImage);
% Take largest blob only.
backgroundMask = bwareafilt(backgroundMask, 1);
% Enlarge it.
se = strel('disk', 15, 0);
backgroundMask = imdilate(backgroundMask, se);
subplot(2, 3, 2);
imshow(backgroundMask, []);
axis('on', 'image');
title('Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
drawnow;
% Plot the boundaries over the original image.
subplot(2, 3, 1);
boundaries = bwboundaries(~backgroundMask);
boundaries = boundaries{1};
x = boundaries(:, 2);
y = boundaries(:, 1);
hold on;
plot(x, y, 'r-', 'LineWidth', 2);
%--------------------------------------------------------------------------------------------------------
% Get a local standard deviation image
sdImage = stdfilt(grayImage, ones(13));
% Erase the backgrond
sdImage(backgroundMask) = 0;
subplot(2, 3, 3);
imshow(sdImage, []);
axis('on', 'image');
title('Standard Deviation Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
drawnow;
%--------------------------------------------------------------------------------------------------------
% Get the histogram so we can see where to threshold it.
subplot(2, 3, 4:5);
histogram(sdImage, 100);
grid on;
title('Histogram of Standard Deviation Image', 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Gray Level', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Pixel Count', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Threshold to get the white squiggles.
% Use interactive thresholding app at https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle
lowThreshold = 0.01; % Set an initial guess.
highThreshold = 5.25; % Set an initial guess. (Depends on neighborhood size used for stdfilt().)
if ~isempty(which('threshold'))
[lowThreshold, highThreshold] = threshold(lowThreshold, highThreshold, sdImage)
else
message = sprintf('Please download interactive threshold app at https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle');
uiwait(helpdlg(message));
end
% Put lines of threshold on the histogram.
xline(lowThreshold, 'Color', 'r', 'LineWidth', 2);
xline(highThreshold, 'Color', 'r', 'LineWidth', 2);
squiggles = (sdImage >= lowThreshold) & (sdImage <= highThreshold);
% Remove blobs touching background
% squiggles = imclearborder(squiggles);
% Remove blobs bigger than 10000 pixels.
maxAllowableBlobSize = 10000;
squiggles = bwareafilt(squiggles, [2, maxAllowableBlobSize]);
% Display the image.
subplot(2, 3, 6);
imshow(squiggles, []);
axis('on', 'image');
title('Squiggles', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
drawnow;
% Measure areas
props = regionprops(squiggles, 'Area', 'Centroid');
allAreas = [props.Area]
msgbox('Done');
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing and Computer Vision finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!