From: Kevin on 19 Jul 2010 05:25 So I have a big matrix which represents an image. I want to find all points inside a circle given an arbitrary center (x coordinate and y coordinate) and also a radius. How do I use logical indexing to do this?
From: Jan Simon on 19 Jul 2010 05:53 Dear Kevin, > So I have a big matrix which represents an image. > I want to find all points inside a circle given an arbitrary center (x coordinate and y coordinate) and also a radius. > How do I use logical indexing to do this? Usually the posters show, what they have done so far. The circle is defined by the equation: (x - cx)^2 + (y - cy)^2 = r^2 with cx, cy is the center and r is the radius. To get your circle mask just calculate, if the corresponding points are inside the circle: mask = bsxfun(@plus, (1:200) - cx)^2, (transpose(1:100) - cy)^2) < r^2; This is a logical array of size 200 x 100, but you have to insert your dimensions. You can get the cut out circle by using this array as index: A = rand(200, 100); CircleA = A(mask); Good luck, Jan
From: Kevin on 19 Jul 2010 23:05 Hey Jan, Thanks for your help. I'm getting this error: >> mask = bsxfun(@plus, ((1:200) - 50)^2, (transpose(1:100) - 50)^2) < 20^2; ??? Error using ==> mpower Matrix must be square. How do I get around not being able to square a row/column vector? -Kevin "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i217a0$c4p$1(a)fred.mathworks.com>... > Dear Kevin, > > > So I have a big matrix which represents an image. > > I want to find all points inside a circle given an arbitrary center (x coordinate and y coordinate) and also a radius. > > How do I use logical indexing to do this? > > Usually the posters show, what they have done so far. > > The circle is defined by the equation: > (x - cx)^2 + (y - cy)^2 = r^2 > with cx, cy is the center and r is the radius. > To get your circle mask just calculate, if the corresponding points are inside the circle: > mask = bsxfun(@plus, (1:200) - cx)^2, (transpose(1:100) - cy)^2) < r^2; > This is a logical array of size 200 x 100, but you have to insert your dimensions. You can get the cut out circle by using this array as index: > A = rand(200, 100); > CircleA = A(mask); > > Good luck, Jan
From: Kevin on 19 Jul 2010 23:19 I tried this out: and it is giving me the B matrix in a straight line instead of a circle shape that I am looking for. mask = bsxfun(@plus, ((1:200) - 80).^2, (transpose(1:100) - 80).^2) < 15^2; figure(1) imshow(mask) A=rand(100,200); figure(2) imshow(A) B=A(mask); figure(3) imshow(B)
From: Kevin on 19 Jul 2010 23:40 Nvm I got it all working, thanks Jan!! "Kevin " <gwkin1989(a)gmail.com> wrote in message <i233p0$679$1(a)fred.mathworks.com>... > Hey Jan, > > Thanks for your help. I'm getting this error: > > >> mask = bsxfun(@plus, ((1:200) - 50)^2, (transpose(1:100) - 50)^2) < 20^2; > ??? Error using ==> mpower > Matrix must be square. > > How do I get around not being able to square a row/column vector? > > -Kevin > > "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i217a0$c4p$1(a)fred.mathworks.com>... > > Dear Kevin, > > > > > So I have a big matrix which represents an image. > > > I want to find all points inside a circle given an arbitrary center (x coordinate and y coordinate) and also a radius. > > > How do I use logical indexing to do this? > > > > Usually the posters show, what they have done so far. > > > > The circle is defined by the equation: > > (x - cx)^2 + (y - cy)^2 = r^2 > > with cx, cy is the center and r is the radius. > > To get your circle mask just calculate, if the corresponding points are inside the circle: > > mask = bsxfun(@plus, (1:200) - cx)^2, (transpose(1:100) - cy)^2) < r^2; > > This is a logical array of size 200 x 100, but you have to insert your dimensions. You can get the cut out circle by using this array as index: > > A = rand(200, 100); > > CircleA = A(mask); > > > > Good luck, Jan
|
Pages: 1 Prev: Matlab Compiler Runtime Next: Image processing ,Image segmentation |