问题描述:

original image is

I would like to compare the rectangular objects present in this image with a rectangular mask?how can i select a rectangular mask? How to compare the similarity of rectangular like image and a mask. I would like to check the similarity using

from the paper

A Fractional Fourier Transform Based Method of Image Fusion. For this, I wrote a sliding window template. How to implement this equation :

I = imread('test1.png');

imageWidth = size(I, 2);

imageHeight = size(I, 1);

windowWidth = 32;

windowHeight = 32;

for j = 1:imageHeight - windowHeight + 1

for i = 1:imageWidth - windowWidth + 1

window = I(j:j + windowHeight - 1, i:i + windowWidth - 1, :);

S(j,i)=sum(sum(abs(window).*abs(mask)))/(sum(sum(window.^2))+sum(sum(mask.^2)));

end

end

网友答案:

Having extracted your window if I understand your similarity function correctly then

S(j, i)=sum(sum(abs(window).*abs(mask)))/(sum(sum(window.^2))+sum(sum(mask.^2)));

For efficiency it would probably be better to use nlfilter to perform a sliding window operation on your image.

First you need to create a function to calculate the similarity. The simplest way is to do this as an anonymous function of the form:

[email protected](M) 'Implent your similarity function here..';

As mask doesn't change when you silde your window you should be able to just call it directly and not need it as a variable of your function.

Then call nlfilter(img, [m n], similarity); where [m n] gives the size of the window you want to use.

相关阅读:
Top