Results 1 to 4 of 4

Thread: QImage - Get the RGB component of a certain pixel

  1. #1
    Join Date
    Jun 2007
    Location
    Plymouth, UK
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QImage - Get the RGB component of a certain pixel

    Hi everyone,

    I'm stuck with an issue that looks quite stupid to me. Nonetheless I don't seem to be smart enough to solve it... :/

    What I'm trying to do is simply to read the RGB values of a pixel contained in a QImage. To do so I'm using the following instructions:

    Qt Code:
    1. X = rand() % originalImage.width();
    2. Y = rand() % originalImage.height();
    3.  
    4. QRgb tempColorRgb = originalImage.pixel(QPoint(X,Y));
    5. QColor tempColor(tempColorRgb);
    6.  
    7. printf("RGB components of the pixel selected: %d %d %d\n", tempColor.red(), tempColor.green(), tempColor.blue());
    To copy to clipboard, switch view to plain text mode 

    What I get is that all the values look the same, whatever pixel I select. For example:

    RGB components of the pixel selected: 0 0 0
    RGB components of the pixel selected: 241 241 241
    RGB components of the pixel selected: 27 27 27


    OriginalImage is a QImage declared and initialised elsewhere in the code. It actually contains a jpeg picture loaded from the disk. I'm confident there's nothing wrong with it, as it is visible (it's displayed on my GUI) and accessible from the code above (I tried to save it with an instruction in the portion of the code below and everything went fine).

    Am I doing something obviously and terribly wrong which I can't notice?
    Last edited by fabietto; 1st July 2011 at 16:46. Reason: Simplified the code

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage - Get the RGB component of a certain pixel

    Can you send your image??
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Jun 2007
    Location
    Plymouth, UK
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImage - Get the RGB component of a certain pixel

    Sure. Didn't think that was an issue concerning the image, but in case that might help... here we go:
    http://www.fabioruini.eu/Plymouth/do...censorship.jpg

    It is loaded into a QImage just using the function:

    Qt Code:
    1. originalImage.load(picturePath);
    To copy to clipboard, switch view to plain text mode 

    where picturePath is a QString that I get from a lineEdit on the GUI. Its format (as returned by originalImage.format()) is RGB32.


    Added after 14 minutes:


    The problem was the image indeed! Thanks for the hint!
    Last edited by fabietto; 1st July 2011 at 17:22.

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage - Get the RGB component of a certain pixel

    Your image use only gray scale colors, so its normal that RGB components have the same values.

    I changed your image to colored

    image.jpg

    and the result is

    result.JPG

    PS. Are you Italian??
    Last edited by mcosta; 1st July 2011 at 17:41. Reason: updated contents
    A camel can go 14 days without drink,
    I can't!!!

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

    fabietto (1st July 2011)

Similar Threads

  1. QImage.pixel and Format_Indexed8
    By chef_seppel in forum Newbie
    Replies: 2
    Last Post: 29th September 2010, 23:17
  2. Shifting a QImage up by 1 pixel row
    By MSUdom5 in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2010, 11:25
  3. QImage direct pixel access.
    By hickscorp in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2010, 11:23
  4. QImage Pixel Coordinations
    By strateng in forum Newbie
    Replies: 2
    Last Post: 6th May 2010, 11:00
  5. Multithreaded per pixel operations on QImage
    By N¤X in forum Qt Programming
    Replies: 8
    Last Post: 14th September 2009, 13:29

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.