简体   繁体   中英

how to move a rectangle over a image in matlab

i am new to matlab

now i am studying about optic disc localization

here my first step is to create two feature maps secondly i have to create a rectangle and move the rectangle from left to right in first feature map and the width is 30 and height of the rectangle is image height

and in the second feature map i have move the rectangle for top to bottom

third step is at each position of the rectangle i have to calculate the sum and plot the sum value and obtain two graphs

now i have used nlfilter which has the width and dimension as that of the rectangle for calculation but i can't get the answer please help me and this is my code


final2=edgediff./eror;
figure,image((final2));
title('Feature MAP 1');
func = @(x) sum(x(:));
B = nlfilter(final2,[30 600],func);

If you're studying optic disc localization I think what you're doing is really two convolutions separately on the horizontal and vertical directions. In fact, the fact that you are using a linear function sum shows that you don't need the non-linear filter function nlfilter . Consider using conv2 with ones(ncols, nrows) instead.

Something like this:

[width, height] = size(featureMap1);
box = ones(30, height);
smoothFeatureMap1 = conv2(featureMap1, box, 'same');

Repeat but with box = ones(width, 30) to get smoothFeatureMap2 .

Then you can just add the two smooth feature maps together.

However to be honest I think maybe what you want is just the result of a single 2D convolution, not the sum of two other ones. It's hard to tell for sure from the question. Particularly I have no idea what you want to graph in your two graphs. (I'll try to update this answer if you make the question more clear).

您可以从图像处理工具箱使用imrect放置矩形并获取其坐标:

H = imrect(axes, position);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM