0
votes

I have a MATLAB code where I am generating a boundary figure for some word from an image. This is then plotted using points generated from bwboundaries function and then I am using the generated plot to create an image that I am using later on in the code.

Here is the code snippet:

%GET 8-NEIGHBOURHOOD BOUNDARIES
[B,L,N] = bwboundaries(z,'noholes');

%PLOT THE BOUNDARY FIGURE FOR EACH WORD
figure;
hold on;
for k=1:length(B),
    boundary = B{k};
    if(k > N)
        plot(boundary(:,2),boundary(:,1),'g','LineWidth',2);
    else
        plot(boundary(:,2),boundary(:,1),'r','LineWidth',2);
    end
    set(gca, 'visible', 'off');
    F = getframe(gcf);
    [X, Map] = frame2im(F);
end

Now, with a normal text with a slightly larger font size, I am getting perfect results, as expected. See here for proper output.

Now, the moment my font size is slightly smaller or the letters are a bit closely spaced, I find that the generated plot is somehow "squeezed" to fit the window size. See here for the wrong output.

I want the plot to take up as much space as it needs to show the entire boundary image, resizing itself if needed. Otherwise, the frame2im is capturing the completely wrong image which is messing up my further computation.

EDIT

I must mention that the final plot figure is being formed by appending several smaller plots into one figure. This final plot is then being converted using frame2im. As each smaller plot is being "appended", the rest of the image "squeezes" itself to make room for newer plots. Thus, the final image is totally squished together.


I thought that Adjusting size of plot in Matlab so that graph does not get cut off by edge of plot window was a possible duplicate, but in that particular case, the plot was getting truncated. In my case, I find the plot getting "squeezed" to fit the area.

1
can you do something like a print to png and then read that back in to get the image? something like print -dpng image.png; imread(image.png) - MZimmerman6
That is precisely what I wanted to avoid. I will essentially create more than a thousand images each time, maybe more. So you can understand my hesitation. - Kanishka Ganguly
@MZimmerman6 The issue is not with saving the plot as png. The issue is that the plot itself is getting squeezed to fit the area. So even if I save as png, it will still be the squeezed image. - Kanishka Ganguly
oh ok, I did not know whether the problem was sourced from the frame2im command. I have never used it before, so I was unsure. just a guess :) - MZimmerman6
@MZimmerman6 Even I don't really know what the issue is exactly. :) Thanks anyway! - Kanishka Ganguly

1 Answers

0
votes

I am not sure if this is what you are looking for but it may help. Here goes a test

%Simulation of a binary L and proper visualization
A=zeros(100,100);
A(80:90,10:60)=1;
A(10:90,10:20)=1;
figure,imagesc(A)

% concatenation of 20 binary L's and the shrink visualization
num=20;
A2=repmat(A,1,num);
figure,
imagesc(A2)

%correction of the visualization through the definition of the axes dimensions
figure,
axes('unit','normalized','position',[0.1 0.1 0.8 0.8/10])
imagesc(A2)

%correction of the visualization through the definition of the axis dimensions
figure,
imagesc(A2)
axis ([0,1000,0,100]) % axis image

You can use this templates to change the appearance of your image and therefore correct the shrinking.