def show_threshold(filename): '''threshold an image''' global threshold, imgf pgm = util.PGM(filename) cv.ConvertScale(pgm.img, imgf, scale=1.0 / 65536) return change_threshold(threshold)
def circle_highest(filename): '''circle the highest value pixel in an image''' pgm = util.PGM(filename) maxpoint = pgm.array.argmax() maxpos = (maxpoint % 1280, maxpoint / 1280) color_img = cv.CreateImage((1280, 960), 16, 3) cv.CvtColor(pgm.img, color_img, cv.CV_GRAY2RGB) overlay = cv.CreateImage((1280, 960), 16, 3) cv.SetZero(overlay) cv.Circle(overlay, maxpos, 10, cv.CV_RGB(65535, 0, 0)) cv.AddWeighted(color_img, 1.0, overlay, 1.0, 0.5, color_img)
def show_edges(filename): '''show edges in an image''' pgm = util.PGM(filename) # convert to 8 bit img8 = cv.CreateImage((1280, 960), 8, 1) cv.ConvertScale(pgm.img, img8, scale=1.0 / 256) edge1 = cv.CreateImage((1280, 960), 8, 1) cv.Canny(img8, edge1, 250, 255, 5) edgecolor = cv.CreateImage((1280, 960), 8, 3) edgecolor16 = cv.CreateImage((1280, 960), 16, 3) cv.CvtColor(edge1, edgecolor, cv.CV_GRAY2RGB) cv.ConvertScale(edgecolor, edgecolor16, scale=256) color_img = cv.CreateImage((1280, 960), 16, 3) cv.CvtColor(pgm.img, color_img, cv.CV_GRAY2RGB) cv.AddWeighted(color_img, 1.0, edgecolor16, 1.0, 0.5, color_img)
def fix_image(f): '''fix one image''' img = util.PGM(f) if img.comment and img.comment.find("OFFSET%u" % extra) != -1: return print("Fixing image %s" % f) os.rename(f, f + '.old') f2 = open(f, mode='w') f2.write('''P5 1280 960 %s (OFFSET%u) 65535 ''' % (img.comment.strip(), extra)) global leader f2.write(leader) img.rawdata.byteswap(True) f2.write(img.rawdata) f2.close() if not opts.keep: os.unlink(f + '.old')
def change_image(i): '''show image idx''' global idx, pgm idx = i pgm = util.PGM(args[idx]) cv.ShowImage('CanberraUAV', pgm.img)