Declare a plotted Line in an image as a variable and not a Matlab graphics chart line?

2 views (last 30 days)
A=imread('g16.BMP');
AR=A(:,:,1);
[rows, columns] = size(AR);
avgs = mean(AR(50:165,:), 2);
avgs2 = mean(AR(165:315,:), 2);
[~,ind]= max(abs(diff(avgs)));
[~,ind2]= max(abs(diff(avgs2)));
figure, image(AR,'CDataMapping','scaled'); colormap('gray'); hold on;
plot([1 size(AR,2)], [ind+50 ind+50], 'r', 'LineWidth', 2);
plot([1 size(AR,2)], [ind2+165 ind2+165], 'g', 'LineWidth', 2);
The code above is used to segment grey scale images based on large intensity changes...
so the code finds the average of each row between rows 50 and 165 followed by 165 to 315, the 2 parameter means to operate along the columns, which means that we will find the average of each row. This can lead to determining where a large change in itensity appears by doing diff combined with max where we compute pairwise distances between elements in an array abs means that no matter what the sign is, we will see the jump as a large positive value.
My problem is that I'm looking to declare the 2 bottom plotted lines as variables for further processing, for example i would like ...
plot([1 size(AR,2)], [ind+50 ind+50], 'r', 'LineWidth', 2);
I want this line to be Yupper
plot([1 size(AR,2)], [ind2+165 ind2+165], 'g', 'LineWidth', 2);
^^^^ this line to be Ylower
when I try and do so the line appears as below when I type 'whos' into the command prompt...
YL 1x1 112 matlab.graphics.chart.primitive.Line
YU 1x1 112 matlab.graphics.chart.primitive.Line

Answers (1)

Brendan Hamm
Brendan Hamm on 1 Apr 2015
What kind of processing do you need to do? You can still access the information from the returned object:
YL = plot([1 size(AR,2)], [ind2+165 ind2+165], 'g', 'LineWidth', 2);
xDat = get(YL,'XData'); % Gets the discrete x-locations used for plot.
inspect(YL); % Opens the Inspector which allows you to view the property list of that line.
Is this enough to get the information about this line you want?
  3 Comments
Brendan Hamm
Brendan Hamm on 1 Apr 2015
Plot does not switch the x and y coordinates I just showed you how to extract the properties which define a line and gave an example with the XData. Is it that you are looking for the y-values of the upper line? If so, follow the same process except extract the 'YData':
lUp = plot([1 size(AR,2)], [ind+50 ind+50], 'r', 'LineWidth', 2);
yUpper = get(lUp,'YData');
Sean
Sean on 1 Apr 2015
Edited: Sean on 1 Apr 2015
These 2 lines represent the plotted lines, highlighting an important segment in my image, I'm looking to extract this segment for further processing such as plotting histograms etc. Therefore what I planned to do was create a new vector Z by stacking all columns with in that area on top on one another using this code:
z=[];
for i = 1:1:1024
z=[z AR(i,yL(i) : 1 : yU(i))] end;
which is why I want to define y lower and y upper...
thanks for the help btw.....

Sign in to comment.

Categories

Find more on Data Distribution Plots 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!