フィルターのクリア

Detecting nonzero matrix elements in a rectangle

1 回表示 (過去 30 日間)
Michael
Michael 2015 年 2 月 5 日
コメント済み: Michael 2015 年 2 月 5 日
I have an image that I performed Sobel Edge Detection on. I am planning on drawing rectangles on top of the edge detected image and counting the number of nonzero matrix elements within those rectangles using the nnz command.
My question is how exactly do I use the nnz command to work only within those rectangles? I have the 4 corner coordinates of the rectangle already, and I will be performing this calculation on at at least 5 rectangles within the image.
Thank you for any help in advance.

採用された回答

David Young
David Young 2015 年 2 月 5 日
Say your edge array is E and opposite corners of a rectangle are at integer coordinates (x0,y0) and (x1,y1), with the former nearer the top left of the image. Then you could use this
nEdgePixels = nnz(E(y0:y1, x0:x1));
Note that I'm using the common convention that X refers to the column subscript in the array and Y refers to the row subscript.
  1 件のコメント
Michael
Michael 2015 年 2 月 5 日
Exactly what I wanted. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by