Hi I need to use sliding circular window of radius "r" for feature extraction on an image. I want to divided this circular in equal 6 quadrants, each other 60 degree. So that calculations can be performed separately for each quadrant.
Can anyone guide me about creating quadrants in a circle.
{Note: Circular window is created by own logic, NOT by any built-in function}

댓글 수: 1

Daniel Armyr
Daniel Armyr 2011년 12월 5일
Do you want to make 2-dimensional kernels that look like 1/6th of a circle? That is fairly easy, if that is what you want.
Or is it something else?

댓글을 달려면 로그인하십시오.

 채택된 답변

David Young
David Young 2011년 12월 5일

1 개 추천

EDIT: Deleted request for additional information. Modified reference to original question. Added suggested code.
This relates to your previous question. The answers there remain relevant.
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; % circular region parameters
r=100;
% Make a logical image with the selected circular region set to 1, the rest
% to zero
[xgrid, ygrid] = meshgrid(1:sz(2), 1:sz(1));
x = xgrid - x2; % offset the origin
y = ygrid - y2;
circlemask = x.^2 + y.^2 <= r.^2;
% Use the mask to select part of the image
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, []);

댓글 수: 9

Khawaja Asim
Khawaja Asim 2011년 12월 5일
This is the piece of cde i used to get circular region around any mentioned coordinates....
im=imread('image.jpg');
figure, imshow(im)
image=rgb2gray(im);
sz=size(image);
empty=zeros(sz(1),sz(2)); %just an image to contain the circular region
figure, imshow(empty)
x2=340; y2=360;
r=100;
for i=1:sz(1)
for j=1:sz(2)
x1=i;
y1=j;
if (distance(x1,x2,y1,y2))<=r
empty(i,j)=image(i,j);
end
end
end
% Hence empty is the image that contains circular region of orignal image
_________________________________________
Dear actually I am working on medical images. I have to detect certain parts in retinal images. For that purpose I have to extract some features, so that on the basis of these features I can detect the desired part....
So for feature extraction I have to slide a circle on the original image pixel by pixel, and perform some operations like "counting of blood vessels pixels, finding standard deviation of a certain type of pixels etc..".
I hope I have explained questions.. :)
Khawaja Asim
Khawaja Asim 2011년 12월 5일
The other thing, I need to divide circle in 4 quadrants, not six. BUT those quadrants should be like "x". means the four quadrants should be like this symbol, not like "+"...
It really gets difficult to explain things. :)
David Young
David Young 2011년 12월 5일
OK, now I can see some of your code, it's much easier to make suggestions. Thank you. I'll put some code in the answer, as the formatting is better there.
Khawaja Asim
Khawaja Asim 2011년 12월 5일
thank you very much :) I may need your help in future also :)
Khawaja Asim
Khawaja Asim 2011년 12월 5일
Now i will use this code to slide circle from top left corner of an image to the bottom left on the image to perform calculations on the image, with every time just an increment in the "circle coordinates" :)
Khawaja Asim
Khawaja Asim 2011년 12월 5일
Hey David Young, can you please extend this circular window for RGB images??
David Young
David Young 2011년 12월 5일
You could either treat each plane of the RGB image separately, or extend the circular window to 3 planes, like this:
circle3 = cat(3, circlemask, circlemask, circlemask);
circle_image = im .* cast(circle3, class(im));
imshow(circle_image, [])
I've cast the mask to the same class as the original image as you probably want to retain the class in this case. You can cast both to double if you prefer.
Junaid Ansari
Junaid Ansari 2015년 1월 31일
Helpful. Thanks
Image Analyst
Image Analyst 2015년 1월 31일
There are also numerous FAQ entries dealing with circles. Mostly in this section of the FAQ: http://matlab.wikia.com/wiki/FAQ#Math.2FAlgorithms

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2011년 12월 5일

댓글:

2015년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by