2
$\begingroup$

Why Mathematica modifies imported images on exporting them?

Example:

Import["C:\\image1.jpg"];
Export["C:\\image2.jpg",%]

and now files image1.jpg and image2.jpg are not identical.

What is a purpose of this? The user did not have made any manipulation to the image, so why the exact same file was not created?

Say I want to change orientation of an image by changing "orientation" parameter in EXIF. The output of exporting such an image should be file with the same size as the original image and the two images should differ only in one byte - byte that encodes EXIF orientation.

$\endgroup$
1
$\begingroup$

When you import an image to Mathematica, you're getting the image data that can be manipulated, edited and processed. Mathematica acts like other photo editors, e.g., Adobe Photoshop. After an image is read (imported), edited, and saved (exported), the original file and the new file are not the same. Even if you make no change to the image, it's possible that the saved file will not be an exact copy of the original. In the case of JPEG files, the image data is re-compressed and the saved file won't be an exact copy of the original.

What you want is not an photo editor, but a metadata editor. Metadata editors don't change the image data. They change tags within a file without changing the image data. Wikipedia has an extensive list of metadata editors.

$\endgroup$
  • $\begingroup$ Thank you for reply. But it should be possible to detect the position of orientation byte within image file with Mathematica. Then read image as byte file, change the orientation byte as you like and then export the file again as byte file. But the problem is, that I do not know how to detect the position of the orientation byte with Mathematica. I do not want to use other tools, I want to use Mathematica to do the job. $\endgroup$ – azerbajdzan Oct 29 '17 at 9:53
  • $\begingroup$ Import and Export are not useful for what you want to do. Check the BinaryRead and BinaryWrite low-level file operations, and Binary Files documentation. $\endgroup$ – creidhne Oct 29 '17 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.