7 Oct 20:27
collecting the bluest pixels
From: paul taney <paultaney <at> yahoo.com>
Subject: collecting the bluest pixels
Newsgroups: gmane.comp.python.numeric.general
Date: 2008-10-07 18:28:43 GMT
Subject: collecting the bluest pixels
Newsgroups: gmane.comp.python.numeric.general
Date: 2008-10-07 18:28:43 GMT
Hi,
I have this silly color filter that Stefan gave me:
def vanderwalt(image, f):
"""colorfilter, thanks to Stefan van der Walt"""
RED, GRN, BLU = 0, 1, 2
bluemask = (image[...,BLU] > f*image[...,GRN]) & \
(image[...,BLU] > f*image[...,RED])
return bluemask
To collect the right number of the bluest pixels I am calling it from this arduous successive approximation
routine. It occured to me that someone on this list knows how to do this in a couple of lines...
def successive_approximation(image, density, width, height, bpp):
"""keep calling vanderwalt till line length is within 10% of density target"""
count = 0
failsafe = 20 # max iterations
gimp.progress_init("this is the fun part...")
init_high = 1.400001
init_low = 1.399991
high_guesses = [(init_high, width*height*bpp)] # we collect recent stats in this list
low_guesses = [(init_low, 0)]
crossed_high = crossed_low = False
factor = 1.4
delta_high = .18 # adjust the factor by this much when it is too high
delta_low = .14 # adjust the factor by this much when it is too low
# if they were the same amount then they"d cancel
xlength = 0
(Continue reading)
RSS Feed