Display LIF Images in 4V
Convert LIF Image format to a Quad and render it on a QuadView.
Last updated
Convert LIF Image format to a Quad and render it on a QuadView.
Last updated
Copyright © 2023 Leia Inc. All Rights Reserved
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.
We will be working with a LIF image in this project. Copy over the following image to your Android project's raw resource directory.
Optionally, you can work with your own LIF image.
Setup the project by adding the dependency for the Leia Android Media SDK to your project.
In order to convert a LIF image, we need to retrieve the file from the resource directory as byte[]
We open the raw resource as an InputStream using Resources#openRawResource(int res)
Convert the input stream to a byte representation using IOUtils
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.
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.
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.
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.
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.
You now have the Quad Bitmap which can be used to display the image in 4V using the QuadView.
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.
In the tutorial above, you learnt how to decode an image using the image bytes[]
. However, the MultiviewImageDecoder
can 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.
In the next tutorial, you will learn how to decode and display a SBS (2x1) image using the QuadView.