matlab の複数の画像に対してテンプレートの相互相関を実行するコードを作成しました。彼/彼女がプログラムを実行して相互相関を実行するよりも、フレームで、コードがこのテンプレートを見つけなければならない関心領域を定義しました。私の質問は、相互相関がすべてのフレームでセルを検出して配置した後、セルの位置の x 座標と y 座標を取得する方法です。
format long
fontSize = 10;
file_name = 'stack0001.tif'; %TIFF Stack
image_info = imfinfo(file_name);
numImg = length(image_info) %Number of images in stack
rgbImage = imread(file_name,'Index', 1);
[sub_rgbImage,rect_rgbImage] = imcrop(rgbImage);
figure,
imshow(sub_rgbImage)
title({'Template Image ' ;'to Search For'});
h=figure;
for i1=1:numImg %Read Each Frame
fprintf('Now correlating frame #%d with frame #%d\n',1,i1);
rect_A= [247.5 134.5 35 81]; % region to look for object
A=imread(file_name,'Index', i1);%read the following image from image loop (in tiff stack)
sub_A = imcrop(A,rect_A); % Region of Interest
figure,
imshow(sub_A); % Show region of Interest
axis on;
% Search the red channel for a match.
correlationOutput = normxcorr2(sub_rgbImage(:,:,1), sub_A(:,:,1));
x=size(correlationOutput, 2);
y=size(correlationOutput, 1);
h=figure;
set(h,'visible','off');
figure, surf(correlationOutput),shading flat;
h=figure;
set(h,'visible','off');
figure('Position', [300 300 300 300]);
imshow(correlationOutput, []);
sprintf('Normalized Cross Correlation Output of frame #%d and #%d\n',i1,i1+1);
title('Cross Correlation');
%Offset between the images found by correlation
[maxCorrValue, maxIndex] = max(abs(correlationOutput(:)))
[ypeak,xpeak] = ind2sub(size(correlationOutput),maxIndex(1))
corr_offset = [(ypeak-size(sub_rgbImage,1))
(xpeak-size(sub_rgbImage,2))] ;
%relative offset between position of subimages
rect_offset = [(rect_A(1)- rect_rgbImage(1))
(rect_A(2)- rect_rgbImage(2))]
%total offset
offset = rect_offset+corr_offset;
xoffset= offset(1)
yoffset= offset(2)
end