作者探索一种新型的围绕自适应电枢的构图指导,并发现自适应电枢可支持用户探索新的构图思想以及在拍摄时重新构图,从而帮助他们制作他们认为构图更好的照片 。
附上自己的实现 cv2显著性检测
import cv2def make_saliency(path):# load the input imageimage = cv2.imread(path)# initialize OpenCV's static fine grained saliency detector and# compute the saliency mapsaliency = cv2.saliency.StaticSaliencyFineGrained_create()(success, saliencyMap) = saliency.computeSaliency(image)saliencyMap = (saliencyMap * 255).astype("uint8")# if we would like a *binary* map that we could process for contours,# compute convex hull's, extract bounding boxes, etc., we can# additionally threshold the saliency map# threshMap = cv2.threshold(saliencyMap, 0, 255,#cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]# show the images# cv2.imshow("Image", image)# cv2.imshow("Output", saliencyMap)# cv2.imshow("Thresh", threshMap)# cv2.waitKey(0)cv2.imwrite('saliency_out.jpg',saliencyMap)
主py文件引用及变量定义
import make_saliencyfrom skimage import iofrom PIL import Image, ImageDrawimport cv2import heapqcomposition_imgs = []# 存储构图线图像lengths = []# 存储构图线长度composition_outs = []# 存储高斯处理后的构图线图像multiplication_results = []# 存储乘法后的图像scores = []# 存储最终计算分数top3_lines = []# 存储最终top3的构图线序号
读入显著性图像函数
def read_saliency():global saliency_img# 存储显著性检测的图片saliency_img = io.imread('saliency_out.jpg')
读入14张构图线图像函数
def read_composition(path):with open(path, encoding='utf-8') as f:for l in f:l = l.strip()if l:# 按照txt中的路径读取图片img = io.imread(l)length = 0rows, cols = img.shape# 处理构图将128像素点转为255for i in range(rows):for j in range(cols):if (img[i, j] > 0):length += 1img[i, j] = 255composition_imgs.append(img)lengths.append(length)# print(img)# print(length)print(composition_imgs)print(lengths)
高斯处理14张构图线图像
def gaussian_all(width):for img in composition_imgs:out = cv2.GaussianBlur(img, (int(int(width)/10-1), int(int(width)/10-1)), int(int(width)/40))composition_outs.append(out)print(composition_outs)
乘法处理
def multiply():for out in composition_outs:result = out * saliency_imgmultiplication_results.append(result)# print(multiplication_results)
计算分数
def calculate_scores():flag = 0for result in multiplication_results:sum = 0rows, cols = result.shapefor i in range(rows):for j in range(cols):if (result[i, j] > 0):sum += result[i, j]score = sum / lengths[flag]flag += 1# print(sum)# print(score)scores.append(score)# print(scores)
输出top3构图线
def print_top3():max_num_index_list = map(scores.index, heapq.nlargest(3, scores))for l in list(max_num_index_list):top3_lines.append(l + 1)print('得出分数为前三的构图线:', top3_lines)
依据本人理解的简单实现,需定义图像大小后执行算法,供交流 。