Transferring tiff image tags identically to another image

조회 수: 14(최근 30일)
I have a script that reads tif images, manipulates them via image processing toolbox and saves it back to disk. The tif files have user defined data in the tags. I would like to pass these onto the new images saved. How can I do that? I started reading methods for reading tags etc but it seems like it's too much work just to copy things over. Can anyone suggest a simpler method?

채택된 답변

Walter Roberson
Walter Roberson 2015년 5월 27일
The easiest way for that flow:
1) make a copy of the .tif file using copyfile or equivalent
2) open the copy using the tiff class and the 'r+' option:
t = Tiff('ImageCopy.tif', 'r+');
3) ImgData = read(t);
4) Process ImgData, producing NewImgData
5) Providing that the new image array is *exactly* the same size as the old one, write() the image
write(t, NewImgData);
6) close(t);
If the new image is a different size, that can be handled relatively easily.
The above flow presumes that you want to modify the first image in the TIFF file, and that it does not have any sub-images
If you need to modify an image other than the first in the file, or if you need to deal with sub-images, then matters become more complex.
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 9월 19일
Looking back over my code, the expectation is that when you write() the image over top of the existing image that it leaves the tag information in place. The Tiff class allows you to talk about writing image data separately from writing the other associated information.
At the moment, I do not recall having tested the above code, so I am not certain how I arrived at it.

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

추가 답변(0개)


Community Treasure Hunt

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

Start Hunting!

Translated by