Last Update: "2025-10-03 18:45:56 ban"
This MATLAB function reads an input MPO file and stores the image data as a MATLAB matrix. It is especially focusing on loading two (left/right-eyes) images extracted from one MPO photo file taken with FujiFilm Real W3 stereo camera and storing them separately into a MATLAB matrix. Any MPO file can be processed but have not fully tested yet.
Important note: The substantial update was applied on Oct 03 2025
The new version is optimized to be significantly faster than disk-based I/O by directly accessing the raw byte buffer of the decoded Java image object, minimizing data copies and type conversions between Java and MATLAB.
If you want to use this updated MEX routine, please copy the decode_jpeg_mex.mexw64 and jpeg62.dll files together with this imreadmpo_mex function to the same directory. You may need to compile decode_jpeg_mex.cpp by yourself depending on your environment. Importantly, even without the faster mex complied binary file, this function works using the previous 'fwrite' and 'imread' routines.
To compile decode_jpeg_mex.cpp by yourself, please follow the instructions written in the file.
function [imgs,imgsize,IFD,MPE,header]=imreadmpo(mpofile,:save_flg); % without the mex acceleration (previous routine with fwrite and imread)
function [imgs,imgsize,IFD,MPE,header]=imreadmpo_mex(mpofile,:save_flg); % with the mex acceleration (new and faster)
(: is option)
mpofile : input MPO-file name, a RELATIVE path format as the location where this function is called is the origin e.g. mpofile='../DSCF0008.mpo'; save_jpg_flg : whether saving the separated left and right-eye images as separated jpg file. [0|1]. 0 by defaut.
imgs : image object, a cell strucuturr imgsize : image size, [height, width] IFD : MP index IDF information MPE : MP entry information header : header information of the input MPO file
The MPO header structure is as below FF E2 00 9E 4D 50 46 00 | 4D 4D 00 2A | 00 00 00 08 | 00 03 B0 00 00 07 ... (APP2 marker) | (endian) (offset) | (MP index IFD, 12 byte x N blocks) ... (image data) | | | <-- offset_start | <-- mp_idx
imreadmpo -- A stereo photo image (*.mpo) reader. Copyright (c) 2015 Hiroshi Ban. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project.