%load attention matrix, h_img,img_h,p_h,h_p 9824*49*49
clear;
load('attention.mat');
%parameters
example_index = 2734;% matlab array index start from 1
h_word_index = 3;%the index of the key word in hypothesis
end_index =11;%the length of premise sentence
text_attention = h_p(example_index,h_word_index,1:end_index);
text_attention = reshape(text_attention,1,end_index);
text_attention = mapminmax(text_attention, -0.4, 1);
h = HeatMap(text_attention,'Colormap',gray);
image_name = '4455622662.jpg';
image_example = imread(image_name);
imshow(image_example);
image_size = size(image_example);
width = image_size(1,1);
height = image_size(1,2);
% attention resize
% image_attention = h_img(example_index,h_word_index,:);% keyword attention attention 1*1*49
% image_attention = reshape(image_attention,7,7)'; %7*7
% image_attention_norm_ori = mapminmax(image_attention, 0, 1);
load('img_norm_light.mat');
image_attention_norm = imresize(image_attention_norm_ori, [width height]);
% FlattenedData = image_attention(:)'; % 展开矩阵为一列,然后转置为一行。
% MappedFlattened = mapminmax(FlattenedData, 0, 1); % 归一化。
% image_attention_norm_ori = reshape(MappedFlattened, size(image_attention));
% image_attention_norm = imresize(image_attention_norm_ori, [width height]);
%heatmap
%imshow(image_attention_norm);
hmap = HeatMap(image_attention_norm);
im_cam_tri = zeros(width, height, 3);
im_cam_tri(:, :, 1) = image_attention_norm * 255;
im_cam_tri(:, :, 2) = image_attention_norm * 255;
im_cam_tri(:, :, 3) = image_attention_norm * 255;
% for k=1:3
% im_cam_tri(:,:,k)=flipud(im_cam_tri(:,:,k));%上下翻转
% end
new_image = double(0.05*image_example) + 0.95*(im_cam_tri);
figure;
imshow(new_image/255);
% new_image = double(image).* (im_cam_tri > 200);
% imshow(new_image/255);
HeatMap attention 高亮显示
于 2018-04-04 22:04:29 首次发布