You don't need your pixels
array at all, you can use pixel_color
to set a pixel's color as well as read it. If you say pixel_color(x, y)
then it behaves like getpixel
in your Python code, if you say pixel_color(x, y, color)
then it behaves like putpixel
. So that gets ride of pixels
and store_pixels
.
Then the problem is figuring out if a pixel is white. The pixel_color
method returns you a Pixel
instance. Pixel
has two methods of particular interest here:
- The
Pixel.from_color
class method for converting a color name to aPixel
. - The
fcmp
instance method for comparingPixel
s with an optional fuzziness in the comparison.
You can get a white Pixel
with white = Pixel.from_color('white')
. Then you can copy white pixels with:
pixel = image.pixel_color(x, y)
if pixel.fcmp(white)
image2.pixel_color(x, y, pixel)
end
If you want to make the comparison fuzzy, then supply the second argument to fcmp
:
if pixel.fcmp(white, 10000)
image2.pixel_color(x, y, pixel)
end
You'll probably have to play around with the fuzz
argument to fcmp
to get something that works for you.