Filter löschen
Filter löschen

move rectangle over te image

2 Ansichten (letzte 30 Tage)
ramya raj
ramya raj am 17 Aug. 2011
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 Kommentar
Walter Roberson
Walter Roberson am 20 Aug. 2011
Duplicate is at http://www.mathworks.com/matlabcentral/answers/13444-to-make-the-rectangle-move-over-the-image

Melden Sie sich an, um zu kommentieren.

Antworten (2)

David Young
David Young am 17 Aug. 2011
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 am 17 Aug. 2011
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.

Community Treasure Hunt

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

Start Hunting!

Translated by