Added White Frame/Background when using imread()

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?

2 comentarios

Check that you're not setting the xlim() or ylim() or holding the axes prior to plotting the image. If so, remove those commands until after the image is plotted.
If none of those are happening, you can always set the axis limits to fit the image
xlim([100,800]) % or whatever your image requires
ylim([50, 600]) % ditto
Vanessa You
Vanessa You el 26 de Jul. de 2019
Hi Adam,
thanks for your reply.
I am not setting the xlim() or ylim() prior to plotting the graph.
What I am doing is that I am reading pictures captured by a camera, so setting the axis limits manually would not work, since the size will always vary depending on what camera I use.
I tried clf('reset') but it did not work either.
Is there a way to clear whatever x limits or y limits the MATLAB has for the figures right now?

Iniciar sesión para comentar.

 Respuesta aceptada

Adam Danz
Adam Danz el 26 de Jul. de 2019
Editada: Adam Danz el 26 de Jul. de 2019
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])

3 comentarios

Hi,
I copied your code but it is still not working.
The image produced is the exact same.
Here is my whole code, I wonder if it is something related to how I captured th photo?
% registering the pixeLINK adaptor in MATLAB
imaqregister(['C:\Program Files\MATLAB\R2019a\toolbox\imaq\imaqadaptors\pixelinkimaq.dll'])
imaqreset;
% querying available cameras and dipslaying info of the camera
dev=imaqhwinfo('pixelinkimaq');
dev.DeviceInfo(1);
vid = videoinput('pixelinkimaq');
% set the region of interest
set(vid, 'ROI', [1472, 760, 1120, 800]);
% get a snapshot from the camera
cla('reset');
start(vid);
data = getdata(vid,1, 'int16');
imaqmontage(data);
picture_name = ['image.png'];
saveas(gcf, picture_name);
stop(vid);
% read image
cla reset
image_og = imread('image.png');
h = image(image_og)
axh = gca()
xlImage = h.XData;
ylImage = h.YData;
xlim(axh, xlImage + [-.5,.5])
ylim(axh, ylImage + [-.5,.5])
Adam Danz
Adam Danz el 26 de Jul. de 2019
Editada: Adam Danz el 26 de Jul. de 2019
Ahhhhhhh.... in that case, yes, the photo you're reading into matlab countains the white border. I'm not sure where that white border is added: in the original picture? the way the picture is captured or saved? I have no idea.
Your options going forward are to either capture the image without the white border prior to loading it into matlab or to use some of matlab's image processing to get rid of the white border.
The good news: We've identified the problem and have some ideas for its solution.
The bad news: I'm not the man for this job. I'd love to tinker with it and learn along with you but I haven't got the time today so your best best is to post a new question explaining the new undertanding of the problem.
Vanessa You
Vanessa You el 26 de Jul. de 2019
Okay, that's fine!
Thank you so much for your help!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2019a

Preguntada:

el 26 de Jul. de 2019

Comentada:

el 26 de Jul. de 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by