micasense / imageprocessing

MicaSense RedEdge and Altum image processing tutorials
https://www.micasense.com
MIT License
260 stars 152 forks source link

writing metadata back to images #69

Closed moghi005 closed 5 years ago

moghi005 commented 5 years ago

Hi, I attempted to process the images in Pix4D but I’m unable to do it. The reason is because the images don’t have the required metadata (Rig Name, Camera Model, Band Name, etc). Pix4Dmapper has the camera and rig information in their database but since the images don’t any metadata, it doesn’t load the rig and camera parameters from the database. I created a csv file as it was described in the tutorial, but it seems it was not enough. Is there any way to copy the metadata for each image and write it back to the images after doing all of the pre-processing steps?

My code saves stacked images and also each individual bands so we can use pix4d for further processing.

Thanks, Ali

poynting commented 5 years ago

Please see https://github.com/micasense/imageprocessing/issues/67 and let me know if this answers your question.

moghi005 commented 5 years ago

I followed your suggestion and saved each band separately as a tif file. I also used the 'batch processing' code to write the metadata.However, it didn't help. As you mentioned, I want to save metadata back to each band so we can use pix4D.

I wonder if there is a way to copy all the metadata from each band before the preprocessing and write it back after the preprocessing.

Thanks, Ali


Ali Moghimi https://about.me/alimoghimi

PhD Candidate & Graduate Research Assistant University of Minnesota - Twin Cities 1390 Eckles Ave. Room 2, St. Paul, MN 55108

On Mon, Aug 26, 2019 at 9:59 PM Justin M. notifications@github.com wrote:

Please see #67 https://github.com/micasense/imageprocessing/issues/67 and let me know if this answers your question.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/micasense/imageprocessing/issues/69?email_source=notifications&email_token=AGZCYF7DBCC6ZAEFWUV44ATQGSYCHA5CNFSM4IPYKKZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5GPOAI#issuecomment-525137665, or mute the thread https://github.com/notifications/unsubscribe-auth/AGZCYF6GEMIM27HYTX5QOYTQGSYCHANCNFSM4IPYKKZA .

poynting commented 5 years ago

My suggestion is to not process in that way, due to complexities with the way Pix4D handles rig metadata and calibration. If you do need to, you'll want to work closely with Pix4D to sort out what specific metadata is required to do proper rig alignment but not do any radiometry, and then work through how to save that data back. The approach used in the batch processing script should be fine, you'll just need to change how your filenames map in the CSV file.

My suggestion is to instead use the alignment and batch processing notebooks together to create aligned, radiometrically corrected stacks of 5 (or 6) bands, and then use Pix4D to process those stacks. This avoids the complexities in how Pix4D handles rigs, but lets you use the reflectance map workflow which does much better averaging than the orthomosaic workflow and results in better radiometric results.

moghi005 commented 5 years ago

Thanks for your prompt reply.

Can we process the stacked images (5 bands) with pix4d and get orthomosaic? My pipeline also saves stacked images in a separate folder. I only need to save individual bands for pix4d processing. If pix4d can do orthomosaic with stacked images, we may want to skip saving the individual images, am I right?

The stacked images have been already aligned and converted to reflectance. If we use reflectance map workflow, does pix4d try to convert them again to reflectance using panel reflectance value entered by user? Since we already converted to radiance and then reflectance, we don't want pix4d do it again.

Regarding the filenames, should filenames (image path + image name) be saved as the first column in the csv file (as it is in the batch processing code)? I saved them as the last column (attached is an example of my csv files).


Ali Moghimi https://about.me/alimoghimi

PhD Candidate & Graduate Research Assistant University of Minnesota - Twin Cities 1390 Eckles Ave. Room 2, St. Paul, MN 55108

On Tue, Aug 27, 2019 at 10:56 AM Justin M. notifications@github.com wrote:

My suggestion is to not process in that way, due to complexities with the way Pix4D handles rig metadata and calibration. If you do need to, you'll want to work closely with Pix4D to sort out what specific metadata is required to do proper rig alignment but not do any radiometry, and then work through how to save that data back. The approach used in the batch processing script should be fine, you'll just need to change how your filenames map in the CSV file.

My suggestion is to instead use the alignment and batch processing notebooks together to create aligned, radiometrically corrected stacks of 5 (or 6) bands, and then use Pix4D to process those stacks. This avoids the complexities in how Pix4D handles rigs, but lets you use the reflectance map workflow which does much better averaging than the orthomosaic workflow and results in better radiometric results.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/micasense/imageprocessing/issues/69?email_source=notifications&email_token=AGZCYF4KUZXIOF4OABATR5DQGVTFPA5CNFSM4IPYKKZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5IS5SQ#issuecomment-525414090, or mute the thread https://github.com/notifications/unsubscribe-auth/AGZCYF5OSEPCXDK4HMAF27TQGVTFPANCNFSM4IPYKKZA .

poynting commented 5 years ago

If you use the Batch processing notebook to create your stacks, and you don't add any radiometric metadata or panel images (only location and time), then Pix4D will process through the reflectance workflow with strong averaging but without modifying the scale of the images.

For the specifications of the CSV file, you'll want to check the exiftool documentation. It's pretty specific about which fields it takes and how they're formatted.

moghi005 commented 5 years ago

I'll look into that.

Is there a way to save stack files as geotiff rather than tiff?

Thanks, Ali


Ali Moghimi https://about.me/alimoghimi

PhD Candidate & Graduate Research Assistant University of Minnesota - Twin Cities 1390 Eckles Ave. Room 2, St. Paul, MN 55108

On Tue, Aug 27, 2019 at 11:52 AM Justin M. notifications@github.com wrote:

If you use the Batch processing notebook to create your stacks, and you don't add any radiometric metadata or panel images (only location and time), then Pix4D will process through the reflectance workflow with strong averaging but without modifying the scale of the images.

For the specifications of the CSV file, you'll want to check the exiftool documentation. It's pretty specific about which fields it takes and how they're formatted.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/micasense/imageprocessing/issues/69?email_source=notifications&email_token=AGZCYF3AT5TTI36JOIZIM73QGVZWPA5CNFSM4IPYKKZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5IYGKI#issuecomment-525435689, or mute the thread https://github.com/notifications/unsubscribe-auth/AGZCYF6DCR7JLH3YG4YPUC3QGVZWPANCNFSM4IPYKKZA .

poynting commented 5 years ago

No. A geotiff requires georeferencing to project the image onto the Earth's surface, which requires knowing precisely where the camera is pointed, what the terrain looks like, how high the camera was when the picture was taken, etc. Determining all of that information is what Pix4D is doing for us.

Matesanz commented 3 years ago

If it helps anyone that was my solution :smile: :

import os
from pathlib import Path

def transfer_metadata(from_path: str, to_path: str) -> None:
    """
    Transfer metadata from one file to another
    Args:
        from_path (str): file path to extract the metadata from
        to_path (str): file path to inject metadata to
    """
    if Path(from_path).exists() and Path(to_path).exists():
        cmd = 'exiftool -TagsFromFile {} {}'.format(from_path, to_path)
        os.system(cmd)