move rectangle over te image

2 次查看(过去 30 天)
ramya raj
ramya raj 2011-8-17
hai
i am doing a project for locating the optic disc in matlab and i am new to matlab what i have to do is to move the rectangle over a image and calculate the sum of values inside the rectangle
now i have created a rectangle by using the rectangle function next i have slide or move the rectangle over my image
i have used while loop for that
and the rectangle is copied over the entire image but i have to just move it in the horizontal direction
here is the code that i have tried please help me
final2=edgediff./eror; figure,image((final2)); title('Feature MAP 1'); i=1; for j=10 while(i<1500) r=rectangle('position'[i,10,26.7,1135],'linewidth',2.4,'edgecolor','w'); res(i) = sum(r); i=i+26.7; end i need the code urgently please help me
  1 个评论
Walter Roberson
Walter Roberson 2011-8-20
Duplicate is at http://www.mathworks.com/matlabcentral/answers/13444-to-make-the-rectangle-move-over-the-image

请先登录,再进行评论。

回答(2 个)

David Young
David Young 2011-8-17
If you have an array A, and you want the sum of the values in a rectangle whose top and bottom are rows R1 and R2, and whose left and right are columns C1 and C2, then you can use
s = sum(sum( A(R1:R2, C1:C2) ));

Walter Roberson
Walter Roberson 2011-8-17
David's response is correct, but there are also other ways to proceed.
You could use blkproc() (older MATLAB) or blockproc() (newer MATLAB), or nlfilter() (probably a good choice for this task). Also, I gather that you could construct this in terms of using conv2() of the matrix with an N x M matrix of 1's.

类别

Help CenterFile Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by