how to obtain the values of a square matrix inside a circular region of image?

Suppose we find a circular roi in an image. How to obtain the values of a square matrix or square area inside that circle. give that the x and y coordinates of the circle and its radius

4 Comments

What information is known about the square matrix or square area? For example is it to be the largest such area that can be inscribed within the circle?
the area may be either a largest square or rectangle inside the circular region
"Largest" in which sense? The greatest area? If so then in a circle the rectangle with the greatest area is a square.
Greatest area.suppose the value of x and y is some value and the radius of circli is 5 . then how to find the greatest area . The aim is to embed image

Sign in to comment.

 Accepted Answer

d = r/sqrt(2);
xcoords = [x-d x+d x+d x-d x-d];
ycoords = [y-d y-d y+d y+d y-d];
line(xcoords, ycoords)
Now what you need to deal with is the rounding to integer coordinates. Rounding towards the center is the safest way. I would need to think more to figure out if there are circumstances under which it might then be possible to get a slightly larger area by extending one pixel further in one direction.

4 Comments

Akila, this assumes the square is aligned with the edges of the image and not rotated. It seems strange that just any old square inside the circle would do. Isn't there any way of specifying the orientation of the square? As usual posting a sample image would be very helpful.
The above script just plots the line. but how to find the pixel values make it ready for embedding a watermark?
Extracting pixel values:
YourImage(x-d:x+d, y-d:y+d)
In terms of area, Yes, any maximal square inside the circle would do, up to the effects of area reduction due to round-off of non-integers. Circles have no inherent internal orientation, so a square aligned with the axis will have the same area (to within round-off) as a square at (say) 17.29 degrees relative to the origin.
What does the d in the code represents?

Sign in to comment.

More Answers (0)

Asked:

on 16 Nov 2013

Commented:

on 22 Jan 2014

Community Treasure Hunt

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

Start Hunting!