MATLAB: Does the IMWRITE function create a blank figure window in MATLAB

blankcolormapfiguregrayimageImage Processing Toolboximwritenewwindow

When I call IMWRITE without displaying the image first, a blank figure window is created:
ima = imread('rice.tif');
imwrite(ima ,gray, 'newrice.bmp')
If I use the IMSHOW command before the IMWRITE command or if I don't specify a colormap, the figure window does not appear.

Best Answer

When you make a call to a colormap creation function with no inputs, it is expected that a figure window will be created, if one does not already exist. Examples of colormap creation functions are GRAY, JET, and HSV.
For example, GRAY is a function that produces a grayscale colormap. When called with no arguments, it produces a colormap whose length is the same as the colormap in the current figure, which has the side effect of making a figure if one doesn't exist. The following code will illustrate this:
close all
gray
Try the following to write your file:
ima = imread('rice.tif');
imwrite(ima,gray(256),'newrice.bmp')