Skip to content

Instantly share code, notes, and snippets.

@rysk-t
Created October 5, 2017 23:20
Show Gist options
  • Save rysk-t/473f3cf90d5def66e48be5dcee455ca9 to your computer and use it in GitHub Desktop.
Save rysk-t/473f3cf90d5def66e48be5dcee455ca9 to your computer and use it in GitHub Desktop.
conv2 as a moving ROI
img = double(2^8-imread('eight.tif')); % ここは適宜
figure;
subplot(1,2,1)
imagesc(img); axis image;
title('Image')
% 直径をマニュアルで決めるとき
% circROI = imellipse;
% circPos = getPosition(circROI);
% circDim = mean(circPos(end-1:end));
circ_D = 80;
% ROI作成とconvolution
[xx,yy] = meshgrid(-circ_D:circ_D); % 適宜もっと大きくしていいかも
ROI_filt = double(sqrt(xx.^2 + yy.^2) < circ_D/2);
conv_img = conv2(double(img), ROI_filt, 'same');
[MP,I] = max(conv_img(:));
[a,b] = ind2sub(size(conv_img), I);
subplot(1,2,2);hold on;
imagesc(conv_img);
axis image
plot(b, a, '+r')
title('ROI-summation result')
set(gca, 'YDir', 'reverse')
colormap gray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment