How to save an image which only display properly using imshow(grayImg,[])?

조회 수: 10 (최근 30일)
ASHWIN JOSHY 2022년 5월 1일
답변: yanqi liu 2022년 5월 7일
I am working on an image encryption project, so I first converts color image to gray and do the rest, after encryption I can see the image only using
Not by
but if I store the image with
Then it isn't saving as expected or not as I saw when using imshow(grayImg,[]) Does anyone know what kind of error am I making?
  댓글 수: 3
ASHWIN JOSHY 2022년 5월 1일
The encrypted values are double, i want to save as .tiff
Image Analyst
Image Analyst 2022년 5월 1일
If you use single or double in imshow() it expects the values to be in the range 0-1. If they're below 0 the pixels show up as black. If more than 1 the pixels show up as white. If you use [] then it scales the min of your data (whatever value it may have) to black and the max to white.
To save a double as a tiff, this should do it:
% Create floating point image.
rgbImage = rand (10, 20, 3);
% Image must be single precision.
rgbImage = single(rgbImage);
% Display it.
imshow(rgbImage, 'InitialMagnification', 1000)
axis('on', 'image');
% Create tiff object.
fileName = '_floatingPointImage.tif';
tiffObject = Tiff(fileName, 'w')
% Set tags.
tagstruct.ImageLength = size(rgbImage,1);
tagstruct.ImageWidth = size(rgbImage,2);
tagstruct.Compression = Tiff.Compression.None;
tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP;
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = 32;
tagstruct.SamplesPerPixel = size(rgbImage,3);
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
% Write the array to disk.
% Recall image.
m2 = imread(fileName)
% Check that it's the same as what we wrote out.
maxDiff = max(max(m2-rgbImage))

댓글을 달려면 로그인하십시오.

답변 (1개)

yanqi liu
yanqi liu 2022년 5월 7일
yes,sir,may be use
and, then to check the file


Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by