Ask the "write" EXIF question and Tiff tags

  • Follow


I am creating a program takes two images as input, registers these images, and saves the results in a separate folder. These input images are Tiff. For the sake of a clearer explanation, I will only address the case where 1 image is transformed and saved in the example below.

My current setup is this:
1. I = imread(tiffPath)
2. I = abitrary transform on I (scale, rotation, translation)
3. imwrite(I,newTiffPath, 'tif', 'Resolution',300,'RowsPerStrip',size(I,1))
4. Sync relevant Tiff tags: 
-t1 = Tiff(tiffPath,'r')
-t2 = Tiff(newTiffPath ,'r+') (read and modify)
- setTags for t2 using getTags from t1. I only do this for a few tags that are relevant to the sync, like "Make" "Model" "ICCProfile".

There are certain tags that I cannot sync, specifically the EXIF tags. Of most concern are the GPSInfo, DigitalCamera, and ITPC tags. I've searched and can't find any information how I might be able to insert this information into the new file (though I can read it with exifread or imfinfo).  Is there any way to do this in matlab? 

Since questions of a similar nature have previously gone unanswered, I will assume no. I will therefore discuss an alternative solution and ask for your input.

I could just create a copy of the Tiff, create a new Tiff object t, read the image data from t (this should be equivalent to the "I" in step 1 above), do my transformation on the image data, and write it back to the Tiff. Now the EXIF is in tact, but there are a variety of Tiff tags that directly correspond to the image data of the original image, not the transformed one. Is there a simple way to update the Tiff tags with the new image data (or is this done automatically)? 
 
Thanks in advance,

Chris
0
Reply Chris 12/13/2010 10:22:05 AM

Hi Chris, unfortunately the Tiff object cannot write Exif tags.  I think your best bet to preserve those tags is as you outlined below, by copying the file, modifying the image data in the file, and then modifying any non-exif tags as necessary.


"Chris  Gat" <gatman02@hotmail.com> wrote in message <ie4s4d$t1c$1@fred.mathworks.com>...
> I am creating a program takes two images as input, registers these images, and saves the results in a separate folder. These input images are Tiff. For the sake of a clearer explanation, I will only address the case where 1 image is transformed and saved in the example below.
> 
> My current setup is this:
> 1. I = imread(tiffPath)
> 2. I = abitrary transform on I (scale, rotation, translation)
> 3. imwrite(I,newTiffPath, 'tif', 'Resolution',300,'RowsPerStrip',size(I,1))
> 4. Sync relevant Tiff tags: 
> -t1 = Tiff(tiffPath,'r')
> -t2 = Tiff(newTiffPath ,'r+') (read and modify)
> - setTags for t2 using getTags from t1. I only do this for a few tags that are relevant to the sync, like "Make" "Model" "ICCProfile".
> 
> There are certain tags that I cannot sync, specifically the EXIF tags. Of most concern are the GPSInfo, DigitalCamera, and ITPC tags. I've searched and can't find any information how I might be able to insert this information into the new file (though I can read it with exifread or imfinfo).  Is there any way to do this in matlab? 
> 
> Since questions of a similar nature have previously gone unanswered, I will assume no. I will therefore discuss an alternative solution and ask for your input.
> 
> I could just create a copy of the Tiff, create a new Tiff object t, read the image data from t (this should be equivalent to the "I" in step 1 above), do my transformation on the image data, and write it back to the Tiff. Now the EXIF is in tact, but there are a variety of Tiff tags that directly correspond to the image data of the original image, not the transformed one. Is there a simple way to update the Tiff tags with the new image data (or is this done automatically)? 
>  
> Thanks in advance,
> 
> Chris
0
Reply John 12/13/2010 2:51:04 PM


Thanks for the reply John. Maybe you can help me out with properly writing to a copied tiff. 

Here is my current workflow
path = /path.../test.tif
data = imread(path)
transform(data) %think of this as resize.. smaller
T = Tiff(path,'r+')
T.setTag('ImageWidth',size(data,2))
T.setTag('ImageLength',size(data,1))
T.setTag('RowsPerStrip',size(data,1)) %this is how the original file has it
T.write(data)
T.rewriteDirectory()
T.close

This works! However, the size of the new Tiff is the size (size of the file on disk, not the dimensions) of the original unmodified image + the size of the transformed image. That is, my original image is 111mb. If I used photoshop to resize this file the new image would be 80mb. When I use the process discussed above, the size is approx 191mb. Opening the file with photoshop and resaving using Save As will bring the size back to 80mb. So, it looks like Tiff.write is not disregarding the old data. Is this a bug(in libtiff or matlab), or am I doing something wrong? 

Thanks,

Chris

"John " <com.works.math@evans.john> wrote in message <ie5bso$39$1@fred.mathworks.com>...
> Hi Chris, unfortunately the Tiff object cannot write Exif tags.  I think your best bet to preserve those tags is as you outlined below, by copying the file, modifying the image data in the file, and then modifying any non-exif tags as necessary.
> 
> 
> "Chris  Gat" <gatman02@hotmail.com> wrote in message <ie4s4d$t1c$1@fred.mathworks.com>...
> > I am creating a program takes two images as input, registers these images, and saves the results in a separate folder. These input images are Tiff. For the sake of a clearer explanation, I will only address the case where 1 image is transformed and saved in the example below.
> > 
> > My current setup is this:
> > 1. I = imread(tiffPath)
> > 2. I = abitrary transform on I (scale, rotation, translation)
> > 3. imwrite(I,newTiffPath, 'tif', 'Resolution',300,'RowsPerStrip',size(I,1))
> > 4. Sync relevant Tiff tags: 
> > -t1 = Tiff(tiffPath,'r')
> > -t2 = Tiff(newTiffPath ,'r+') (read and modify)
> > - setTags for t2 using getTags from t1. I only do this for a few tags that are relevant to the sync, like "Make" "Model" "ICCProfile".
> > 
> > There are certain tags that I cannot sync, specifically the EXIF tags. Of most concern are the GPSInfo, DigitalCamera, and ITPC tags. I've searched and can't find any information how I might be able to insert this information into the new file (though I can read it with exifread or imfinfo).  Is there any way to do this in matlab? 
> > 
> > Since questions of a similar nature have previously gone unanswered, I will assume no. I will therefore discuss an alternative solution and ask for your input.
> > 
> > I could just create a copy of the Tiff, create a new Tiff object t, read the image data from t (this should be equivalent to the "I" in step 1 above), do my transformation on the image data, and write it back to the Tiff. Now the EXIF is in tact, but there are a variety of Tiff tags that directly correspond to the image data of the original image, not the transformed one. Is there a simple way to update the Tiff tags with the new image data (or is this done automatically)? 
> >  
> > Thanks in advance,
> > 
> > Chris
0
Reply Chris 12/16/2010 1:03:04 PM

2 Replies
466 Views

(page loaded in 0.059 seconds)

Similiar Articles:













7/23/2012 9:45:37 PM


Reply: