Results 1 to 8 of 8

Thread: Image reading and writing line by line

  1. #1
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Image reading and writing line by line

    Hi there. Would you please, guys help me out? I have got an image and sometimes a huge one. In order to avoid memory problems I would like to read an image line by line and after having processed each line I would want to write it to an output image.
    The problem is I need to use QImage::scaled() function (or similar which can provide efficient scaling procedure which I need use) that suits me fine.
    First guess is to divide input image into number of QImages (let's say, number of lines of input image) and accomplish scaling procedure on each of them. But how will I write all of them into single output image? There may be another solution or more suitable Q-class I'm not aware of. Anyway you're welcome to give any input on this. Thank you so much in advance.
    Last edited by Astrologer; 28th April 2010 at 14:08.

  2. #2
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: Image reading and writing line by line

    I doubt you can do that. Images are usually compressed so there is no simple way to read just a line. I might be wrong, I am not an expert on images, but I think to get a line of a jpeg there is no other way to fully load it into memory and uncompress it there resulting in an even larger image in memory.

  3. #3
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image reading and writing line by line

    Thank you for help. Actually I can use QImageReader to split it as:
    Qt Code:
    1. QImageReader imagereader(input_jpg_name);
    2. imagereader.setScaledSize(QSize(500,500));
    3. QImage img1 = imagereader.read();
    To copy to clipboard, switch view to plain text mode 
    avoiding memory wasting. Any other suggestions, guys?
    Last edited by Astrologer; 28th April 2010 at 13:42.

  4. #4
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: Image reading and writing line by line

    From the QImageReader docs:
    Depending on the underlying support in the image format, this can save memory and speed up loading of images.

    So even if you can get a scaled image from QImageReader, it does not necessarily mean that you can save memory.

  5. #5
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image reading and writing line by line

    I see your point. That's exactly the problem that I am longing for solution which will help me. I have an image let's say 20000x20000. If not up to QImageReader I can't see a way QT can handle it. If I feed the image directly to QImage it returns zero width and zero height purpotedly because of the size. If I do it with example written above, it works and saves a thumbnail size of 500x500. Memory can be saved as I pointed out by cropping the big one into slices size of one pixel, for example.
    Last edited by Astrologer; 28th April 2010 at 13:42.

  6. #6
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image reading and writing line by line

    Hey, guys. Ain't there any idea?

  7. #7
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Image reading and writing line by line

    Qt doesn't really give you access to the primitive graphics and image file functions you need to do this properly. If your solution works for your purposes, then you're done. But as noted, there are potential problems with it.

    Most modern image formats use some sort of compression. In JPEG, images are processed in 8x8 blocks, so you would need access to the raw JPEG library to read strips, which would decompress into more than a single line. Other formats, like JPEG2000, use wavelet transforms for compression, and the spatial information in the image is scattered throughout the compressed data, making retrieval of individual lines or blocks problematic.

    For similar reasons, your procedure of removing blocks, reducing them and then stitching them back together to produce a single, reduced image may produce "seams" around the edges of your individual tiles, because the compression algorithm relies on a broad "neighborhood" around each pixel and behaves differently near edges. You'll want to inspect your images carefully after reassembly to see if these are visible, or if they are objectionable.

    A better solution would be to use a tool like ImageMagick, an image processing toolkit that can be used from either the command line or through a C++ interface. It allows you to set the maximum amount of memory an operation will consume, and is careful not to exceed that limit, although more memory results in greater execution speed. But when dealing with really huge images, it is often the best solution available. It's scaling algorithms are top-notch, as well, and their advantages and shortcomings are carefully documented. Plus, it's free.

  8. The following user says thank you to SixDegrees for this useful post:

    Astrologer (29th April 2010)

  9. #8
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image reading and writing line by line

    Yes, it seems to be a great library, though I just skimmed over it. I am going to plough on with the library. Thank you all, guys.

Similar Threads

  1. New line when writing a File
    By locke in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2011, 11:27
  2. Replies: 1
    Last Post: 21st November 2009, 08:29
  3. Why doesn't the line appear on my Image?
    By Gh0stR1der in forum Newbie
    Replies: 1
    Last Post: 18th April 2009, 23:42
  4. Replies: 0
    Last Post: 28th February 2009, 23:18
  5. Almost reading QImage line by line, help me please.
    By newqtuser in forum Qt Programming
    Replies: 4
    Last Post: 18th July 2008, 14:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.