Declare a plotted Line in an image as a variable and not a Matlab graphics chart line?
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Brendan Hamm
2015-4-1
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 个评论
Brendan Hamm
2015-4-1
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');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!