Clear Filters
Clear Filters

Removing gray border from imshow plot

9 views (last 30 days)
Erik Henegar
Erik Henegar on 3 Jun 2021
Commented: DGM on 4 Jun 2021
I am trying to create images from 128x128 matrices of complex doubles and then use those images as my test data for a convolutional neural network using the Deep Learning Toolbox(my training images are 128x128 .png files). I am using the imshow command to plot the data from the matrices because that command removes the axes and tick markings from the plot, but this command is leaving an unwanted gray border around my images. Instead of getting the desired 128x128 images, I'm getting images that are 185x160. I also tried using the imsave command, but the saved image turns out to just be a black box and does not match the plotted figure. Is there any other way for me to get only the desired 128x128 images without any borders or axes? Here is my current code:
figure, imshow( complex_image_new_dB, image_scale_bounds_new_c );
axis equal;
set(gca,'units','pixels'); % set the axes units to pixels
x = get(gca,'position'); % get the position of the axes
set(gcf,'units','pixels'); % set the figure units to pixels
y = get(gcf,'position'); % get the figure position
set(gcf,'position',[y(1) y(2) x(3) x(4)]);% set the position of the figure to the length and width of the axes
set(gca,'units','normalized','position',[0 0 1 1]); % set the axes units to pixels

Answers (1)

Chunru
Chunru on 4 Jun 2021
try the following command
imwrite(X,MAP,FILENAME,FMT)
where X is the data matrix you have (it should be real), MAP is the colourmap you use, FMT should be 'png'.
  1 Comment
DGM
DGM on 4 Jun 2021
Absolutely correct. If the image data is available, just use imwrite. There's one additional thing though. OP's image data is likely not scaled to standard image data range, hence the syntax used for imshow() and the issues with black output.
% assuming images are grayscale
imwrite(mat2gray(myimage,mydatarange),'unnecessarilylongfilename.png')
mat2gray() is going to rescale the image to standard data range based on the specified range and the numeric class of the image. If the range is left unspecified, it uses [min max] automatically.

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!