Trouble saving image to tif format
Show older comments
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)
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
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!