Results 1 to 11 of 11

Thread: Basic image processing on a QImage

  1. #1
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Basic image processing on a QImage

    Hello forum people,

    Does anyone know of an easy way to perform basic image processing algorithms on a QImage? I figured algorithms for modifying brightness and contrast where already implemented quite a few times in Qt, but I'm unable to find Qt functions or otherwise libraries that aren't a complete overkill for the task (e.g. using openCV and converting image formats back and forth).

    So far, I've implemented the basic brightness / contrast / gamma filters myself, but moving on to implementing a simple blur (convolution with a Gaussian window) is too much...

    Any suggestions?

    Thanks!
    Danny

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Basic image processing on a QImage

    Maybe you want to have a look at

    http://doc.qt.nokia.com/4.6/qgraphicseffect.html

    I didn't use it yet, though.

    HIH

    Johannes

  3. #3
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Basic image processing on a QImage

    Thanks for the quickly reply!

    I'm kind of new in Qt, but according to my understanding this class doesn't exactly do what I want. I think it's used as a rendering effect on a QGraphicItem, when rendered on a QGraphicView. (Works on a painter, when there is a draw() event, etc.)

    I really think I actually need something a lot more basic, just some trivial image processing code that works on the pixels of a QImage directly. Sounds like it must be implemented somewhere in Qt... no?

    Thanks,
    Danny

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Basic image processing on a QImage

    If you look into the implementation of QGraphicsEffect, you can see how it is implemented.

    They use some QPixMapFilters, which sadly are declared private (qpixmapfilter_p.h).. Bu you can look into those files and see how it is done:

    Blurring from qpixmapfilter.cpp:

    Qt Code:
    1. static QImage blurred(const QImage& image, const QRect& rect, int radius, bool alphaOnly = false)
    2. {
    3. int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
    4. int alpha = (radius < 1) ? 16 : (radius > 17) ? 1 : tab[radius-1];
    5.  
    6. QImage result = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
    7. int r1 = rect.top();
    8. int r2 = rect.bottom();
    9. int c1 = rect.left();
    10. int c2 = rect.right();
    11.  
    12. int bpl = result.bytesPerLine();
    13. int rgba[4];
    14. unsigned char* p;
    15.  
    16. int i1 = 0;
    17. int i2 = 3;
    18.  
    19. if (alphaOnly)
    20. i1 = i2 = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3);
    21.  
    22. for (int col = c1; col <= c2; col++) {
    23. p = result.scanLine(r1) + col * 4;
    24. for (int i = i1; i <= i2; i++)
    25. rgba[i] = p[i] << 4;
    26.  
    27. p += bpl;
    28. for (int j = r1; j < r2; j++, p += bpl)
    29. for (int i = i1; i <= i2; i++)
    30. p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
    31. }
    32.  
    33. for (int row = r1; row <= r2; row++) {
    34. p = result.scanLine(row) + c1 * 4;
    35. for (int i = i1; i <= i2; i++)
    36. rgba[i] = p[i] << 4;
    37.  
    38. p += 4;
    39. for (int j = c1; j < c2; j++, p += 4)
    40. for (int i = i1; i <= i2; i++)
    41. p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
    42. }
    43.  
    44. for (int col = c1; col <= c2; col++) {
    45. p = result.scanLine(r2) + col * 4;
    46. for (int i = i1; i <= i2; i++)
    47. rgba[i] = p[i] << 4;
    48.  
    49. p -= bpl;
    50. for (int j = r1; j < r2; j++, p -= bpl)
    51. for (int i = i1; i <= i2; i++)
    52. p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
    53. }
    54.  
    55. for (int row = r1; row <= r2; row++) {
    56. p = result.scanLine(row) + c2 * 4;
    57. for (int i = i1; i <= i2; i++)
    58. rgba[i] = p[i] << 4;
    59.  
    60. p -= 4;
    61. for (int j = c1; j < c2; j++, p -= 4)
    62. for (int i = i1; i <= i2; i++)
    63. p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
    64. }
    65.  
    66. return result;
    67. }
    To copy to clipboard, switch view to plain text mode 
    Good luck :-> !

    Johannes
    Last edited by JohannesMunk; 13th December 2009 at 18:07.

  5. The following user says thank you to JohannesMunk for this useful post:

    Danny (14th December 2009)

  6. #5
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Basic image processing on a QImage

    While not exactly what I originally wanted, your snippet was extremely useful!

    So it seems like a basic (Q)image processing Qt library doesn't exist, right? That's too bad...

    Thanks!
    Danny

  7. #6
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Basic image processing on a QImage

    Just found a QtSolution for this: http://qt.nokia.com/products/appdev/...timagefilters/

    HIH

    Johannes

  8. #7
    Join Date
    Jan 2010
    Posts
    18
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Basic image processing on a QImage

    The OpenCV library may be what you're looking for
    I'm using it at the moment with Qt for a computer vision application

  9. #8
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Basic image processing on a QImage

    I've posted a contrast and a brightness filter on this forum .
    you can check it out .

  10. #9
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Basic image processing on a QImage

    Can you share you contrast/brigthen filter ?
    I would like to have look at it.

  11. #10
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Basic image processing on a QImage

    you can use fmt_filters filters. this filter are written in c++ but is compatible whit QImage. only check the examples.

    homepage http://ksquirrel.sourceforge.net/subprojects.php

  12. #11
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Basic image processing on a QImage

    sorry by the double post..

    please. someone of the staf f can delte this..
    Last edited by ecanela; 27th January 2010 at 01:31.

Similar Threads

  1. [Qt4] How to load Url image into QImage?
    By Gonzalez in forum Qt Programming
    Replies: 6
    Last Post: 13th October 2014, 10:10
  2. get QImage object from buffer
    By Sheng in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2012, 02:03
  3. OpenCv & Qt4
    By switch in forum Qt Programming
    Replies: 0
    Last Post: 4th August 2009, 15:12
  4. Replies: 0
    Last Post: 26th October 2008, 13:56
  5. Image processing via matrix
    By jones.79 in forum Qt Programming
    Replies: 10
    Last Post: 22nd September 2008, 00:42

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.