×

Discussion Board

Results 1 to 3 of 3

Hybrid View

  1. #1
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    271

    Question Best practises for performing Image Processing in S40?

    Hi

    I have been experimenting with Image processing for a while.I came across a whole range of problems while doing the same.Most of them were concerned with the limited memory.I read a lot on best practises for memory management,but none of them were specific to image processing.Here are some of the problems I encountered.

    1.) Reading a JPEG file

    The 2-4 MB heap space made it almost impossible to decompress a JPEG image.I was forced to use a scaled down version of the original.

    2.) Getting Snapshot from the camera

    The snapshot obtained from the camera is of a lower resolution than the maximum resolution possible.

    3.) Manipulating the image(Image filters)

    For performing image filters, I had to store two versions of the image in memory.One was the original snapshot obtained.Other was the image obtained after applying a particular effect(say grayscale).The memory problem became very prominent from here.For simple effects,it was okay.But for complex effects, retaining even two images in memory became impossible.

    Most of the techniques for efficient memory management in J2ME were not useful in this situation.Weak references were useless as I need to keep both images alive in the memory.I have set all the useless variables to null as soon as their purpose is done.I inclued calls to System.gc() in many places.It was still not enough.The only option I had was to scale down the images so that there was enough memory to store both of them

    4.) Storing the image in file system.

    Even if there is enough memory to store two images,storing the image posed another problem.I had to use either a PNG or a JPEG encoder.The encoding process required some amount of memory.The application crashed due to lack of memory.
    Once again, I had to scale down the image in order to make enough room for the encoding process to happen.

    For all the problems , only solution I was able to find was to scale down the image in a huge way.This is really disappointing as the quality of the final image is very very bad when compared to the original.The users of my app are very unhappy because of this.

    Is there any other way to solve this problem? Is there any best practises I should follow while handling camera images?

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Best practises for performing Image Processing in S40?

    Yes, it is a tricky problem.

    Decompressed, an image is likely to take (depending on device) between two and four bytes per pixel. At four bytes per pixel, a 5Mpixel image needs 20Mb of memory... bad news for almost anything running Java ME.

    In 2Mb of heap, with a need to keep two copies of the image in memory, even 640x480 could push you over the edge.

    Avoid calling System.gc(). It won't have any benefit on any device with a compacting garbage collector (all but the very earliest of S40 devices), and causes a big performance drop on some devices (especially Nokia Series 60 devices).

    Pretty much your only option would be to maintain images in compressed form, and decompress the image only in small parts. For example, decompress one scanline, process it, then compress the processed version before decompressing the next scanline. The built in decoders are not likely to help you, so you'd need to implement your own, not a trivial job unless you've done this before.

    [edit]
    Forcing the camera resolution:
    Code:
    byte[] snapshot = control.getSnapshot("encoding=image/jpeg&width=" + WIDTH + "&height=" + HEIGHT);
    This is likely to throw an exception if the resolution you ask for is not supported by the camera.
    [/edit]

    Graham.
    Last edited by grahamhughes; 2013-04-21 at 19:27.

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    1,980

    Re: Best practises for performing Image Processing in S40?

    In S40 platform,getting Snapshot from the camera is supportted not well than other platforms,such as Symbian.So what the developers can do is few.

Similar Threads

  1. Replies: 0
    Last Post: 2011-12-19, 23:15
  2. about image processing......
    By rahulvala in forum Symbian
    Replies: 3
    Last Post: 2008-10-10, 17:41
  3. performing image processing
    By rashmi_ghai in forum Symbian Tools & SDKs
    Replies: 13
    Last Post: 2007-03-04, 08:10
  4. Image processing
    By zhenwe1 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2004-02-16, 16:27
  5. performing image processing
    By rashmi_ghai in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-11-19, 16:33

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×