3
\$\begingroup\$

I have some JPEGs captured from a Nintendo 3DS via Miiverse and would like to optimise them for the web.

The images are 2D but stored as a stereoscopic JPEG, so each file ends up containing the same image twice. In order to halve the amount of storage I require, it would be good to remove the second image. If I import one of the files into GIMP, I can see that exporting it with its original quality settings results in about half the file size. The only issue with this process (I'd automate it and use ImageMagick) is that surely it will result in picture quality degradation. So are there any ways of achieving lossless 2D image extraction? Linux-compatible only.

Although converting to PNG does reduce the size and would be lossless, it doesn't halve it. PNG8 isn't an option either as I require more than 256 colours. By the way, I'll also want to remove EXIF data but that can be done easily with exiv2.

\$\endgroup\$
1
  • \$\begingroup\$ The 3DS is a camera too! It's not about the equipment etc… \$\endgroup\$
    – Kevin Chen
    Aug 20, 2017 at 4:13

3 Answers 3

2
\$\begingroup\$

Here is a bash script that extracts left-right stereo pairs from mpo files using exiftool. Depending on the source of the file, the right image may be stored within a different tag.

#!/usr/bin/env bash

for i in *.mpo ; do
    j="${i#*/}"
    k="${j%.mpo}"

    # extract left images
    exiftool -trailer:all= "$i" -o "${k}.left.jpg"
    exiftool -TagsFromFile "$i" "${k}.left.jpg"

    # extract right images
    if exiftool "$i" | grep "MP Image 3" ; then
        # Samsung NX 45mm f/1.8 2D/3D
        exiftool "$i" -mpimage3 -b > "${k}.right.jpg"
        exiftool -TagsFromFile "$i" "${k}.right.jpg"
    else
        # Fujifilm Real 3D W3
        exiftool "$i" -mpimage2 -b > "${k}.right.jpg"
        exiftool -TagsFromFile "$i" "${k}.right.jpg"
    fi
done
\$\endgroup\$
1
\$\begingroup\$

I have found the solution to my problem.

JPEG images begin with FF D8 FF, so the solution for an individual file is to simply search for the second occurrence of this using a hex editor and remove it, along with everything that comes after it. Writing a script to automate this process should be straight-forward, and it could even split images into two separate files with ease - could be handy if your image actually has two perspectives.

Without stopping to think about it too much, I'm using this to extract the first image:
bbe -b '/\xFF\xD8\xFF\xE1/:' -e 'D 2' -o outputFile inputFile

It works. I'm happy. Stolen from this answer.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ If the image is stored as a multipart JPEG, it may be more robust to use exiftool: exiftool input.jpg -MPImage2 -b > output.jpg \$\endgroup\$
    – Kevin Chen
    Aug 20, 2017 at 4:16
-2
\$\begingroup\$

If I import one of the files into GIMP, I can see that exporting it with its original quality settings results in about half the file size.

Which it ought to be as you're doing exactly that.

The images are 2D but stored as a stereoscopic JPEG, so each file ends up containing the same image twice.

No it does not.

It contains two different images from different points of view.

They will be similar but not the same.

The only issue with this process (I'd automate it and use ImageMagick) is that surely it will result in picture quality degradation.

You have a two images and the only way to do this is to extract one or the other from the file.

So are there any ways of achieving lossless 2D image extraction? Linux-compatible only.

Apart reading from and saving to JPEG it is lossless.

You cannot sensibly merge the two distinct images as they are taken from two different points of view and you would introduce a number of parallax related artifacts in trying to merge them.

\$\endgroup\$
5
  • \$\begingroup\$ They were taken in 2D mode and when viewing the images on the system with 3D enabled, I can assure you they're both from the same point of view. \$\endgroup\$
    – spacer GIF
    Aug 18, 2017 at 23:34
  • \$\begingroup\$ Two images taken from the same position and same point of view cannot provide a stereo imaging pair. It's impossible. \$\endgroup\$ Aug 18, 2017 at 23:36
  • \$\begingroup\$ Think of it like having a mono recording encoded in a stereo sound file. It's just duplicate data. These stereoscopic JPEGs are much like animated GIFs - the first image will be visible in standard image viewers and only compatible ones can see the second image, or the right eye's perspective (which is identical to the left in this case). \$\endgroup\$
    – spacer GIF
    Aug 18, 2017 at 23:44
  • 1
    \$\begingroup\$ So it's not really 3D data then, correct? \$\endgroup\$
    – scottbb
    Aug 19, 2017 at 11:52
  • \$\begingroup\$ I guess you could say it's not really 3D data. It technically is, but with both perspectives being identical... \$\endgroup\$
    – spacer GIF
    Aug 19, 2017 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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