Extract XY data from the image based on the color filter

조회 수: 9 (최근 30일)
S.R.
S.R. 2020년 6월 5일
댓글: S.R. 2020년 6월 7일
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
Ameer Hamza
Ameer Hamza 2020년 6월 6일
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.
S.R.
S.R. 2020년 6월 6일
Hi Ameer,
I ma looking into this function "impixelinfoval" that returns pixel location and color when I hover over the attached figure. If I could return this information back, I assume that there is a function for locating or scanning entire picture and returning pixel locations with the same color?
h = imshow('new_LTC5596.png')
hText= impixelinfoval(gcf,h);
set(hText,'FontWeight','bold')
set(hText,'FontSize',10)
Thank you,

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2020년 6월 6일
편집: Image Analyst 2020년 6월 6일
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
Image Analyst
Image Analyst 2020년 6월 6일
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.
S.R.
S.R. 2020년 6월 7일
Hi Image Analyst,
Absolutely sure. When doing RF design we normally work from the datasheet. Newer datasheets come in colors and the old ones come in black and white. I use WebPlotDigitizer but would like to implement this type of code in Matlab due to the other scripts I am using. If the plots overlap I see that as a problem but in that case I would use manual type of digitizer where I select points. In the case where we can extract datapoints, this more automated way would be of tramnedous help becasue it would speed up process.
I am getting pixel information and RGB color now with the code below but I am not certain how to pass variables to your code to be able to find matching RGB colors and re-plot figure?
Thank you for sending freehand drawing demo. I will check it out.
rgbImage = imread('new_LTC5596.png');
h=imshow(rgbImage);
msgbox({'You can zoom and pan before selecting each point';'press "space" when you are done to start the selection';'If you made a mistake, you can delete latest points pressing "backspace"';'Once you are finished, press "enter" to exit'})
[x,y] = ginput_zoom();
% Put a cross where they clicked.
hold on;
plot(x, y, 'w+', 'MarkerSize', 200);
% Get the location they click on.
% Extract the RGB color from that location.
[row,col,rgb]=impixel(rgbImage,x,y)
function [x,y] = ginput_zoom()
x=[];y=[];
h=[];
w=1;
while w~=0;
w = waitforbuttonpress;
while w==0
w = waitforbuttonpress;
end
cfg = gcf();
ch = double(get(cfg, 'CurrentCharacter'));
if ch == 13 % ENTER button
break;
end
if ch == 8 % Backspace button
if isempty(x) == 0
x = x(1:end-1);
y = y(1:end-1);
delete(h(end));
h = h(1:end-1);
continue;
end
end
[a,b]=ginput(1);
x = [x;a];
y = [y;b];
hold on; h = [h;plot(x,y,'g+')]; hold off;
end
Thank you,

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by