converting tiff to image
显示 更早的评论
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?
采纳的回答
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 个评论
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?
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.
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;
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!
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).
so you mean if I can make a tiff image with double data type from the beginning it will work properly?
"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.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Convert Image Type 的更多信息
标签
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
