필터 지우기
필터 지우기

Removing gray border from imshow plot

조회 수: 9 (최근 30일)
Erik Henegar
Erik Henegar 2021년 6월 3일
댓글: DGM 2021년 6월 4일
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

답변 (1개)

Chunru
Chunru 2021년 6월 4일
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
DGM
DGM 2021년 6월 4일
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.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by