MATLAB: Added White Frame/Background when using imread()

imageimage processingimreadimshowMATLABwhite backgroundwhite frame

Hi,
when i do
image_og = imread('image.png');
image(image_og);
MATLAB always automaticallty adds a white frame for me. (The original graph does not have the white frame)
I don't see other people encountering this when they use imread(), so is there a way for me to remove the white frame?

Best Answer

You can determine the x and y limits of your image by accessing the handle output of image(). Then set your axis limits to the limits of your image.
image_og = imread('image.png');
h = image(image_og); % <----- get the output (h)
axh = gca();
% TUTORIAL
% h.XData are the [left, right] limits of your image
% h.YData are the [lower, upper] limits of your image however, the direction
% of the y axis is likely reversed so keep that in mind.
% These limits are the centers of the corners of the image so you must add/subtract
% 1/2 from each limit value to get the true edges of the image.
xlImage = h.XData;
ylImage = h.YData;
axis(axh,'equal')
xlim(axh, xlImage + [-.5,.5])
ylim(axh, ylImage + [-.5,.5])