Use imwrite to save tif images

I want to save a 3 color image as a lossless tif image. When i tried
imwrite(image,'test.tif','Mode','lossless')
I got an error message. Is there any way to save an image as a lossless tif? Thank you.

 Risposta accettata

Guillaume
Guillaume il 5 Ott 2018
Modificato: Guillaume il 5 Ott 2018
"I got an error message" is a useless statement if you don't give us said error message. Thankfully, you've finally given it in a comment to Image Analyst's answer.
'Mode' is indeed not a valid option for TIF. Probably, the nearest available option would be Compression. However, note that the default compression method for colour images is 'packbits' which is lossless anyway. In fact, the only compression mode that is lossy is 'jpeg' which you'd have to set explicitly. So really, for lossless TIF,
imwrite(im2uint16(NewImage), 'test.tif')
is all that is needed.

Più risposte (1)

Yes. Do NOT call your image variable image since that is the name of a built in function. Try
imwrite(yourImage,'test.tif');

6 Commenti

if I save the enhanced image then using imshow(NSS_Img,[]) I get the same enhanced image. But if I use imshow(NSS_Img) the image is not the saved enhanced image. Please help. Actually, I want to enhance image X and save it and then crop a small portion from the saved enhanced image. But, the values of NSS_img and the image after saving is not same. my code is given below:
X = imread(imfile(image).name);
filename = imfile(image).name;
full_file = fullfile('C:\Users\Puja Bharti\Desktop\matlab\',filename);
[pathname, name, ext] = fileparts(full_file);
s1 = 'En';
s2 = filename;
s = strcat(s1,s2);
new_name = fullfile(pathname, s)
if size(X,3)==3
X = rgb2gray(X);
end
grayImage= im2double(X);
figure('Name','Original image'), imshow(grayImage)
NSS_img = NSS(grayImage); %NSS_img is enhanced image
whos NSS_img
figure('Name','final image'), imshow(NSS_img,[])
imwrite(NSS_img,new_name,'png','Mode','lossless');
What is NSS? And why are you using a double array as a linear index to NSS? I doubt that will work? And why are you casting to double()?
To "enhance", try using imadjust().
To crop, try using imcrop().
Thank you Image Analyst, I tried a different name and when i type:
imwrite(im2uint16(NewImage),'test.tif','Mode','Lossless');
I get an error,
Error using writetif>parse_param_value_pairs (line 161)
'Mode' is not a recognized parameter. For a list of valid name-value pair arguments, see the documentation for this function.
Is there a way to use imwrite for tif images in a way that the exported image is a lossless image?
Thank you Image Analyst, NSS is the enhancement code I have made. It uses a filter which needs im2double() as input and output is also im2double(). The Image get enhanced with my code NSS(), image is shown correctly with imshow(NSS_img,[]). But I have to store this enhanced image and then use it for my future use (Region of interest segmentation). While using imwrite() enhanced image get saved but the if i open the saved enhanced image, then its not the same which i saved. Please help.
@Puja Bharti, are your comments in any way related to Angela question or did you just try to highjack somebody's else question? If so, then please start your own question.
Sorry Guillaume and Angela. I had no such intensions. I just want the solution to my problem. Please help me at:
https://in.mathworks.com/matlabcentral/answers/422212-enhanced-image-is-not-getting-saved-as-it-values-get-changed-after-imwrite

Accedi per commentare.

Categorie

Scopri di più su Convert Image Type in Centro assistenza e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by