Trouble saving image to tif format

I have a cellarray that contains images(4 in this case)
imgArray=
[1040x1393 uint16]
[1040x1393 uint16]
[1040x1393 uint16]
[1040x1393 uint16]
Each one can be displayed on an axes component by the use of a scroll bar by indexing the cellarray.
I have a save button, that loops through the array and I am wanting to save them as tifs. The code that Geoff kindly showed me was,
for k=1:length(imgArray)
imwrite(imgArray{k},sprintf('image%04d.tif',k);
end
This indeed saves the files, but I can't then open them with any software. I have also tried to open them using matlab
[Filename,Pathname]=uigetfile('*.tif','Select an Image');
fname=[Pathname,Filename]
figure
imshow(fname,[]);
but get the error message

Answers (1)

Voss
Voss on 3 Jan 2024
Edited: Voss on 3 Jan 2024
This is mentioned in the documentation for imshow, in a Note under the DisplayRange input argument section:
"If you call imshow with a filename, then you must specify the DisplayRange name-value argument."
In other words, imshow(filename,[]) won't work, but imshow(filename,'DisplayRange',[]) will.
Example:
% create a cell array of matrices:
imgArray = {randi([0,65535],1040,1393,'uint16')};
% write the matrices to image files:
for k = 1:numel(imgArray)
imwrite(imgArray{k},sprintf('image%04d.tif',k));
end
filename = sprintf('image%04d.tif',1);
imshow(filename,'DisplayRange',[]) % works
imshow(filename,[]) % gives an error like you got
Error using images.internal.imageDisplayParsePVPairs
The parameter, image0001.tif, is not recognized by imageDisplayParsePVPairs

Error in images.internal.imageDisplayParseInputs (line 70)
[common_args,specific_args] = images.internal.imageDisplayParsePVPairs(varargin{:});

Error in imshow (line 253)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});

Categories

Find more on Convert Image Type in Help Center and File Exchange

Asked:

on 4 Mar 2015

Edited:

on 3 Jan 2024

Community Treasure Hunt

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

Start Hunting!