def buildSM(self, gazepath, lblpath): ''' build saliency map from gaze labels ''' ''' # convert black pixels in lbl to white with open(lblpath, 'r+b') as f: with PIL.Image.open(f) as image: for width in xrange(image.size[0]): for length in xrange(image.size[1]): pixel = image.getpixel((width, length)) if pixel == (0, 0, 0): image.putpixel((width, length), (255, 255, 255)) ''' oi = OpencvIo() gaze = oi.imread(lblpath) sm = SaliencyMap(gaze) oi.imwrite(sm.map, gazepath) # threshold SM with open(gazepath, 'r+b') as f: with PIL.Image.open(f).convert('RGB') as image: for length in xrange(image.size[0]): for width in xrange(image.size[1]): pixel = image.getpixel((length, width)) # putpixel() is slow, learn to use paste for single pixel placement if possible if pixel[0] < 50: image.putpixel((length, width), (0, 0, 0)) elif 50 <= pixel[0] < 100: image.putpixel((length, width), (100, 100, 100)) elif 100 <= pixel[0] < 150: image.putpixel((length, width), (175, 175, 175)) else: image.putpixel((length, width), (255, 255, 255)) image.save(gazepath, image.format)
#!/usr/bin/python # -*- coding: utf-8 -*- import sys from saliency_map import SaliencyMap from utils import OpencvIo if __name__ == "__main__": oi = OpencvIo() src = oi.imread(sys.argv[1]) sm = SaliencyMap(src) oi.imshow_array([sm.map]) #cv.imwrite('out.png', sm.map)
def setUp(self): oi = OpencvIo() src = oi.imread('./images/fruit.jpg') gp = GaussianPyramid(src) fm = FeatureMap(gp.maps) self.__cm = ConspicuityMap(fm.maps)
def setUp(self): oi = OpencvIo() src = oi.imread('./images/fruit.jpg') self.__gp = GaussianPyramid(src)
#!/usr/bin/python # -*- coding: utf-8 -*- import sys from saliency_map import SaliencyMap from utils import OpencvIo filename = "/home/yhq/Desktop/saliency/images/test2.jpg" oi = OpencvIo() src = oi.imread(filename) sm = SaliencyMap(src) oi.imshow_array([sm.map])
from saliency import SaliencyMap from utils import OpencvIo oi = OpencvIo() src = oi.imread('..\IMG_7842.jpg') sm = SaliencyMap(src) oi.imshow_array([sm.map])