0
$\begingroup$

When exporting an image from the Mathematica and comparing it to the same image in the code using ImageData[Img,Byte], it results into 2 different vectors , so what's wrong with the exporting method ?! and, is there any another way of exporting an image without using Export[ ] method ?

CarImg = Import["D:\Images\MonaLisa.jpg"]; 

X=ImageData[CarImg,Byte]; 

Y=ImageData[Import[Export["Image.jpg",CarImg]],Byte]; 

Values of the Original Image: {{{124, 128, 98}, {80, 89, 62}, {87, 100, 81}, {90, 109, 91}, {87, 109,89}, {75, 92, 68}, {82, 94, 64}, {92, 100, 66}, {78, 98, 87}, {97, 118, 101}, {88, 114, 89}}}

Values of the Exported Image: {{{116, 128, 118}, {69, 81, 69}, {89, 99, 88}, {94, 105, 89}, {99, 107, 92}, {79, 88, 69}, {82, 94, 74}, {87, 101, 78}, {83, 97,74}, {102, 120, 96}}}

Values aren't identical. I want to preserve the values of the original image when exporting.

$\endgroup$

closed as off-topic by C. E., rhermans, MarcoB, Henrik Schumacher, halirutan Jul 16 '18 at 22:36

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – C. E., rhermans, MarcoB, Henrik Schumacher, halirutan
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ Please post a MWE. How did you compare the image you exported with the image in the notebook? Images displayed in notebook are raster format, but image on disk can be any other binary format such as png or jpg etc... when you export an image from the notebook to a file and give it a format, Mathematica converts the image to that format. So you can't expect the bits in the file to be the same as displayed inside the notebook. $\endgroup$ – Nasser Mar 17 '18 at 5:01
  • 1
    $\begingroup$ Again, your description of the problem is not clear. You are not showing all the steps. Was the original image imported from an image file first, then you exported it back again? Or it was a Mathematica Graphics you created inside the notebook? Please show all the code you used so that the issue is made more clear. $\endgroup$ – Nasser Mar 17 '18 at 5:41
  • 1
    $\begingroup$ Would it be possible for you to upload your MonaLisa.jpg to an image host? $\endgroup$ – J. M. will be back soon Mar 17 '18 at 12:18
  • 5
    $\begingroup$ JPEG encoding uses lossy compression, so you will not generally get back the same data when you decode it. $\endgroup$ – John Doty Mar 17 '18 at 12:33
  • 3
    $\begingroup$ right, even though you started out with a jpg, it is highly unlikely you will get the same jpg when you re-compress it. Use something lossless like tiff. $\endgroup$ – george2079 Mar 17 '18 at 13:04
2
$\begingroup$

I found a solution which is saving the image as ".png" instead of ".jpg" to preserve it's original quality.

$\endgroup$
  • 1
    $\begingroup$ Sounds like this is related to JPG being a lossy image format and PNG being a lossless image format. $\endgroup$ – Edmund Mar 17 '18 at 21:52

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