一种importance map的生成方法

%这段代码利用被试的鼠标点击数据生成一个importance map,颜色越深表示该区域鼠标点击的次数越多

%模拟被试的点击数据
%生成鼠标点击点,分四个区域,每个区域中鼠标点击的数量不同
point_x_one=480:10:530;
point_y_one=280:10:330;
[one_x,one_y]=meshgrid(point_x_one,point_y_one);
point_one=[one_x(:),one_y(:)];


point_x_two=80:10:120;
point_y_two=80:10:120;
[two_x,two_y]=meshgrid(point_x_two,point_y_two);
point_two=[two_x(:),two_y(:)];

point_x_three=290:10:310;
point_y_three=290:10:310;
[three_x,three_y]=meshgrid(point_x_three,point_y_three);
point_three=[three_x(:),three_y(:)];

point_four=[560,380;570,380;550,380;570,370;560,370;550,370];

point={point_one,point_two,point_three,point_four};


%初始化与原图像大小相等的权重图
A = imread('test.png'); 
[a,b,c]=size(A);
weight=zeros(a,b);

%指定bubble size大小为 sigema=32
%由鼠标点击得到权重分布图
sigema=32;
for i=1:4;
    [m,n]=size(point{i});
    for j=1:m;
        for y_cordinate=point{i}(j,2)-32:point{i}(j,2)+32
            left_x=point{i}(j,1)-floor(sqrt(sigema^2-(y_cordinate-point{i}(j,2))^2));
            right_x=point{i}(j,1)+floor(sqrt(sigema^2-(y_cordinate-point{i}(j,2))^2));
            for x_cordinate=left_x:right_x
                weight(x_cordinate,y_cordinate)=weight(x_cordinate,y_cordinate)+32-floor(sqrt((x_cordinate-point{i}(j,1))^2+(y_cordinate-point{i}(j,2))^2));
            end
        end
    end       
end


%生成原始热图啦
cmap = colormap(jet(256));
rgb = ind2rgb(weight,cmap);
subplot(1,2,1);
imshow(rgb);

%经过高斯滤波进行处理后的热图
w = fspecial('gaussian',[8,8],24);
newmap= imfilter(rgb,w,'replicate');
subplot(1,2,2);
imshow(newmap);

imwrite(rgb,'heatMap.png')

结果:

在python中调用OpenCV,将热图分布贴在原图上:

#-*-coding:utf-8-*-
import cv2

img = cv2.imread('test.png', 1)
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
heatmap_img=cv2.imread('heatMap.png', 1)
fin = cv2.addWeighted(heatmap_img, 0.5, img, 0.5, 0)

cv2.imshow('image',fin)
cv2.waitKey(0)
cv2.destroyAllWindows()

 

结果:

过程中用到的数据:

test.png

heatMap.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值