How I can save Image without using imwrite ?
Show older comments
I want a code that save Image after I construct this Image from blocks,I used imwrite but it effect on the values of the Image when I read this Image ,please I need your help in that problem ????
2 Comments
Michael Haderlein
on 7 May 2015
Could you please also state what kind of effect of imwrite is the problem?
Ameligege
on 7 May 2015
Edited: Walter Roberson
on 8 May 2015
Answers (1)
Image Analyst
on 7 May 2015
1 vote
Save it to a .mat file with save().
13 Comments
Ameligege
on 7 May 2015
Joseph Cheng
on 7 May 2015
Edited: Joseph Cheng
on 7 May 2015
depends... are you looking to view it in another program as in you're still trying to save it as a jpg, png, or tiff then NO? OR if you just want the RAW data then the .mat will be able to be loaded back into matlab. Otherwise if you could always just use fwrite and save it as a RAW file.
Ameligege
on 7 May 2015
Ameligege
on 7 May 2015
Joseph Cheng
on 7 May 2015
Edited: Joseph Cheng
on 7 May 2015
well you're dealing with jpg compression which is terrible if you're looking to get your exact values back and using the default parameters. Unless you are using lossless compression. you can try setting different modes in the jpeg section to get lossless compression.
Guillaume
on 7 May 2015
@Joseph, standard jpg does not support lossless compression (*unless you don't use the standard jpeg library). jpeg 2000 does, but usually use a different extension (.jp2).
@Ameligege, before complaining that imwrite does not give you the result you expect when you use a particular file format, it would be a good idea to learn about the capabilities of the file format. jpg is a lossy compression format, you never get back the same value you wrote. Use png, bmp, tiff with a different compression than jpeg obviously) or other lossless format.
Each format also has some limitation over the range of intensities they can encode (8-bit, 16-bit, etc.) and number of channels (1,3, 4).
Walter Roberson
on 7 May 2015
imwrite will do lossless jpeg though, and it is not uncommon for it to be supported by other programs
Image Analyst
on 7 May 2015
You can get back the image variable from .mat and display it with imshow(). imshow() doesn't really care what format the image was when it was on disk. Compressed, uncompressed, integer, floating point - it just doesn't care (as long as you pass it the variable instead of a filename string). It's the job of the reader function to read it in and give you a proper MATLAB variable, and that's all imshow() cares about.
Mat files are a proprietary format though. If you want to see thumbnails in your Windows Explorer or be able to read it with other programs, like Photoshop, then you should store it in a standard format, perhaps one that can handle floating point numbers or whatever strange stuff you had that didn't let imwrite store it properly.
Image Analyst
on 7 May 2015
Ameligege, I recommend you use PNG format with imwrite. That's what I always use and it's pretty much become a standard for much/most of the digital imaging world. You can make a round trip from variable to disk to variable with PNG and there will be no change of values because it's an lossless, compressed format.
A K M FOYSAL AHMED
on 6 Jan 2017
Hello, I have png image with pixel value 0 and 255. I am trying to save this as same png format after changing the value to 0=1 and 255=2 using "imwrite". But, unfortunately it save the image with all value as 255.
Walter Roberson
on 6 Jan 2017
NewImage = uint8(YourImage + 1) ;
NewImage(YourImage > 1) = 2;
A K M FOYSAL AHMED
on 6 Jan 2017
Thank you Walter, it works....:)
Image Analyst
on 6 Jan 2017
Why do you want 1 and 2 instead of the more usual 0 and 1 (used for binary images, masks, ROIs, etc.)?
Categories
Find more on Images 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!