Circular window
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
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
2011년 12월 5일
1 개 추천
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; % 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
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
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
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
2011년 12월 5일
thank you very much :) I may need your help in future also :)
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
2011년 12월 5일
Hey David Young, can you please extend this circular window for RGB images??
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
2015년 1월 31일
Helpful. Thanks
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개)
카테고리
도움말 센터 및 File Exchange에서 Image Segmentation에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
