Ask Your Question
1

drawrect with Color.WHITE results in (254,254,254)

asked 2013-04-16 02:32:40 -0500

xtofl gravatar image

updated 2013-04-16 03:36:59 -0500

Hi,

I'm trying to draw an all white rectangle in an image. However, the resulting color is just one less than Color.WHITE...

>>> image=Image((100,100))
>>> image.drawRectangle(10,10,50,50,Color.WHITE,0,255)                                                                                                                                                  
>>> image=image.applyLayers()                                                                                                                                                                           
>>> image.getPixel(15,15)                                                                                                                                                                               
(254.0, 254.0, 254.0)                    
>>> Color.WHITE                                                                                                                                                                                         
(255, 255, 255)

Any idea why this is? Does the term 'desired' in the documentation have anything to do with it?

edit retag flag offensive close merge delete

Comments

How did you check the color?

jayrambhia gravatar imagejayrambhia ( 2013-04-16 03:01:26 -0500 )edit

@jayrambhia: using 'getPixel'; I added the code.

xtofl gravatar imagextofl ( 2013-04-16 03:37:34 -0500 )edit

I'm getting (255, 255, 255).

jayrambhia gravatar imagejayrambhia ( 2013-04-16 15:52:45 -0500 )edit

yeah. I'm using Ubuntu 12.04. OpenCV 2.4.4 and Pygame 1.9,1. Here's the snapshot. http://i.imgur.com/dwQlFne.png

jayrambhia gravatar imagejayrambhia ( 2013-04-16 16:08:05 -0500 )edit

$Rev: 4557$ is 2.3.1. It's very old. I think you must have installed it using apt-get on 12.04, if you use that. If you want latest OpenCV versions here's a link for scripts. https://github.com/jayrambhia/Install-OpenCV

jayrambhia gravatar imagejayrambhia ( 2013-04-16 18:33:18 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-04-17 09:03:08 -0500

kscottz gravatar image

My guess is that your bug actually has more do with anti-aliasing than it does with the Image class. This is just a guess but on my machine the outer edge of the white box is slightly anti-aliased and therefore the values are less than 255. What happens when you drop the alpha parameter? I am not sure if this is something I would consider a bug. If you need a work around you can always use the image slice notation to create your rectangle (e.g. img[10:50,10,50] = Color.WHITE).

edit flag offensive delete link more

Comments

Thanks for this idea; Indeed when I use the slice notation, the getPixel returns 'pure' white. How can I check whether it's the anti-aliasing causing harm?

xtofl gravatar imagextofl ( 2013-04-22 03:45:33 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-04-16 02:32:40 -0500

Seen: 225 times

Last updated: Apr 17 '13