Python has bitwise operators I would suggest turning it into a bitstream and do a bit by bit comparison.

https://wiki.python.org/moin/BitwiseOperators


Quote Originally Posted by morph View Post
Hi.

I'm converting a QImage bitmap file between formats using PyQt.
After conversion I want to get back to the starting colours, because they change a tiny bit after converting.

Is there any accurate way to compare QColor objects and find the most similar one?

I've tried to compare rgb values, but it's not accurate enough:

Qt Code:
  1. def nearest_color(self, color):
  2.  
  3. col = QColor(color)
  4. r = col.red()
  5. g = col.green()
  6. b = col.blue()
  7. ranks = {}
  8. for orig_color in self.originalImageColors:
  9. orig_rgb = QColor(orig_color)
  10. diff = abs(orig_rgb.red() - r) + abs(orig_rgb.green() - g) + abs(orig_rgb.blue() - b)
  11. ranks[diff] = orig_color
To copy to clipboard, switch view to plain text mode 


Test data:
Original colours: 4281742902L, 4278190335L, 4278190144L, 4294967295L
Colours after conversion: 4281742902L, 4278190335L, 4278190144L, 4294967295L
I need to map matching colors