Display LIF Images in 4V
Convert LIF Image format to a Quad and render it on a QuadView.
As discussed in previous sections, a QuadView requires a Quad Bitmap to render an image in 4V. The Android Media SDK provides support for different image types. In order to render a Leia Image Format or other supported formats like SBS, you need to first decode them and generate viewpoints.
The Leia Android Media SDK provides flexible APIs to convert the different supported image formats. This section provides a step-by-step guide on rendering a Leia Image Format or LIF image using a QuadView.
For this tutorial, you will load a LIF image from your Android project's resource directory, decode it and generate views to obtain a Quad bitmap. You can then display the Quad using the QuadView.

Setup Resources

We will be working with a LIF image in this project. Copy over the following image to your Android project's raw resource directory.
farm-lif.jpeg
farm-lif.jpeg
5MB
Image
farm-lif
Optionally, you can work with your own LIF image.

Setup Environment

Retrieve LIF file

In order to convert a LIF image, we need to retrieve the file from the resource directory as byte[]
Kotlin
Java
1
val fileInputStream = resources.openRawResource(R.raw.farm_lif)
2
fileInputStream.use {
3
val imageBytes = IOUtils.toByteArray(it)
4
}
Copied!
1
try (InputStream fileInputStream = getResources().openRawResource(R.raw.farm_lif)) {
2
byte[] imageBytes = IOUtls.toByteArray(fileInputStream);
3
}
Copied!
  • We open the raw resource as an InputStream using Resources#openRawResource(int res)
  • Convert the input stream to a byte representation using IOUtils

Decode LIF image

After you retrieve the file, you can decode the LIF using the MultiviewImageDecoder to obtain a MultiviewImage instance. A MultiviewImage is a decoded representation of image formats supported by a Leia Light-field device. You can learn about the Multiview Image here.
Kotlin
Java
1
val fileInputStream = context.resources.openRawResource(R.raw.farm_lif)
2
fileInputStream.use {
3
val imageBytes = IOUtils.toByteArray(it)
4
5
// Decode LIF image bytes to obtain multiview image
6
val multiviewImage = MultiviewImageDecoder.getDefault().decode(imageBytes, 1280 * 720)
7
}
Copied!
1
InputStream fileInputStream = getResources().openRawResource(R.raw.farm_lif);
2
byte[] imageBytes = IOUtls.toByteArray(fileInputStream);
3
4
// Decode LIF image bytes to obtain multiview image
5
MultiviewImage multiviewImage = MultiviewImageDecoder.getDefault().decode(imageBytes, 1280 * 720);
6
Copied!
  • The decode() function takes in the byte[] and the number of output resolution pixels as parameters.
  • We will set the output pixels to 1280 x 720 for this tutorial. This ensures that all the decoded view points have the same resolution specified here.
  • The decoder returns null if the file passed in is not an image format supported by the SDK.
Note: The code in this step should be called on a worker thread.

Populate Disparity Maps

The MultiviewImage obtained in the previous step can now be used to generate view points and convert the image to a Quad.
In order to do so, we can use the MultiviewSynthesizer2 to synthesize the MultiviewImage and generate the disparity maps, if required.
Kotlin
Java
1
// Obtain MultiviewSynthesizer instance
2
val synthesizer = MultiviewSynthesizer2.createMultiviewSynthesizer(context)
3
4
// Populate Disparity maps
5
synthesizer.populateDisparityMaps(multiviewImage)
6
Copied!
1
// Obtain MultiviewSynthesizer instance
2
MultiviewSynthesizer2 synthesizer = MultiviewSynthesizer2.createMultiviewSynthesizer(context);
3
4
// Populate Disparity maps
5
synthesizer.populateDisparityMaps(multiviewImage);
Copied!
  • Obtain the MultiviewSynthesizer2 instance using the MultiviewSynthesizer2.createMultiviewSynthesizer(Context context) function.
  • Generate the disparity maps for the MultiviewImage using MultiviewSynthesizer2#populateDisparityMaps(MultiviewImage).
  • Disparity maps are essential for generating the different view points in a Quad image. Disparity maps will only be populated by this function, if not already present in the MultiviewImage
Note: All steps in this section should be called on a worker thread.

View Synthesis to Quad

Finally, obtain a Quad Bitmap by converting the MultiviewImage to a Quad using the MultiviewSynthesizer2#toQuadBitmap(MultiviewImage) function. This synthesizes the Multiview Image to generate 4 viewpoints and return a Bitmap representing a Quad image.
Kotlin
Java
1
val quadBitmap = synthesizer2.toQuadBitmap(multiviewImage)
Copied!
1
Bitmap quadBitmap = synthesizer2.toQuadBitmap(multiviewImage);
Copied!

Set Quad in QuadView

You now have the Quad Bitmap which can be used to display the image in 4V using the QuadView.
Kotlin
Java
1
quadView.setQuadBitmap(quadBitmap)
Copied!
1
quadView.setQuadBitmap(quadBitmap);
Copied!

Build your app

If you followed the steps correctly, you should be able to view the LIF image in 4V in your Android project.
Feel free to refer to the sample project on Github, which performs decoding and view synthesis on a worker thread, while following Android best practices.

Decode using File or Content Uris

In the tutorial above, you learnt how to decode an image using the image bytes[]. However, the MultiviewImageDecodercan also decode files using the File Uri or ContentUris.
You can use this to load LIF images stored on the device's internal storage and decode them directly using their Uri. You can learn more about the different decoding options here.
Kotlin
Java
1
val contentUri: Uri;
2
// ..
3
// Obtain uri of file on device storage
4
5
// Decode image using Uri to obtain Multiview Image
6
val multiviewImage = MultiviewImageDecoder.getDefault().decode(context, contentUri, 1280 * 720)
Copied!
1
Uri contentUri;
2
// ..
3
// Obtain uri of file on device storage
4
5
// Decode image using Uri to obtain Multiview Image
6
MultiviewImage multiviewImage = MultiviewImageDecoder.getDefault().decode(context, contentUri, 1280 * 720);
Copied!
In the next tutorial, you will learn how to decode and display a SBS (2x1) image using the QuadView.
Last modified 11mo ago