Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change in image properties after performing EXIF operation #6925

Open
sumedhvidhate opened this issue Dec 6, 2023 · 2 comments
Open

Change in image properties after performing EXIF operation #6925

sumedhvidhate opened this issue Dec 6, 2023 · 2 comments

Comments

@sumedhvidhate
Copy link

ImageMagick version

13.4.0

Operating system

Windows

Operating system, version and so on

Windows 11, Magick.NET.Core

Description

When performing EXIF operation on the image, image properties are getting changed. On carrying out pixel by pixel comparison there was around 50% pixels changed.

Steps to Reproduce

The code I'm using is as follows

        XmpMetaFactory.SchemaRegistry.RegisterNamespace("http://www.pix4d.com", "Camera");

        try
        {
            using (MagickImage image = new MagickImage(_imagePath))
            {

                #region Add EXIF metadata

                IExifProfile exifProfile = image.GetExifProfile();
                if (exifProfile == null)
                {
                    exifProfile = new ExifProfile();
                }

                exifProfile.SetValue(ExifTag.GPSLatitudeRef, _latitude >= 0 ? "N" : "S"); // select between northern (N) / southern (S) hemisphere
                var data = ConvertToRationalDMS(Math.Abs(_latitude));
                exifProfile.SetValue(ExifTag.GPSLatitude, data);

                data = ConvertToRationalDMS(Math.Abs(_longitude));
                exifProfile.SetValue(ExifTag.GPSLongitudeRef, _longitude >= 0 ? "E" : "W"); // select between eastern (E) / western (W) hemisphere
                exifProfile.SetValue(ExifTag.GPSLongitude, data);

                exifProfile.SetValue(ExifTag.GPSAltitudeRef, _altitude >= 0 ? (byte)0 : (byte)1); // select between above (0) / below (1)  sea-level
                exifProfile.SetValue(ExifTag.GPSAltitude, new Rational(Math.Abs(_altitude)));

                image.SetProfile(exifProfile);

                #endregion

                #region Add XMP metadata

                IXmpProfile xmpProfile1 = image.GetXmpProfile();

                Console.WriteLine();

                IXmpMeta xmpData = XmpMetaFactory.Create();

                xmpData.SetProperty("http://www.pix4d.com", "GPSXAccuracy", $"{_gpsXAccuracy:0.0000000000}");
                xmpData.SetProperty("http://www.pix4d.com", "GPSYAccuracy", $"{_gpsYAccuracy:0.0000000000}");
                xmpData.SetProperty("http://www.pix4d.com", "GPSZAccuracy", $"{_gpsZAccuracy:0.0000000000}");
                xmpData.SetProperty("http://www.pix4d.com", "GPSXYAccuracy", $"{_gpsXYAccuracy:0.0000000000}");
                xmpData.SetProperty("http://www.pix4d.com", "RINEXTimestamp", $"{_eventTime:yyyyMMdd_HHmmss.fff}");

                string serializedData = XmpMetaFactory.SerializeToString(xmpData, new XmpCore.Options.SerializeOptions());
                IXmpProfile xmpProfile = new XmpProfile(System.Text.Encoding.UTF8.GetBytes(serializedData));

                image.SetProfile(xmpProfile);

                #endregion
                image.Interlace = Interlace.NoInterlace;
                image.Quality = 100;
                image.Settings.Compression = CompressionMethod.NoCompression;
                var optimizer = new ImageOptimizer();
                optimizer.LosslessCompress(_imagePath);

                image.Write(_newImagePath);
            }
        }
        catch (Exception exp)
        {
        }

    }

Images

No response

@snibgo
Copy link

snibgo commented Dec 6, 2023

You don't show your input and output images, so we can only guess.

I guess your output format is lossy, eg jpeg compression.

@sumedhvidhate
Copy link
Author

You don't show your input and output images, so we can only guess.

I guess your output format is lossy, eg jpeg compression.

Here i'm attaching the images in the drive link below
https://drive.google.com/drive/folders/1ggSsa2eM1IS-fDxVTuHK8P5P6_i3XCnB?usp=drive_link

We are using this images for photogrammetry purpose and ortho-mosaic generation.
There is significant change in the size too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants