def generateSM(img_dir,img_name,output_dir): # image path img_path = img_dir + '/' + img_name print(img_path) # read img = cv2.imread(img_path) # initialize imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) # computation saliency_map = sm.SMGetSM(img) # salient_region = sm.SMGetSalientRegion(img) saliency_map *= 255.0/np.array(saliency_map).max() saliency_map = np.array(saliency_map).round() # save it to the output folder # '/sm/.." output_file_name = output_dir + img_name.split('.tif')[0] + "-sm.jpg" cv2.imwrite(output_file_name, np.array(saliency_map)) return saliency_map
def shadow_enhancement(img: np.ndarray, xywh: list, base: np.ndarray, detail: np.ndarray): img_lab = cv2.cvtColor(img, cv2.COLOR_BGR2Lab) # show_img("Base",base,0) base = base * 255 detail = detail * 255 saliency_map = pySaliencyMap(img.shape[1], img.shape[0]) energy_map = saliency_map.SMGetSM(img) # skin_mask = np.zeros((img.shape[0],img.shape[1]),dtype=bool) # for x,y,w,h in xywh: # skin_mask[y:y+h,x:x+w] = True # energy_map = get_energy_map(img_lab,skin_mask) plt.imshow(energy_map, cmap="rainbow") plt.show() L = img_lab[:, :, 0] dark = (L < 50) & ( np.maximum.reduce([img[:, :, 0], img[:, :, 1], img[:, :, 2]]) - np.minimum.reduce([img[:, :, 0], img[:, :, 1], img[:, :, 2]]) > 5) dark_base, dark_detail = wlsFilter(L[dark].reshape((-1, 1))) f_sal = min( 2.0, 1.0 * np.percentile(L[~dark], 35) / np.percentile(dark_base, 95)) img_lab[:, :, 0] = ((f_sal * energy_map * base + (1 - energy_map) * base) + detail).clip(0, 255).astype('uint8') i_res = cv2.cvtColor(img_lab, cv2.COLOR_Lab2BGR) show_img("Image", i_res, 0) return i_res
def execute(b64): plt.switch_backend('AGG') # Read b64 = base64.b64decode(b64) b64 = BytesIO(b64) img = Image.open(b64) img= np.array(img) # Initialize imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) # Computation saliency_map = sm.SMGetSM(img) plt.imshow(saliency_map, 'gray') fig = plt.gcf() plt.axis('off') buffer = StringIO.StringIO() fig.savefig(buffer, format="PNG", bbox_inches='tight', pad_inches=0, transparent=True) result = base64.b64encode(buffer.getvalue()) buffer.close() return [result]
def saliency(self,img): imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) map = sm.SMGetSM(img) return map
def conv_saliency_img(input_data): sm = pySaliencyMap.pySaliencyMap(input_data.shape[-2], input_data.shape[-1]) saliency_map = [] for img in input_data: saliency_map.append(sm.SMGetSM(img)) return np.array(saliency_map)
def getSaliency(img): imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) # computation saliency_map = sm.SMGetSM(img) return saliency_map
def saliency(imgs): n = len(imgs) h, w, c = imgs[0].shape[:3] S = np.zeros((h, w, n)) for i in range(n): sm = pySaliencyMap.pySaliencyMap(w, h) S[:, :, i] = sm.SMGetSM(imgs[i]) # pf.showImage('Saliency', S, 0) return S
def sMap(img): imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) saliency_map = sm.SMGetSM(img) return saliency_map.reshape(-1, 1)
def saliency(img): imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) # computation saliency_map = sm.SMGetSM(img) peak = max(saliency_map.flatten()) saliency_map = (255 / peak) * saliency_map return np.array(saliency_map, np.uint8)
def saliency_map(self): # read img = cv2.imread(self.fname) # initialize imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) # computation self.saliency_map, self.anti_saliency_map = sm.SMGetSM(img) # Modified by Dawei
def toBinarySaliency(image, mask): imgsize = image.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) binarized_map = sm.SMGetBinarizedSM(cv2.medianBlur(image, 15)) mask=mask[:-50,:] mask[mask>0]=255 bool_mask=mask.astype('bool') binarized_map[bool_mask]=0 return binarized_map
def static(img): # read # img = cv2.imread('test3.jpg') # initialize imgsize = img.shape[0] img_width = imgsize[1] img_height = imgsize[0] start = time.time() sm = pySaliencyMap.pySaliencyMap(img_width, img_height) print(time.time() - start)
def main(): #initialize sm = pySaliencyMap.pySaliencyMap(640, 480) # read path_to_folder=os.path.dirname(os.path.abspath(__file__)) images=load_images_from_folder(path_to_folder+'\\imgs\\train\\c0') p=0 for image in images: salient_region = sm.SMGetSalientRegion(image) salient_region_image=cv2.cvtColor(salient_region, cv2.COLOR_BGR2RGB) cv2.imwrite(path_to_folder+'\\salient\\c0\\'+str(p)+'.jpg',salient_region_image) p+=1
def saliency_2(frame, threshold = 0.5): #candidate 2 #its saliency map follows almost the same as the original image frame #but no cracking and kind of more plausible saliency map than the candidate 1 #https://github.com/akisato-/pySaliencyMap height, width, _ = frame.shape sm = pySaliencyMap.pySaliencyMap(width, height) saliency = sm.SMGetSM(frame) binarized_map = sm.SMGetBinarizedSM(frame, threshold) return saliency, binarized_map
def returnIttiSaliency(img): imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) saliency_map = sm.SMGetSM(img) #Scale pixel values to 0-255 instead of float (approx 0, hence black image) #https://stackoverflow.com/questions/48331211/how-to-use-cv2-imshow-correctly-for-the-float-image-returned-by-cv2-distancet/48333272 saliency_map = cv2.normalize(saliency_map, None, 255, 0, cv2.NORM_MINMAX, cv2.CV_8UC1) return saliency_map
def __init__(self, img_path): basename = os.path.basename(img_path) dirname = os.path.dirname(img_path) name, ext = os.path.splitext(basename) # --------------------------------------------- # read # --------------------------------------------- img = cv2.imread(img_path) # --------------------------------------------- # initialize # --------------------------------------------- imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) # --------------------------------------------- # computation # --------------------------------------------- self.saliency_map = saliency_map = sm.SMGetSM(img) # 顕著度スコア self.binarized_map = binarized_map = sm.SMGetBinarizedSM(img) # 01のマスク self.salient_region = salient_region = sm.SMGetSalientRegion(img) # 切り抜かれた画像 # --------------------------------------------- # img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) self.img_sl_map_gray = cv2.cvtColor(saliency_map*255, cv2.COLOR_GRAY2RGB) # --------------------------------------------- # OUTPUT # --------------------------------------------- # normalize saliency_map = (saliency_map/saliency_map.max()) img[:,:,0]= (1-saliency_map) * img[:,:,0] # B img[:,:,1]= (1-saliency_map) * img[:,:,1] # G # img[:,:,2]= (saliency_map) * img[:,:,2] # R self.output_file=output = os.path.join(dirname, name+"_slmap"+ext) ret = cv2.imwrite(output, img); #BGR if(ret is False): raise IOError("cv2.write is Failed {}".format(output)) self.region_file = region_file = os.path.join(dirname, name+"_reg"+ext) ret = cv2.imwrite(region_file, self.salient_region); #BGR self.slgray_file = slgray_file = os.path.join(dirname, name+"_slgray"+ext) ret = cv2.imwrite(slgray_file, self.img_sl_map_gray); #BGR
def ss_enhance(I_bgr): """ Keyword Arguments: I_bgr -- uint8, (m,n,3), BGR """ I_lab = cv2.cvtColor(I_bgr, cv2.COLOR_BGR2LAB) # skin_mask = get_skin_mask(I_lab, I_bgr) # energy_map = get_energy_map(I_lab, skin_mask) sm = pySaliencyMap.pySaliencyMap(I_bgr.shape[1], I_bgr.shape[0]) _em = sm.SMGetSM(I_bgr) energy_map = enhance_em(I_lab, _em) L_new = shad_saliency_enhace(energy_map, I_lab[...,0], I_bgr) I_lab[...,0] = L_new I_res_bgr = cv2.cvtColor(I_lab, cv2.COLOR_LAB2BGR) return I_res_bgr
def __init__(self,img,th,tw): self.img = img self.th = th self.tw = tw self.imgsize = img.shape self.W = self.imgsize[1] self.H = self.imgsize[0] self.M = 4 self.N = 4 self.Wr = (self.W)/self.tw self.Hr = (self.H)/self.th self.sm = pySaliencyMap.pySaliencyMap(self.W, self.H) self.saliency_map = self.sm.SMGetSM(self.img)
def ss_enhance(I_bgr): """ Keyword Arguments: I_bgr -- uint8, (m,n,3), BGR """ I_lab = cv2.cvtColor(I_bgr, cv2.COLOR_BGR2LAB) # skin_mask = get_skin_mask(I_lab, I_bgr) # energy_map = get_energy_map(I_lab, skin_mask) sm = pySaliencyMap.pySaliencyMap(I_bgr.shape[1], I_bgr.shape[0]) _em = sm.SMGetSM(I_bgr) energy_map = enhance_em(I_lab, _em) L_new = shad_saliency_enhace(energy_map, I_lab[..., 0], I_bgr) I_lab[..., 0] = L_new I_res_bgr = cv2.cvtColor(I_lab, cv2.COLOR_LAB2BGR) return I_res_bgr
def mapas(file): try: #--------------------Lee el archivo-------------------- img = cv2.imread('images/imagesEntrenar/' + file) #img = cv2.imread('images/imagesEntrenar/'+sys.argv[1]+'.jpg') #--------------------Inicializa las variables-------------------- imgsize = img.shape #Crea un arreglo con las dimensiones de la imagen img_height = imgsize[ 0] #Asigna el valor de altura de la posicion 0 de imgsize img_width = imgsize[ 1] #Asigna el valor de ancho de la posicion 1 de imgsize sm = pySaliencyMap.pySaliencyMap(img_width, img_height) #Inicializa la clase #--------------------Llamada a los metodos de obtencion de rasgos-------------------- saliency_map = sm.SMGetSM(img) #Obtiene el mapa de poderacion binarized_map = sm.SMGetBinarizedSM(img) #Obtiene el mapa binarizado salient_region = sm.SMGetSalientRegion( img) #Obtiene la region poderada #--------------------Ploteo del resultado de lops metodos de obtencion de rasgos-------------------- #plt.subplot(2,2,1), plt.imshow(img, 'gray') #Original en escala de grises plt.subplot(2, 2, 1), plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) #Original plt.title('Imagen de entrada') #cv2.imshow("input", img) #Muestra imagen en grande plt.subplot(2, 2, 2), plt.imshow(saliency_map, 'gray') plt.title('Mapa de ponderacion') #cv2.imshow("output", map) #Muestra imagen en grande plt.subplot(2, 2, 3), plt.imshow(binarized_map) plt.title('Mapa de ponderacion binarizada') #cv2.imshow("Binarized", binarized_map) #Muestra imagen en grande plt.subplot(2, 2, 4), plt.imshow( cv2.cvtColor(salient_region, cv2.COLOR_BGR2RGB)) cv2.imwrite('images/mapas/' + file, salient_region) #cv2.imwrite('images/mapas/'+sys.argv[1]+'.jpg',salient_region) plt.title('Region ponderada') #cv2.imshow("Segmented", segmented_map) #Muestra imagen en grande #plt.show() #Muestra las 4 imagenes #--------------------Cierra el programa-------------------- #cv2.waitKey(0) #cv2.destroyAllWindows() except: print("Imagen muy pequena")
def run(image, mask=None, smoothing=False, show=False, show_now=True): if mask is None: mask = np.ones_like(image) im_orig = image.copy() else: image, mask = tools.crop_to_bbox(image, mask) im_orig = image.copy() mean_v = int(image[np.nonzero(mask)].mean()) image = np.where(mask, image, mean_v) mask = mask.astype(np.uint8) if smoothing: image = tools.smoothing(image) rgb_image = cv2.cvtColor(image, cv2.COLOR_BAYER_GR2BGR).astype(np.float32) imgsize = rgb_image.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) saliency_map = sm.SMGetSM(rgb_image) saliency_map *= mask.astype(np.uint8) im_orig *= mask.astype(np.uint8) saliency_map = skiexp.rescale_intensity(saliency_map, out_range=(0, 1)) if show: plt.figure(figsize=(24, 14)) if smoothing: plt.subplot(131), plt.imshow( im_orig, 'gray', interpolation='nearest'), plt.title('input') plt.subplot(132), plt.imshow( image, 'gray', interpolation='nearest'), plt.title('smoothed') plt.subplot(133), plt.imshow( saliency_map, 'gray', interpolation='nearest'), plt.title('saliency') else: plt.subplot(121), plt.imshow( im_orig, 'gray', interpolation='nearest'), plt.title('input') plt.subplot(122), plt.imshow( saliency_map, 'gray', interpolation='nearest'), plt.title('saliency') if show_now: plt.show() return im_orig, image, saliency_map
def generateSM(img_path): # read img = cv2.imread(img_path) # initialize imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) # computation saliency_map = sm.SMGetSM(img) salient_region = sm.SMGetSalientRegion(img) saliency_map *= 255.0/np.array(saliency_map).max() return np.array(saliency_map).round()
def get_saliency_map(self, image: cv2) -> cv2: imgsize = image.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) # computation print("Calculating Saliency map...") saliency_map = sm.SMGetSM(image) print("Calculating Binarized map...") binarized_map = sm.SMGetBinarizedSM(image) # グレースケール(2値化)に変換 print("Convert to gray scale saliency map...") saliency_map = saliency_map.astype(np.float64) saliency_map = saliency_map * 255 saliency_map = saliency_map.astype(np.uint8) print("Output Complete") cv2.imwrite("./output/saliency_map.png", saliency_map) return saliency_map
def apply(self, stim): # pySaliencyMap from https://github.com/akisato-/pySaliencyMap data = stim.data # Initialize variables h, w, c = stim.data.shape sm = pySaliencyMap.pySaliencyMap(h, w) # Compute saliency maps and store full maps as derivatives stim.derivatives = dict() stim.derivatives['saliency_map'] = sm.SMGetSM(stim.data) stim.derivatives['binarized_map'] = sm.SMGetBinarizedSM(stim.data) #thresholding done using Otsu # Compute summary statistics output = {} output['max_saliency'] = np.max(stim.derivatives['saliency_map']) output['max_y'], output['max_x'] = [list(i)[0] for i in np.where(stim.derivatives['saliency_map']==output['max_saliency'])] output['frac_high_saliency'] = np.sum(stim.derivatives['binarized_map']/255.0)/(h * w) return Value(stim, self, output)
def __init__(self, img, tgImg, th, tw): self.img = img self.tgImg = tgImg self.th = th self.tw = tw self.imgsize = img.shape self.W = self.imgsize[1] self.H = self.imgsize[0] self.M = 4 self.N = 4 self.Wr = (self.W) / (self.W / (self.W - self.tw)) self.Hr = (self.H) / (self.H / (self.H - self.th)) self.sm = pySaliencyMap.pySaliencyMap(self.W, self.H) self.saliency_map = self.sm.SMGetSM(self.img) self.obj = pyFrameSTemporal.temporal_S(self.img, self.tgImg, self.th, self.tw) self.STemp = self.obj.Frame_S_temporal(self.img, self.tgImg)
#implemented pySaliencyMap developed by Akisato Kimura import cv2 import pySaliencyMap import matplotlib.pyplot as plt img = cv2.imread('S1001L01.jpg', cv2.IMREAD_COLOR) height, width, channels = img.shape sm = pySaliencyMap.pySaliencyMap(width, height) saliency_map = sm.SMGetSM(img) binarized_map = sm.SMGetBinarizedSM(img) salient_region = sm.SMGetSalientRegion(img) plt.subplot(221) plt.imshow(img) plt.xticks([]), plt.yticks([]) plt.title('Input Image') plt.subplot(222) plt.imshow(saliency_map, 'gray') plt.xticks([]), plt.yticks([]) plt.title('Saliency Map') plt.subplot(223) plt.imshow(binarized_map, 'gray') plt.xticks([]), plt.yticks([]) plt.title('Binarized Saliency Map')
def GetFeatures(input_img): #input_img_name = "../images/10045.jpg" features = {} I_rgb_in = input_img#cv2.imread(input_img_name)[:,:,::-1] scaler = np.min([800.0/I_rgb_in.shape[0], 800.0/I_rgb_in.shape[1]]) I_rgb = cv2.resize(I_rgb_in,(np.int(scaler*I_rgb_in.shape[1]),np.int(scaler*I_rgb_in.shape[0])),interpolation=cv.CV_INTER_AREA) print I_rgb_in.shape,"->",I_rgb.shape #assert isinstance(I_rgb, np.ndarray), "Filename %s is not valid" % input_img_name I_rgb = remove_border(I_rgb) I_hsv = cv2.cvtColor(I_rgb,cv.CV_RGB2HSV) I_h = I_hsv[:,:,0] I_h_rad = I_h.flatten()*np.pi/180.0 I_s = I_hsv[:,:,1] features['isGray'] = np.all(I_s==0) I_v = I_hsv[:,:,2] I_g = cv2.cvtColor(I_rgb,cv.CV_RGB2GRAY) nrows = I_rgb.shape[0] ncols = I_rgb.shape[1] rows1thrd = np.int(np.floor(nrows*1.0/3.0)) rows2thrd = np.int(np.floor(nrows*2.0/3.0)) cols1thrd = np.int(np.floor(ncols*1.0/3.0)) cols2thrd = np.int(np.floor(ncols*2.0/3.0)) rows1thrd_o = np.int(rows1thrd - np.floor(nrows/20.0)) rows2thrd_o = np.int(rows2thrd + np.floor(nrows/20.0)) cols1thrd_o = np.int(cols1thrd - np.floor(ncols/20.0)) cols2thrd_o = np.int(cols2thrd + np.floor(ncols/20.0)) rows1thrd_i = np.int(rows1thrd + np.floor(nrows/20.0)) rows2thrd_i = np.int(rows2thrd - np.floor(nrows/20.0)) cols1thrd_i = np.int(cols1thrd + np.floor(ncols/20.0)) cols2thrd_i = np.int(cols2thrd - np.floor(ncols/20.0)) I_zRoT = np.zeros_like(I_g) I_zRoT[rows1thrd_o:rows2thrd_o,cols1thrd_o:cols2thrd_o] = 1 I_zRoT[rows1thrd_i:rows2thrd_i,cols1thrd_i:cols2thrd_i] = 0 sm = pySaliencyMap.pySaliencyMap(ncols, nrows) saliencymap = sm.SMGetSM(I_rgb) features['Salience_mu'] = np.mean(saliencymap) # 0-1 features['Salience_med'] = np.median(saliencymap) # 0-1 features['Salience_var'] = np.var(saliencymap) # 0-1 features['SubjLighting_Hue'] = np.log(circstat.mean(I_h[saliencymap>=0.2]*np.pi/180.0)/circstat.mean(I_h*np.pi/180.0)) features['SubjLighting_Saturation'] = np.log(np.mean(I_s[saliencymap>=0.2])/np.mean(I_s)) features['SubjLighting_Value'] = np.log(np.mean(I_v[saliencymap>=0.2])/np.mean(I_v)) features['Blurriness'] = BlurDetection.blur_detector(I_rgb)[1] features['ComplementaryColorIndex'] = np.abs(np.exp(2*I_h_rad*1j).sum() / len(I_h_rad)) # dutta f4 features['Hue_mu'] = circstat.mean(I_h_rad)*180.0/np.pi features['Hue_var'] = circstat.var(I_h_rad)*180.0/np.pi # dutta f3 features['Saturation_mu'] = np.mean(I_s)/255.0 features['Saturation_var'] = np.var(I_s/255.0) # dutta f1 features['Value_mu'] = np.mean(I_v)/255.0 features['Value_var'] = np.var(I_v/255.0) # dutta f2 features['Colorfulness'] = emd.getColorfulness(I_rgb,8) # dutta f5 - circularized features['Rule_of_Thirds_Hue'] = circstat.mean(I_h[rows1thrd:rows2thrd,cols1thrd:cols2thrd]*np.pi/180.0)*180.0/np.pi # dutta f6 features['Rule_of_Thirds_Saturation'] = np.mean(I_s[rows1thrd:rows2thrd,cols1thrd:cols2thrd]/255.0) # dutta f7 features['Rule_of_Thirds_Value'] = np.mean(I_v[rows1thrd:rows2thrd,cols1thrd:cols2thrd]/255.0) features['Rule_of_Thirds_Salience'] = np.sum(saliencymap[I_zRoT==1])/np.sum(I_zRoT) (maskr,maskc) = np.where(I_zRoT) (maxsr,maxsc) = np.where(saliencymap == np.max(saliencymap)) features['Rule_of_Thirds_Distance'] = np.min([np.sqrt(((maxsc[0] - maskc[i])/np.float(ncols))**2 + ((maxsr[0] - maskr[i])/np.float(nrows))**2) for i in range(len(maskr))]) / np.sqrt(2) # dutta f8/f9 - Familiarity Metric - Requires Knn clustering of a large dataset. # # dutta f10-12 wpH = pywt.WaveletPacket2D(data=I_h, wavelet='db1', mode='zpd', maxlevel=3) for ii in xrange(3): whh = wpH['d'*ii].data whl = wpH['v'*ii].data wlh = wpH['h'*ii].data Sk = np.linalg.norm(whh,2)+np.linalg.norm(whl,2)+np.linalg.norm(wlh,2) features["Wavelet_hue_%d" % ii] = (whh.sum()+whl.sum()+wlh.sum())/Sk # dutta f13-15 wpS = pywt.WaveletPacket2D(data=I_s, wavelet='db1', mode='zpd', maxlevel=3) for ii in xrange(3): whh = wpS['d'*ii].data whl = wpS['v'*ii].data wlh = wpS['h'*ii].data Sk = np.linalg.norm(whh,2)+np.linalg.norm(whl,2)+np.linalg.norm(wlh,2) features["Wavelet_saturation_%d" % ii] = (whh.sum()+whl.sum()+wlh.sum())/Sk # dutta f16-18 wpV = pywt.WaveletPacket2D(data=I_v, wavelet='db1', mode='zpd', maxlevel=3) for ii in xrange(3): whh = wpV['d'*ii].data whl = wpV['v'*ii].data wlh = wpV['h'*ii].data Sk = np.linalg.norm(whh,2)+np.linalg.norm(whl,2)+np.linalg.norm(wlh,2) features["Wavelet_value_%d" % ii] = (whh.sum()+whl.sum()+wlh.sum())/Sk # dutta f19-21 features['Wavelet_hue'] = features['Wavelet_hue_0'] +features['Wavelet_hue_1'] +features['Wavelet_hue_2'] features['Wavelet_saturation'] = features['Wavelet_saturation_0']+features['Wavelet_saturation_1']+features['Wavelet_saturation_2'] features['Wavelet_value'] = features['Wavelet_value_0'] +features['Wavelet_value_1'] +features['Wavelet_value_2'] # dutta f22 - size features['Img_size'] = nrows + ncols # dutta f23 - ratio features['Img_ratio'] = float(ncols)/nrows # dutta f24-52 - Requires Segementation! # # dutta f53-55 Low DOF #wp = pywt.WaveletPacket2D(data=I_h, wavelet='db1', mode='zpd', maxlevel=3) (nsmallrows,nsmallcols) = wpH['ddd'].data.shape A = wpH['ddd'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() + \ wpH['vvv'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() + \ wpH['hhh'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() B = wpH['ddd'].data.sum() + wpH['vvv'].data.sum() + wpH['hhh'].data.sum() features["DoF_hue"] = A/B #wp = pywt.WaveletPacket2D(data=I_s, wavelet='db1', mode='zpd', maxlevel=3) (nsmallrows,nsmallcols) = wpS['ddd'].data.shape A = wpS['ddd'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() + \ wpS['vvv'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() + \ wpS['hhh'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() B = wpS['ddd'].data.sum() + wpS['vvv'].data.sum() + wpS['hhh'].data.sum() features["DoF_saturation"] = A/B #wp = pywt.WaveletPacket2D(data=I_v, wavelet='db1', mode='zpd', maxlevel=3) (nsmallrows,nsmallcols) = wpV['ddd'].data.shape A = wpV['ddd'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() + \ wpV['vvv'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() + \ wpV['hhh'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() B = wpV['ddd'].data.sum() + wpV['vvv'].data.sum() + wpV['hhh'].data.sum() features["DoF_value"] = A/B features["LapVar_Hue"] = cv2.Laplacian(I_h/255.0, cv2.CV_64F).var() features["LapVar_Saturation"] = cv2.Laplacian(I_s/255.0, cv2.CV_64F).var() features["LapVar_Value"] = cv2.Laplacian(I_v/255.0, cv2.CV_64F).var() tmp = I_h lines = cv2.HoughLinesP(cv2.Canny(tmp,100,200,apertureSize = 3),1,np.pi/180,100, minLineLength = 5, maxLineGap = 20) if not lines is None: features['ProbAngles_Hue'] = circstat.mean([np.arctan2(np.abs(y2-y1),np.abs(x2-x1)) for x1,y1,x2,y2 in lines[0]]) else: features['ProbAngles_Hue'] = 0 tmp = I_s lines = cv2.HoughLinesP(cv2.Canny(tmp,100,200,apertureSize = 3),1,np.pi/180,100, minLineLength = 5, maxLineGap = 20) if not lines is None: features['ProbAngles_Saturation'] = circstat.mean([np.arctan2(np.abs(y2-y1),np.abs(x2-x1)) for x1,y1,x2,y2 in lines[0]]) else: features['ProbAngles_Saturation'] = 0 tmp = I_v lines = cv2.HoughLinesP(cv2.Canny(tmp,100,200,apertureSize = 3),1,np.pi/180,100, minLineLength = 5, maxLineGap = 20) if not lines is None: features['ProbAngles_Value'] = circstat.mean([np.arctan2(np.abs(y2-y1),np.abs(x2-x1)) for x1,y1,x2,y2 in lines[0]]) else: features['ProbAngles_Value'] = 0 tmp = I_h a = tmp.astype("float") b1 = tmp[::-1,:].astype("float") b2 = tmp[:,::-1].astype("float") features['Sym_Horizontal_Hue'] = (a * b1).sum() / (np.sqrt((a**2).sum())*np.sqrt((b1**2).sum())) features['Sym_Vertical_Hue'] = (a * b2).sum() / (np.sqrt((a**2).sum())*np.sqrt((b2**2).sum())) tmp = I_s a = tmp.astype("float") b1 = tmp[::-1,:].astype("float") b2 = tmp[:,::-1].astype("float") features['Sym_Horizontal_Saturation'] = (a * b1).sum() / (np.sqrt((a**2).sum())*np.sqrt((b1**2).sum())) features['Sym_Vertical_Saturation'] = (a * b2).sum() / (np.sqrt((a**2).sum())*np.sqrt((b2**2).sum())) tmp = I_v a = tmp.astype("float") b1 = tmp[::-1,:].astype("float") b2 = tmp[:,::-1].astype("float") features['Sym_Horizontal_Value'] = (a * b1).sum() / (np.sqrt((a**2).sum())*np.sqrt((b1**2).sum())) features['Sym_Vertical_Value'] = (a * b2).sum() / (np.sqrt((a**2).sum())*np.sqrt((b2**2).sum())) return features
import cv2 import pySaliencyMap # main if __name__ == '__main__': # set up webcams capture = cv2.VideoCapture(0) # repeat until pressing a key "q" while(True): # capture retval, frame = capture.read() # initialize frame_size = frame.shape frame_width = frame_size[1] frame_height = frame_size[0] sm = pySaliencyMap.pySaliencyMap(frame_width, frame_height) # computation saliency_map = sm.SMGetSM(frame) # binarized_map = sm.SMGetBinarizedSM(frame) # salient_region = sm.SMGetSalientRegion(frame) # visualize cv2.imshow('Input image', cv2.flip(frame, 1)) cv2.imshow('Saliency map', cv2.flip(saliency_map, 1)) # cv2.imshow('Binalized saliency map', cv2.flip(binarized_map, 1)) # cv2.imshow('Salient region', cv2.flip(salient_region, 1)) # exit if the key "q" is pressed if cv2.waitKey(1) & 0xFF == ord('q'): break cv2.destroyAllWindows()
#------------------------------------------------------------------------------- import cv2 import matplotlib.pyplot as plt import pySaliencyMap # main if __name__ == '__main__': # read img = cv2.imread('saliency.png') # initialize print img.shape imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) # computation saliency_map = sm.SMGetSM(img) #binarized_map = sm.SMGetBinarizedSM(img) #salient_region = sm.SMGetSalientRegion(img) # visualize # plt.subplot(2,2,1), plt.imshow(img, 'gray') plt.subplot(2,2,1), plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) plt.title('Input image') # cv2.imshow("input", img) plt.subplot(2,2,2), plt.imshow(saliency_map, 'gray') plt.title('Saliency map') # cv2.imshow("output", map) #plt.subplot(2,2,3), plt.imshow(binarized_map) #plt.title('Binarilized saliency map') # cv2.imshow("Binarized", binarized_map)
from makeTemporalFilter import makeTemporalFilter tf.enable_eager_execution() import cv2 import matplotlib.pyplot as plt if __name__ == '__main__': # with h5py.File('./video_explosion.mat', 'r') as f: # video = tf.constant(np.transpose(f['video'],[1,0,3,2])) params = makeDefaultParams(1e5) cap = cv2.VideoCapture(1) cap.set(cv2.CAP_PROP_FRAME_HEIGHT,308) cap.set(cv2.CAP_PROP_FRAME_WIDTH,308) #cap= cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)308, height=(int)308,format=(string)I420, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink") sm = pySaliencyMap.pySaliencyMap(308,308) r_s = np.flip(makeTemporalFilter('strong_t3'),axis=-1) r_w = np.flip(makeTemporalFilter('weak_t6'),axis=-1) #r_s = tf.convert_to_tensor( #r_w = tf.convert_to_tensor(np.reshape(np.flip(makeTemporalFilter('strong_t3'),axis=-1) fil_s = tf.to_double(np.reshape(r_s, [3, 1, 1, 1, 1])) fil_w = tf.to_double(np.reshape(r_w, [6, 1, 1, 1, 1])) video =[] ret, frame = cap.read() if ret: print("Camera found") fr_no = 0 #sess = tf.Session() #video = np.zeros((10,608,608,3))
def GetFeatures(input_img): #input_img_name = "../images/10045.jpg" features = {} I_rgb_in = input_img #cv2.imread(input_img_name)[:,:,::-1] scaler = np.min([800.0 / I_rgb_in.shape[0], 800.0 / I_rgb_in.shape[1]]) I_rgb = cv2.resize(I_rgb_in, (np.int( scaler * I_rgb_in.shape[1]), np.int(scaler * I_rgb_in.shape[0])), interpolation=cv.CV_INTER_AREA) print I_rgb_in.shape, "->", I_rgb.shape #assert isinstance(I_rgb, np.ndarray), "Filename %s is not valid" % input_img_name I_rgb = remove_border(I_rgb) I_hsv = cv2.cvtColor(I_rgb, cv.CV_RGB2HSV) I_h = I_hsv[:, :, 0] I_h_rad = I_h.flatten() * np.pi / 180.0 I_s = I_hsv[:, :, 1] features['isGray'] = np.all(I_s == 0) I_v = I_hsv[:, :, 2] I_g = cv2.cvtColor(I_rgb, cv.CV_RGB2GRAY) nrows = I_rgb.shape[0] ncols = I_rgb.shape[1] rows1thrd = np.int(np.floor(nrows * 1.0 / 3.0)) rows2thrd = np.int(np.floor(nrows * 2.0 / 3.0)) cols1thrd = np.int(np.floor(ncols * 1.0 / 3.0)) cols2thrd = np.int(np.floor(ncols * 2.0 / 3.0)) rows1thrd_o = np.int(rows1thrd - np.floor(nrows / 20.0)) rows2thrd_o = np.int(rows2thrd + np.floor(nrows / 20.0)) cols1thrd_o = np.int(cols1thrd - np.floor(ncols / 20.0)) cols2thrd_o = np.int(cols2thrd + np.floor(ncols / 20.0)) rows1thrd_i = np.int(rows1thrd + np.floor(nrows / 20.0)) rows2thrd_i = np.int(rows2thrd - np.floor(nrows / 20.0)) cols1thrd_i = np.int(cols1thrd + np.floor(ncols / 20.0)) cols2thrd_i = np.int(cols2thrd - np.floor(ncols / 20.0)) I_zRoT = np.zeros_like(I_g) I_zRoT[rows1thrd_o:rows2thrd_o, cols1thrd_o:cols2thrd_o] = 1 I_zRoT[rows1thrd_i:rows2thrd_i, cols1thrd_i:cols2thrd_i] = 0 sm = pySaliencyMap.pySaliencyMap(ncols, nrows) saliencymap = sm.SMGetSM(I_rgb) features['Salience_mu'] = np.mean(saliencymap) # 0-1 features['Salience_med'] = np.median(saliencymap) # 0-1 features['Salience_var'] = np.var(saliencymap) # 0-1 features['SubjLighting_Hue'] = np.log( circstat.mean(I_h[saliencymap >= 0.2] * np.pi / 180.0) / circstat.mean(I_h * np.pi / 180.0)) features['SubjLighting_Saturation'] = np.log( np.mean(I_s[saliencymap >= 0.2]) / np.mean(I_s)) features['SubjLighting_Value'] = np.log( np.mean(I_v[saliencymap >= 0.2]) / np.mean(I_v)) features['Blurriness'] = BlurDetection.blur_detector(I_rgb)[1] features['ComplementaryColorIndex'] = np.abs( np.exp(2 * I_h_rad * 1j).sum() / len(I_h_rad)) # dutta f4 features['Hue_mu'] = circstat.mean(I_h_rad) * 180.0 / np.pi features['Hue_var'] = circstat.var(I_h_rad) * 180.0 / np.pi # dutta f3 features['Saturation_mu'] = np.mean(I_s) / 255.0 features['Saturation_var'] = np.var(I_s / 255.0) # dutta f1 features['Value_mu'] = np.mean(I_v) / 255.0 features['Value_var'] = np.var(I_v / 255.0) # dutta f2 features['Colorfulness'] = emd.getColorfulness(I_rgb, 8) # dutta f5 - circularized features['Rule_of_Thirds_Hue'] = circstat.mean( I_h[rows1thrd:rows2thrd, cols1thrd:cols2thrd] * np.pi / 180.0) * 180.0 / np.pi # dutta f6 features['Rule_of_Thirds_Saturation'] = np.mean( I_s[rows1thrd:rows2thrd, cols1thrd:cols2thrd] / 255.0) # dutta f7 features['Rule_of_Thirds_Value'] = np.mean( I_v[rows1thrd:rows2thrd, cols1thrd:cols2thrd] / 255.0) features['Rule_of_Thirds_Salience'] = np.sum( saliencymap[I_zRoT == 1]) / np.sum(I_zRoT) (maskr, maskc) = np.where(I_zRoT) (maxsr, maxsc) = np.where(saliencymap == np.max(saliencymap)) features['Rule_of_Thirds_Distance'] = np.min([ np.sqrt(((maxsc[0] - maskc[i]) / np.float(ncols))**2 + ((maxsr[0] - maskr[i]) / np.float(nrows))**2) for i in range(len(maskr)) ]) / np.sqrt(2) # dutta f8/f9 - Familiarity Metric - Requires Knn clustering of a large dataset. # # dutta f10-12 wpH = pywt.WaveletPacket2D(data=I_h, wavelet='db1', mode='zpd', maxlevel=3) for ii in xrange(3): whh = wpH['d' * ii].data whl = wpH['v' * ii].data wlh = wpH['h' * ii].data Sk = np.linalg.norm(whh, 2) + np.linalg.norm(whl, 2) + np.linalg.norm( wlh, 2) features["Wavelet_hue_%d" % ii] = (whh.sum() + whl.sum() + wlh.sum()) / Sk # dutta f13-15 wpS = pywt.WaveletPacket2D(data=I_s, wavelet='db1', mode='zpd', maxlevel=3) for ii in xrange(3): whh = wpS['d' * ii].data whl = wpS['v' * ii].data wlh = wpS['h' * ii].data Sk = np.linalg.norm(whh, 2) + np.linalg.norm(whl, 2) + np.linalg.norm( wlh, 2) features["Wavelet_saturation_%d" % ii] = (whh.sum() + whl.sum() + wlh.sum()) / Sk # dutta f16-18 wpV = pywt.WaveletPacket2D(data=I_v, wavelet='db1', mode='zpd', maxlevel=3) for ii in xrange(3): whh = wpV['d' * ii].data whl = wpV['v' * ii].data wlh = wpV['h' * ii].data Sk = np.linalg.norm(whh, 2) + np.linalg.norm(whl, 2) + np.linalg.norm( wlh, 2) features["Wavelet_value_%d" % ii] = (whh.sum() + whl.sum() + wlh.sum()) / Sk # dutta f19-21 features['Wavelet_hue'] = features['Wavelet_hue_0'] + features[ 'Wavelet_hue_1'] + features['Wavelet_hue_2'] features[ 'Wavelet_saturation'] = features['Wavelet_saturation_0'] + features[ 'Wavelet_saturation_1'] + features['Wavelet_saturation_2'] features['Wavelet_value'] = features['Wavelet_value_0'] + features[ 'Wavelet_value_1'] + features['Wavelet_value_2'] # dutta f22 - size features['Img_size'] = nrows + ncols # dutta f23 - ratio features['Img_ratio'] = float(ncols) / nrows # dutta f24-52 - Requires Segementation! # # dutta f53-55 Low DOF #wp = pywt.WaveletPacket2D(data=I_h, wavelet='db1', mode='zpd', maxlevel=3) (nsmallrows, nsmallcols) = wpH['ddd'].data.shape A = wpH['ddd'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() + \ wpH['vvv'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() + \ wpH['hhh'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() B = wpH['ddd'].data.sum() + wpH['vvv'].data.sum() + wpH['hhh'].data.sum() features["DoF_hue"] = A / B #wp = pywt.WaveletPacket2D(data=I_s, wavelet='db1', mode='zpd', maxlevel=3) (nsmallrows, nsmallcols) = wpS['ddd'].data.shape A = wpS['ddd'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() + \ wpS['vvv'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() + \ wpS['hhh'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() B = wpS['ddd'].data.sum() + wpS['vvv'].data.sum() + wpS['hhh'].data.sum() features["DoF_saturation"] = A / B #wp = pywt.WaveletPacket2D(data=I_v, wavelet='db1', mode='zpd', maxlevel=3) (nsmallrows, nsmallcols) = wpV['ddd'].data.shape A = wpV['ddd'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() + \ wpV['vvv'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() + \ wpV['hhh'].data[nsmallrows*1/4:nsmallrows*3/4,nsmallcols*1/4:nsmallcols*3/4].sum() B = wpV['ddd'].data.sum() + wpV['vvv'].data.sum() + wpV['hhh'].data.sum() features["DoF_value"] = A / B features["LapVar_Hue"] = cv2.Laplacian(I_h / 255.0, cv2.CV_64F).var() features["LapVar_Saturation"] = cv2.Laplacian(I_s / 255.0, cv2.CV_64F).var() features["LapVar_Value"] = cv2.Laplacian(I_v / 255.0, cv2.CV_64F).var() tmp = I_h lines = cv2.HoughLinesP(cv2.Canny(tmp, 100, 200, apertureSize=3), 1, np.pi / 180, 100, minLineLength=5, maxLineGap=20) if not lines is None: features['ProbAngles_Hue'] = circstat.mean([ np.arctan2(np.abs(y2 - y1), np.abs(x2 - x1)) for x1, y1, x2, y2 in lines[0] ]) else: features['ProbAngles_Hue'] = 0 tmp = I_s lines = cv2.HoughLinesP(cv2.Canny(tmp, 100, 200, apertureSize=3), 1, np.pi / 180, 100, minLineLength=5, maxLineGap=20) if not lines is None: features['ProbAngles_Saturation'] = circstat.mean([ np.arctan2(np.abs(y2 - y1), np.abs(x2 - x1)) for x1, y1, x2, y2 in lines[0] ]) else: features['ProbAngles_Saturation'] = 0 tmp = I_v lines = cv2.HoughLinesP(cv2.Canny(tmp, 100, 200, apertureSize=3), 1, np.pi / 180, 100, minLineLength=5, maxLineGap=20) if not lines is None: features['ProbAngles_Value'] = circstat.mean([ np.arctan2(np.abs(y2 - y1), np.abs(x2 - x1)) for x1, y1, x2, y2 in lines[0] ]) else: features['ProbAngles_Value'] = 0 tmp = I_h a = tmp.astype("float") b1 = tmp[::-1, :].astype("float") b2 = tmp[:, ::-1].astype("float") features['Sym_Horizontal_Hue'] = (a * b1).sum() / (np.sqrt( (a**2).sum()) * np.sqrt((b1**2).sum())) features['Sym_Vertical_Hue'] = (a * b2).sum() / (np.sqrt( (a**2).sum()) * np.sqrt((b2**2).sum())) tmp = I_s a = tmp.astype("float") b1 = tmp[::-1, :].astype("float") b2 = tmp[:, ::-1].astype("float") features['Sym_Horizontal_Saturation'] = (a * b1).sum() / (np.sqrt( (a**2).sum()) * np.sqrt((b1**2).sum())) features['Sym_Vertical_Saturation'] = (a * b2).sum() / (np.sqrt( (a**2).sum()) * np.sqrt((b2**2).sum())) tmp = I_v a = tmp.astype("float") b1 = tmp[::-1, :].astype("float") b2 = tmp[:, ::-1].astype("float") features['Sym_Horizontal_Value'] = (a * b1).sum() / (np.sqrt( (a**2).sum()) * np.sqrt((b1**2).sum())) features['Sym_Vertical_Value'] = (a * b2).sum() / (np.sqrt( (a**2).sum()) * np.sqrt((b2**2).sum())) return features
def get_saliency_map(img): sm = pySaliencyMap.pySaliencyMap(img.shape[1], img.shape[0]) # computation saliency_map = sm.SMGetSM(img) return saliency_map
#------------------------------------------------------------------------------- # Name: main # Purpose: Testing the package pySaliencyMap # # Author: Akisato Kimura <*****@*****.**> # # Created: May 4, 2014 # Copyright: (c) Akisato Kimura 2014- # Licence: All rights reserved #------------------------------------------------------------------------------- import cv2 import pySaliencyMap # main if __name__ == '__main__': img = cv2.imread('pic36.jpg') imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height) map = sm.SMGetSM(img) cv2.imshow("input", img) cv2.imshow("output", map) cv2.waitKey(0) cv2.destroyAllWindows()
import matplotlib.pyplot as plt import pySaliencyMap # main if __name__ == '__main__': # set up webcams capture = cv2.VideoCapture(0) # repeat until pressing a key "q" while(True): # capture retval, frame = capture.read() # initialize frame_size = frame.shape frame_width = frame_size[1] frame_height = frame_size[0] sm = pySaliencyMap.pySaliencyMap(frame_width, frame_height) # computation saliency_map = sm.SMGetSM(frame) # binarized_map = sm.SMGetBinarizedSM(frame) # salient_region = sm.SMGetSalientRegion(frame) # visualize cv2.imshow('Input image', cv2.flip(frame, 1)) cv2.imshow('Saliency map', cv2.flip(saliency_map, 1)) # cv2.imshow('Binalized saliency map', cv2.flip(binarized_map, 1)) # cv2.imshow('Salient region', cv2.flip(salient_region, 1)) # exit if the key "q" is pressed if cv2.waitKey(1) & 0xFF == ord('q'): break cv2.destroyAllWindows()
if __name__ == '__main__': # with h5py.File('./video_explosion.mat', 'r') as f: # video = tf.constant(np.transpose(f['video'],[1,0,3,2])) params = makeDefaultParams(1e5) cap = cv2.VideoCapture(1) #cap.set(cv2.CAP_PROP_FRAME_HEIGHT,300) #cap.set(cv2.CAP_PROP_FRAME_WIDTH,300) width = 640 height = 480 # #cap= cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)308, height=(int)308,format=(string)I420, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink") sm = pySaliencyMap.pySaliencyMap(height, width) r_s = np.reshape(makeTemporalFilter('strong_t3'), (3, 1, 1, 1)) r_w = np.reshape(makeTemporalFilter('weak_t6'), (6, 1, 1, 1)) imgs = np.zeros((height, width, 3, 3)) print(r_s.shape) video = np.zeros((6, height, width, 3)) for i in range(6): ret, frame = cap.read() print(np.asarray(frame).shape) video[i, :, :, :] = frame imgs = np.zeros((video[0].shape[0], video[0].shape[1], video[0].shape[2], len(params['channels']))) while (True):
# Licence: All rights reserved #------------------------------------------------------------------------------- import cv2 import matplotlib.pyplot as plt import pySaliencyMap # main if __name__ == '__main__': # read img = cv2.imread('test3.png') # initialize imgsize = img.shape img_width = imgsize[1] img_height = imgsize[0] sm = pySaliencyMap.pySaliencyMap(img_width, img_height)#initialize # computation saliency_map = sm.SMGetSM(img)#input is origin img binarized_map = sm.SMGetBinarizedSM(img) salient_region = sm.SMGetSalientRegion(img) # visualize # plt.subplot(2,2,1), plt.imshow(img, 'gray') plt.subplot(2,2,1), plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) plt.title('Input image') # cv2.imshow("input", img) plt.subplot(2,2,2), plt.imshow(saliency_map, 'gray') plt.title('Saliency map') # cv2.imshow("output", map) plt.subplot(2,2,3), plt.imshow(binarized_map) plt.title('Binarilized saliency map') # cv2.imshow("Binarized", binarized_map)