Extract XY data from the image based on the color filter
9 views (last 30 days)
Show older comments
Hi,
How could I extract XY data from the image by selecting points of the same color? For example, in the attached figure, gain is plotted versus frequency for three different temperatures. +85C is red color, +25C is green color and -40C is blue color. I would like to be able to extract XY data but instead of picking up manually point by point on the curve, I would like to pick one point on the red curve which would then select all points with the same color and export them as the XY data scaled based on the some already known XY points presented on the graph.
Thank you,
S.R.

6 Comments
Ameer Hamza
on 6 Jun 2020
I think there is no straightforward way to extract the data. You may need to write the code according to your requirement using the image processing tools.
Accepted Answer
Image Analyst
on 6 Jun 2020
Edited: Image Analyst
on 6 Jun 2020
Try imsplit
[r,g,b] = imsplit(rgbImage);
% Then scan each column with find() until you find the first row where that color appears.
redImage = r == 255 & g == 0 & b == 0;
greenImage = r == 0 & g == 255 & b == 0;
blueImage = r == 0 & g == 0 & b == 255;
[rows, columns] = size(redImage)
ry = zeros(1, columns)
gy = zeros(1, columns)
by = zeros(1, columns)
for col = 1 : columns
% First the red
thisCol = redImage(:, col);
topRow = find(thisCol);
if ~isempty(topRow)
ry = topRow;
end
% Next the green
thisCol = greenImage(:, col);
topRow = find(thisCol);
if ~isempty(topRow)
gy = topRow;
end
% Next the blue
thisCol = blueImage(:, col);
topRow = find(thisCol);
if ~isempty(topRow)
by = topRow;
end
end
Of course the values will be in units and coordinates of image pixels, so you'll have to calibrate the distances.
3 Comments
Image Analyst
on 6 Jun 2020
Are you sure you can't get the figure, or the data used to create the figure. If you have just the PNG image, it's going to be hard to pull out each curve independently since they overlap. You're probably best off using imfreehand to hand trace the curve. I'm attaching a demo.
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!