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.

  • The 3DS is a camera too! It's not about the equipment etc… – Kevin Chen Aug 20 '17 at 4:13

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

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.

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

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.

  • 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. – spacer GIF Aug 18 '17 at 23:34
  • Two images taken from the same position and same point of view cannot provide a stereo imaging pair. It's impossible. – StephenG Aug 18 '17 at 23:36
  • 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). – spacer GIF Aug 18 '17 at 23:44
  • 1
    So it's not really 3D data then, correct? – scottbb Aug 19 '17 at 11:52
  • I guess you could say it's not really 3D data. It technically is, but with both perspectives being identical... – spacer GIF Aug 19 '17 at 13:57

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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