MATLAB Answers

getting coordinates from a picture

323 views (last 30 days)
aaditya
aaditya on 2 Oct 2014
Commented: Image Analyst on 14 Jun 2021
Hi! I have an image that I would like to get the coordinates from. Its a 2D image. I need to perform some operation with the image. I need to get the coordinates of some points I choose and get them saved. I am aware of the data cursor, but since I have a huge number of points, manual operation will be of no way.
lets say, I have this basic structure of a thermal fin. I need say 1000 points from its boundary.Is there any way in matlab, I can import the image, and save the coordinates of the boundary, distributed evenly over.
I hope my question is clear.
thanks in advance!!

Accepted Answer

Image Analyst
Image Analyst on 2 Oct 2014
Edited: Image Analyst on 16 Jul 2019
Well, you could use image analysis:
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 = 36;
% 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 standard MATLAB color demo image.
folder = 'C:\Users\aaditya\Documents\Temporary';
baseFileName = 'part1.jpg';
% 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
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
axis on;
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
% Extract the individual red, green, and blue color channels.
% redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
% blueChannel = rgbImage(:, :, 3);
% Get the binaryImage
binaryImage = greenChannel < 200;
% Display the original color image.
subplot(2, 2, 2);
imshow(binaryImage);
axis on;
title('Binary Image', 'FontSize', fontSize);
% Find the baseline
verticalProfile = sum(binaryImage, 2);
lastLine = find(verticalProfile, 1, 'last')
% Scan across columns finding where the top of the hump is
for col = 1 : columns
yy = lastLine - find(binaryImage(:, col), 1, 'first');
if isempty(yy)
y(col) = 0;
else
y(col) = yy;
end
end
subplot(2, 2, 3);
plot(1 : columns, y, 'b-', 'LineWidth', 3);
grid on;
title('Y vs. X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
Of course you'll get better results if you use a PNG image rather than that crummy JPG which has all kinds of bad compression artifacts.
  15 Comments
Image Analyst
Image Analyst on 14 Jun 2021
@Erkan Karaoglu, let's not start a new discussion in @aaditya's 7 year old thread. Please start your own thread and attach the original grayscale thermal images rather than the pseudocolored ones. Also take the picture with the scene perpendicular to the optic axis, not an an oblique angle (bad for a number of reasons).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!