produce gaussian heatmap for landmarks

% 28 * 28 for conv3
% 14 * 14 for conv4
% 7 * 7 for conv5
close all;
datas = load('datas5224_pure3.mat');
datas = datas.datas;

f = @(x,meanx,nSigma) exp(-1/2*(x-meanx)'*nSigma*(x-meanx));

for i = 1:length(datas)
    landmark  = datas(i).after_landmark;
    
    imgpath2 = datas(i).imgpath2;
    %imgpath = strrep(imgpath,'flickr','flickr224');
    img = imread(imgpath2);
    subplot(141);
    imshow(img);
    hold on;
    for j = 1:size(landmark,1)
        plot(landmark(j,1),landmark(j,2),'.r','markersize',15);
        text(landmark(j,1),landmark(j,2),num2str(j),'color','w');
    end
    
    subplot(142);
    heatmap = compute_heatmap([28,28],imgSize,[landmark(8,:);landmark(12,:);landmark(15,:)]);
    imshow(heatmap,[]);
    
    subplot(143);
    heatmap = compute_heatmap([14,14],imgSize,[landmark(8,:);landmark(12,:);landmark(15,:)]);
    imshow(heatmap,[]);
    
    subplot(144);
    heatmap = compute_heatmap([7,7],imgSize,[landmark(8,:);landmark(12,:);landmark(15,:)]);
    imshow(heatmap,[]);
    
    break;
end
function heatmap = compute_heatmap(imgsize,imgSize,landmarks)
% imgsize: the heatmap size for dst
% imgSize: the heatmap size for src, examples: 224 * 224 for CNN
% landmarks

landmarks = round(landmarks .* (imgsize ./ imgSize));
%tau = max((imgSize ./ imgsize)) * 0.1;
tau = min((imgsize ./ imgSize)) * 20; % change those values
Sigma = [tau^2 0 ; 0 tau^2]; % not use
nSigma = [1.0/(tau^2) 0;0 1.0/(tau^2)]; % inverse of Sigma
% note that: x and meanx's shape: [2,1], not [1,2]
f = @(x,meanx,nSigma) exp(-1/2*(x-meanx)'*nSigma*(x-meanx));
heatmap = zeros(imgsize(1),imgsize(2));

for i = 1:size(landmarks,1) % nlandmark
    landmark = landmarks(i,:); % x,y
    for j = 1:imgsize(2) % x: w
        for k = 1:imgsize(1) % y: h
            seat = [j,k]; % (x,y)
            heatmap(k,j) = heatmap(k,j) + f(seat',landmark',nSigma);
        end
    end
end
activation_type = 'softmax';
if strcmp(activation_type,'sigmoid')
    % pass Sigmoid activation funcion
    heatmap = 1 ./ (1+exp(-heatmap));
elseif strcmp(activation_type,'softmax')
    % pass softmax function
    heatmap = exp(heatmap);
    heatmap = heatmap ./ sum(heatmap(:));
end
end

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值