Results 1 to 3 of 3

Thread: Subtract QImage

  1. #1
    Join Date
    Dec 2010
    Posts
    55
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Subtract QImage

    I would like to subtract two QImages so the resultant image shows a difference.
    I know I can brute-force loop through each pixel and subtract that way.

    I was wondering if there is already a built in function that can do this.
    Running:
    RHEL 5.4
    Python 2.7.2
    Qt 4.7.4
    SIP 4.7.8
    PyQt 4.7

  2. #2
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Subtract QImage

    First, I don't see anything in the Qpixmap documentation or QIcon documentation that suggests this functionality is in place; but it's worth noting that your problem is not well-defined:

    -What happens if you subtract a larger from a smaller number? (I.E. (20,20,20)Pixel - (40,40,40)Pixel)
    -What happens between a color without an alpha value vs. one with an alpha value?
    (I.E. (20,20,20,255) - (20,20,20))
    -Must the images be the same size? If not, what do you do? You could error out, or you could just show the difference between the existing values. Or show an image only modified by the difference of the smaller picture.
    -etc..


    There are probably a billion very specific cases you'll cover in your own code. Were there functionality in place already you'd probably have to modify it. There are (somewhat) obvious solutions such as:
    -Treat "no" alpha value as 255
    -Subtract only until you hit zero
    -Show the absolute value of the difference between pixels
    -etc..

    but even so, it's such an odd thing to ask for IMO that it's unlikely two people wanting it would program it the same.


    IMO Go with the simple:
    Qt Code:
    1. for each x pixel
    2. for each y pixel
    3. new_images_pixle(absolute_value(image1.x,image2.x),absolute_value(image1.y,image2.y))
    To copy to clipboard, switch view to plain text mode 

    and cover all of your goofy issues the way you desire.

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

    Default Re: Subtract QImage

    I've seen this function in various imaging and math software.
    The same sized image would need to be used.
    Typical the Absolute Value is taken so black would mean no difference.
    However sometimes the number is allowed to go negative then it is normalized so grey would mean no difference.

    But yes I pretty much went with what you said.
    Running:
    RHEL 5.4
    Python 2.7.2
    Qt 4.7.4
    SIP 4.7.8
    PyQt 4.7

Similar Threads

  1. QImage* to QImage
    By bajoelkid12 in forum Qt Programming
    Replies: 1
    Last Post: 19th June 2011, 11:15
  2. Replies: 5
    Last Post: 16th May 2011, 21:15
  3. QImage and Qt 4.5.3
    By halmassi in forum Newbie
    Replies: 26
    Last Post: 10th March 2010, 21:49
  4. What's faster: QPixmap-to-QImage or QImage-to-QPixmap
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2006, 17:11
  5. Replies: 3
    Last Post: 15th March 2006, 11:44

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.