Fast computation of joint histogram of two images

196 views Asked by At

In the context of image registration, I have to compute the joint histogram of two images i.e. each histogram(i,j) contains the number of pixels whose intensity is i in the first image and j in the second one.

To do this I loop on the intensities:

clear all; close all; clc

M = 1024;
N = 1024;

world_map=NaN(M,N,2);

rail_1 = rgb2gray(imread('img2.bmp'));

% Initial misregistration
dx = 12;
dy = 15;

[M1,N1] = size(rail_1);

% Center the 1st image on the world_map first layer
world_map(floor(M/2-M1/2):floor(M/2+(M1/2-1)),floor(N/2-N1/2):floor(N/2+(N1/2-1)),1) = rail_1;

% Translate the same image on the world_map second layer
world_map(floor(M/2-M1/2-dx):floor(M/2+(M1/2-1-dx)),floor(N/2-N1/2-dy):floor(N/2+(N1/2-1)-dy),2) = rail_1;


figure
h1=imagesc(world_map(:,:,1));
hold on
h2=imagesc(world_map(:,:,2));
set(h2,'AlphaData',0.5)
colormap gray

% find the overlapping area of the two images
overlap = find(~isnan(world_map(:,:,1)) & ~isnan(world_map(:,:,2)));
rail_1 = world_map(:,:,1);
rail_2 = world_map(:,:,2);

% compute the joint histogram (we here suppose that we have 256 gray level)
histo = zeros(256,256);

for i=1:256
    for j=1:256

        histo(i,j) = numel(find(rail_1(overlap)==i-1 & rail_2(overlap)==j-1));

    end
end

However such an algorithm is too much slow for my project and I have tried to do this without for loops but,so far, I have not find any solution to solve my problem.

I hope you guys could help me to solve it ;)

0

There are 0 answers