def measure(im, debug=False): gray = image.rgb2gray(im) _, s, v = image.split(image.rgb2hsv(im)) h = GrayscaleHist(bins=64).use_image(v) s = GrayscaleHist(bins=64).use_image(s) scores = [score_hist(h)] if debug: image.show(v, "1. Value") image.show(h.to_img(), "2. Value Histogram") image.show(s.to_img(), "2. Saturation Histogram") print score_hist(s) return (None, scores[0]) # h.to_img(),
def measure(im, debug=False): gray = image.rgb2gray(im) _, s, v = image.split(image.rgb2hsv(im)) h = GrayscaleHist(bins=64).use_image(v) s = GrayscaleHist(bins=64).use_image(s) scores = [score_hist(h)] if debug: image.show(v, "1. Value") image.show(h.to_img(), "2. Value Histogram") image.show(s.to_img(), "2. Saturation Histogram") print score_hist(s) return ( None, #h.to_img(), scores[0], )
def measure_color_roi(im, roi, area, focused_regions, debug=False): im = cv.CloneImage(im) g = Grid(cv.GetSize(im)) """ contours = Contours(image.threshold(focused_regions, threshold=1)).approx_poly() if debug: test = image.new_from(im) cv.Set(test, 0) for c in contours: i = 1 while c: cv.FillPoly(test, [[c[x] for x in range(len(c))]], cv.RGB(0,64*i,0)) c = c.v_next() i += 1 #contours.draw(test, levels=9) image.show(test, "Test") """ #mask = image.And(image.threshold(focused_regions, threshold=1), roi) # #canvas = image.new_from(im, nChannels=1) #cv.Set(canvas, 0) #if cv.CountNonZero(mask) <= 1: # return 0, 0 #contours = Contours(image.dilate(mask)).approx_poly() #for c in contours: # i = 1 # while c: # cv.FillPoly(canvas, [[c[x] for x in range(len(c))]], 255) # c = c.v_next() # i += 1 #mask = image.Or(mask, canvas) #if debug: # image.show(mask, "MASK") # #cv.Set(im, 0, image.invert(mask)) cv.Set(im, 0, image.invert(roi)) #area = cv.CountNonZero(image.threshold(im, threshold=1)) if debug: image.show(g.draw(im,thickness=2), "Image + ROI + Focus point mask") scores = [] im = image.rgb2gray(im) #canvas = image.And(plane, roi) quadrants = g.split_in_four(im) hist = [] for q,quad in enumerate(quadrants): #scores.append(cv.Sum(quad)[0] / float(area/4)) h = GrayscaleHist(value_range=(1,255)).use_image(quad) #image.show(h.to_img(), ['gray', 'red','green','blue'][i] + ' in ' + str(q)) hist.append(h.to_array()) scores = [] excluded_points = set([(2, 1), (3, 0)]) for i,h1 in enumerate(hist): for j,h2 in enumerate(hist): if i <= j or (i,j) in excluded_points: continue h = abs(h2-h1) ht = GrayscaleHist(value_range=(0,255)).use_array_as_hist(h) scores.append((h[5:].mean(), h[5:].std())) means = max([x[0] for x in scores]) stddevs = max([x[1] for x in scores]) return means/255.0, stddevs/255.0
def measure_contrast(im, debug=False): h = GrayscaleHist(bins=64).use_image(image.rgb2gray(im)) return h.stddev()