EDIT: Deleted request for additional information. Modified reference to original question. Added suggested code.
Pedantry corner: you can't divide a circle into 6 quadrants, you can only divide it into 4 quadrants. You can divide it into 6 sectors though. In your code, you use loops to set individual pixels. The basic idea is fine, and you can get it to work, but there are more powerful ways to write such operations in MATLAB, and it's worth knowing about these, so first, I'll give a modified version of your code to pick out the circular region of the image. It looks like this, taking over from your code right after the call to rgb2gray:
sz=size(image);
x2=340; y2=360;
r=100;
[xgrid, ygrid] = meshgrid(1:sz(2), 1:sz(1));
x = xgrid - x2;
y = ygrid - y2;
circlemask = x.^2 + y.^2 <= r.^2;
circle_image = double(image) .* circlemask;
imshow(circle_image, []);
Except for the fact the result is of class 'double', this does the same as your code. Note how the logical operator <= can be used to select part of a region, and also note that the operations make use of MATLAB's inbuilt "parallel" operations to do things to the whole of the arrays.
Now, we can extend this to doing quadrants. It's a matter choosing the parts of the circle that lie between radii at specific angles. Angles are computed using atan2, and again we can compute the angles everywhere in the array, and then use logical operators to pick the quadrants:
angle = atan2(y, x);
quadrant1 = circlemask & angle > -pi/4 & angle <= pi/4;
quadrant2 = circlemask & angle > pi/4 & angle <= 3*pi/4;
quadrant3 = circlemask & (angle > 3*pi/4 | angle <= -3*pi/4);
quadrant4 = circlemask & angle > -3*pi/4 & angle <= -pi/4;
A quadrant is defined by the pixels inside the circle, and also with an angle between specific values. The only peculiarity is for the third quadrant - this is because of the wraparound of angles, which has to be somewhere and happens to be in this quadrant. See the diagram in doc atan2, which should make it clear what is happening.
Adjusting the angle thresholds will let you pick out any sectors at any angles you wish.
You can pick out part of the image within a quadrant as before: here's one example:
quad1_image = double(image) .* quadrant1;
imshow(quad1_image, []);
Best Answer