Circular window
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
