[英]how to move a rectangle over a image in matlab
i am new to matlab 我是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 在这里,我的第一步是创建两个特征图,然后我必须创建一个矩形并将矩形在第一张特征图中从左向右移动,宽度为30,矩形的高度为图像高度
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 现在我已经使用了nlfilter,其宽度和尺寸与矩形的宽度和尺寸相同,但是我无法获得答案,请帮助我,这是我的代码
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
. 实际上,使用线性函数
sum
的事实表明您不需要非线性滤波器函数nlfilter
。 Consider using conv2
with ones(ncols, nrows)
instead. 考虑将
conv2
与ones(ncols, nrows)
使用。
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
. 重复上述步骤,但使用
box = ones(width, 30)
smoothFeatureMap2
box = ones(width, 30)
来获取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. 但是说实话,我认为也许您想要的只是一个2D卷积的结果,而不是其他两个卷积的结果。 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.