Enhanced image is not getting saved as it. Values get changed after imwrite()

My ques is: 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');

7 Kommentare

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.
It would be very useful if you attached the actual images (save them in a mat file) and ideally the NSS code.
One obvious thing: you're displaying the original image on the default intensity range of [0 1] (imshow with no optional argument) but displaying the enhanced image with a dynamic display range that matches the intensity range of the image (imshow with []). So, if the image doesn't use the full [0 1] intensity range, it will be enhanced by imshow. However, saving always use the [0 1] intensity range regardless of the dynamic range of the image.
@Puja Have to try using saveas or save gcf also? Is it the same? Yes, the contrast reduced in save image.
The output of NSS is not in the range 0 to 1 like your input image is.
@ Walter Roberson thanks for reply. The values of NSS is between [0 0.6944]. So while using imshow(NSS_img,[]) it scales the maximum value to 1. pls correct if i am wrong. Then,how I can make it from [0 1]. Pls help
Puja Bharti
Puja Bharti am 7 Okt. 2018
Bearbeitet: Puja Bharti am 7 Okt. 2018
Thank you @Walter. Thank you so much...... Yes now I am getting the exact enhanced image.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Produkte

Version

R2018a

Tags

Gefragt:

am 4 Okt. 2018

Bearbeitet:

am 7 Okt. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by