Matlab imshow function border tight not working under small size image
Show older comments
By default, when imshow displays an image in a figure, it surrounds the image with a gray border. You can change this default and suppress the border using the 'border' parameter.
But, I recently found that border tight will stop working when the matrix is smaller than approximately 125-130 thresholding
Please try these two Matlab command and you will see the difference
imshow(rand(130,130),'Border','tight') % works! no grey boundary at all
imshow(rand(120,120),'Border','tight') % not working! grey boundary appears

I carefully read the doc and found the sentence below When set to ‘tight', the figure window does not include any space around the image in the figure. If the image is very small or if the figure contains other objects besides an image and its axes, imshow might use a border regardless of how this parameter is set.
That is very disappointing. What I am trying to do is to capture image after imshow and store it to the matrix using command like
f=getframe(gcf);
resultMatr=f.cdata;
so any border will influence the result.
Any solution for that?
Answers (1)
Jihang Wang
on 4 Mar 2015
Edited: Jihang Wang
on 4 Mar 2015
2 Comments
Cg Gc
on 9 Jan 2019
I know this is a little odd, but can you provide an example of how to use your function? I am trying to group a few images together and I really would like to remove the border, but I keep receiving an error message because I don't have enough input arguments. I am not sure what that means. An example would be lovely.
Thank you.
Walter Roberson
on 9 Jan 2019
Example of use:
img = imread('cameraman.tif');
outsize = 100;
outputimg = removeBorder(img, outsize);
Categories
Find more on Convert Image Type 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!