Why is the entire image copied instead of the axes only?

4 views (last 30 days)
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.
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:
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.

Accepted Answer

Image Analyst
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
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?
Faraz
Faraz on 19 Mar 2014
Yes, I will look into it. That looks to be the best option. Since the area are plotted on the y-axis, I used this code to trasfer that to a vector where the area is the vector index. I am setting that pixel to white.
area = [stats.Area];
normalized_area = area/norm(area);
figure(1), plot(5, area(:),'.');
axis([0 300 0 6000]);
for k = 1: length(area)
test(area(k)) = 255;
end
Now what I have to do is to search for continuous "255" in the vector and that will be my blob.
Is this what you had in mind? with writing it directly to an array or is there a better way to do it?

Sign in to comment.

More Answers (0)

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!