Hi all, I am trying to code a tiff format file into a matrix of 2 dimention using imread. then I want to convert back the matrix to my original tiff file using imwrite. but when I do this the new tiff image is not the same as the original one. it is just a black background. is there anyway I can solve this problem?

 Akzeptierte Antwort

Image Analyst
Image Analyst am 22 Dez. 2017

0 Stimmen

Simply calling
tifImage = imread(inputFilename);
followed by
imwrite(tifImage, outputFilename);
Should not do that. The pixel values should be exactly the same (since no compression is being done). Chances are, you did something to the image, like converted it to a double or something. If you want any more help, attach your code (everything from imread to imwrite and all the lines of code in between) and your original input image that you say is not saving correctly.

7 Kommentare

Image Analyst
Image Analyst am 22 Dez. 2017
Original post in case he deletes it again.
Hi all, I am trying to code a tiff format file into a matrix of 2 dimention using imread. then I want to convert back the matrix to my original tiff file using imwrite. but when I do this the new tiff image is not the same as the original one. it is just a black background. is there anyway I can solve this problem?
K.G
K.G am 23 Dez. 2017
I have not written any code for that yet. overall, I want to first have its matrix format and then change the lower half of the elements in the matrix to 1 and then in order to make sure that the picture has changed the same way(the lower half of the image should be black now) I have to convert the modified matrix back to the image to see the changes I applied. I have attached the file here(I could not attach the tiff format but you can make a tiff out of it in the paint app) and I can do the modification to the matrix, but first I need to know how to convert back.
Image Analyst
Image Analyst am 23 Dez. 2017
K.G. :
"I want to first have its matrix":
tifImage = imread(inputFilename);
"then change the lower half of the elements in the matrix to 1"
[rows, columns, numberOfColorChannels] = size(tifImage);
originalImage = tifImage; % Save original image.
halfRows = round(rows/2);
tifImage(halfRows:end, :, :) = 1;
"to convert the modified matrix back to the image"
tifImage = originalImage;
K.G
K.G am 23 Dez. 2017
in terms of changing the lower half of the image to pure white it works! however, I also want to have the upper half unchanged and this function turned the upper half to pure black and I do not know why!
Image Analyst
Image Analyst am 23 Dez. 2017
It depends on the class of your image. I'm assuming it is uint8, so what I did was to set the lower half of the image to 1, almost pure black, not pure white. The only way that 1 would be white is if your image is a double. What that assumes is that values less than 0 are black. Values 1 or more are white. And values in between 0 and 1 are gray scale (like mapped to values between 1 and 254, inclusive).
K.G
K.G am 23 Dez. 2017
so you mean if I can make a tiff image with double data type from the beginning it will work properly?
Walter Roberson
Walter Roberson am 23 Dez. 2017
"so you mean if I can make a tiff image with double data type from the beginning it will work properly?"
No.
"Hi all, I am trying to code a tiff format file into a matrix of 2 dimention using imread."
Your image is color, which requires 3 or more dimensions. You cannot retain color in 2 dimensions.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by