can anyone suggest a good way to save & again read a image that will loss lowest possible information?

i need to save my worked image & use it for next work. but i am losing information in read & write the image. i am using
imread(w1,'x.png');%after that preform other operation
imwrite(ww,'y.png');
imread(w2,'y.png');%again read the image for next work
i read about export_fig .is it will be helpful for me? & if how to use it?

 Respuesta aceptada

Thorsten
Thorsten el 10 de Sept. de 2015
Editada: Thorsten el 10 de Sept. de 2015
Use
save
and
load

9 comentarios

may i have it with an example for image?
To save a variable ww, use
save('ww.mat', ww)
to load it, use
load('ww.mat')
If you use imwrite on double values, they are converted and usually saved as uint8 integer values, that's why you're loosing information in the imwrite/imread cycle.
doing this-
final=cat(3,finalR,finalG,finalB);
save(final, 'final.mat')
getting this-
??? Error using ==> save
Argument must contain a string.
Error in ==> first at 128
save(final, 'final.mat')
You have to change the order of the arguments to save; the name of the mat file comes first; my example above was wrong, I corrected it.
save('final.mat', final)
thanks. need some more help. when i work with the workspace data of the first program for further operation on second program instead of "fianl image" i am getting the output as follows-
and when i am using the image from the first one to work on for the next one getting as follows-
you can see the quality degradation. i must say again no operation in between them without imread & imwrite .can u explain why it is & suggest me something for better result?
Sorry, but I don't believe it. I assure you that you can save an image as PNG format and recall it with no degradation. You must be using JPG or some other lossy format. Otherwise, prove it with a short demo that saves and recalls your PNG image and subtracts the two to show that the values are not the same.
final=cat(3,cDR,cDG,cDB);
imwrite(uint8(final),'Watermarked_Image.png');
figure();
imshow(uint8(final));
title('Watermarked Image');
thats the last portion of my first code
x = imread('Watermarked_Image.png');
here is the first portion of the second code i hope its good enough to make u believe. and I checked the NC(normalized correlation) value for your assurance they are .98 & .91 respectively, u can also see there difference from above picture. don't u think its degrading?
My guess is that "final" is not uint8, and that when you cast it to uint8, you're changing it. Perhaps it has values outside the range of 0-255 and those pixels are the ones that will be noticeably different.
If you do this,
final=cat(3,cDR,cDG,cDB);
final8bit = uint8(final);
imwrite(final8bit,'Watermarked_Image.png');
figure();
subplot(1,2,1);
imshow(final8bit);
title('Watermarked Image');
x = imread('Watermarked_Image.png');
subplot(1,2,2);
imshow(x);
Then you will see not difference between x and final8bit because a round-trip to a PNG file will not change the image. However if you compare final and final8bit you will see a difference. To verify:
diffImage = final - final8bit;
fprintf('max Diff=%f\n', max(diffImage(:)));
diffImage = x - final8bit;
fprintf('max Diff=%f\n', max(diffImage(:)));
The first one will show a difference of some number. The second will show a max difference of 0 because PNG does not change the image. Your image corruption is happening when you cast to uint8, and not because you're using a PNG image.

Iniciar sesión para comentar.

Más respuestas (1)

You forgot to assign the output of imread to a variable, plus the first argument of imread has to be a string. Not sure what your w1 is. Try it this way:
ww = imread('x.png'); % Read in original image
% After that preform other operation
% Output image is still called ww (though that's probably not a good name).
imwrite(ww,'y.png');
w2 = imread(y.png');% Recall the save image for next work

5 comentarios

i am already doing this. any example with save & load?
Please see my comment above.
x=load('Watermarked_Image.png');
getting this-
??? Error using ==> load
Number of columns on line 4 of ASCII file C:\Users\anika\Dropbox\manwar\Watermarked_Image.png
must be the same as previous lines.
Error in ==> second at 1 x=load('Watermarked_Image.png');
Use imread to read the image, and load and save for the result of your computations on the image.
anika, you are NOT already doing that. My code is substantially different than yours. Take a closer look.
There will be no loss of information in the image at all if you use a PNG format file. This is a standard lossless image format supported by virtually every program. You can use a .mat file to save the variable but it's a proprietary format that only MATLAB (and maybe a few other programs) understands. That's why Thorsten and I both recommend to use png for images and load()/save() for other kinds of variables, like the non-image results of your image analysis.

Iniciar sesión para comentar.

Preguntada:

el 10 de Sept. de 2015

Comentada:

el 11 de Sept. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by