Why is the entire image copied instead of the axes only?
2 views (last 30 days)
Show older comments
What I have is a plot showing the area of connected components. What I want to do is to further work on the plot figure such as clean it up a bit or ``imcomplement`` it etc. and then be able to apply the axes from the original plot to this image and be able to extract the ``ylabel``.
Let me explain the above issue with my code and some examples.
This is the plot I have, the y-axis represents the object areas. This is the important axis that I want to transfer to the new image.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/158772/image.jpeg)
Since I am interested in the axes only I copy that using
h = findobj(gcf,'type','axes');
So that I can work with the figure without the axes and borders interfering I save it without these attributes
set(gca, 'visible', 'off'); % Hide the axis and borders
hgexport(gcf, 'plot1.jpg', hgexport('factorystyle'), 'Format', 'jpeg');
This is what I get:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/158775/image.jpeg)
So far so good.
Now comes the processing or in other words changing the plot to my needs.
plot_img = rgb2gray(imread('plot1.jpg'));
img_bw_plot = im2bw(plot_img, graythresh(plot_img));
[rows cols] = size(plot_img);
new = zeros(size(plot_img));
for i = 1: rows
for j = 1: cols
if (img_bw_plot(i,j) == 0)
new(i, 1:10) = 255;
end
end
end
f = figure;
imshow(new);
copyobj(h,f)
This produces a weird overlapped image where instead of copying only the axes, the entire image is copied on top of the ``new``. The ``datacursormode`` also fails to work beyond the over lapping image.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/158779/image.jpeg)
0 Comments
Accepted Answer
Image Analyst
on 17 Mar 2014
I really don't understand what you want to do. What or where is this "ylabel" that you want to extract? Do you mean the tick labels on the y axis? And I don't know why you want to treat a plot of markers (diamonds?) as if it were an image. And I don't know what you are hoping to do with the "new" matrix.
Why don't we take a step back and start with the original x,y data you plotted. You say you have a "plot showing the area of connected components." I guess x is the blob number, and y is the area of the blob. Now, what do you want to do with that?
7 Comments
Image Analyst
on 18 Mar 2014
Instead of plotting those points with plot() or scatter() or whatever you used, why don't you just set pixels in an array (an image) and just use regular image processing methods?
More Answers (0)
See Also
Categories
Find more on Visual Exploration 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!