How can I have Matlab use deep learning to identify key items in an image?

4 ビュー (過去 30 日間)
Steven D
Steven D 2022 年 5 月 19 日
コメント済み: Steven D 2022 年 5 月 23 日
I am trying to have MATLAB use deep learning to automatically identify specific items within an image (namely, all the triangles located at the nodes). Can anyone give any input on how I would go about having MATLAB do this? Attached is:
  1. The raw input image
  2. A modified version of the input image that shows the objects of interest in the image (i.e., the triangles)
The x,y coordinates of the triangle vertices is what I ultimately need. Thanks in advance for your help!
1)
2)

採用された回答

Image Analyst
Image Analyst 2022 年 5 月 21 日
I'm sure if you had tried, you would have figured this out.
% 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 = 22;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = pwd;
baseFileName = 'triangles.png';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% 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(rgbImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
fprintf('It is not really gray scale like we expected - it is color\n');
% Extract the blue channel.
grayImage = rgbImage(:, :, 3);
else
grayImage = rgbImage;
end
% Update 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)
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 2, 1);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
drawnow;
% Display histogram.
subplot(2, 2, 2);
histogram(grayImage);
grid on;
drawnow;
title('Histogram of Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Binarize the image to get a mask.
lowThreshold = 0;
highThreshold = 182;
% https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle
% threshold(lowThreshold, highThreshold, grayImage);
mask = grayImage >= lowThreshold & grayImage <= highThreshold;
% Put red threshold line on histogram so they know where it was thresholded at.
xline(highThreshold, 'Color', 'r', 'LineWidth', 2)
% Get rid of thin tendrils.
mask = imopen(mask, true(7));
% Take only the largest blobs.
mask = bwareafilt(mask, 2500);
% Display mask image.
subplot(2, 2, 3);
imshow(mask);
hold on;
impixelinfo;
axis('on', 'image');
drawnow;
title('Mask, a Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Label the two blobs so we can fit a line through wach one, one at a time.
[labeledImage, numBlobs] = bwlabel(mask);
% Get areas
props = regionprops(mask, 'Area', 'Centroid');
allAreas = [props.Area]
xy = vertcat(props.Centroid)
subplot(2, 2, 4);
histogram(allAreas, 10);
caption = sprintf('Size distribution of %d triangles', length(allAreas))
title(caption, 'FontSize',fontSize);
grid on;
xlabel('Area in Pixels', 'FontSize',fontSize)
ylabel('Count', 'FontSize',fontSize)
  9 件のコメント
Steven D
Steven D 2022 年 5 月 23 日
I'll definitely give it a shot. Thanks again for all your help!

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 5 月 19 日
You can probably get those with traditional methods like thresholding and blob analysis.
For a deep learning solution you can use SegNet.
  1 件のコメント
Steven D
Steven D 2022 年 5 月 21 日
Thanks for your comment. Would you happen to have any specific code examples that I could try?

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

Community Treasure Hunt

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

Start Hunting!

Translated by