フィルターのクリア

How to generate grayscale from equation?

1 回表示 (過去 30 日間)
Belal Abboushi
Belal Abboushi 2017 年 9 月 18 日
コメント済み: Belal Abboushi 2017 年 9 月 20 日
Hello, I'm trying to generate a grayscale image similar to one attached using an equation. The image is a circle in which the center area is brighter while areas closer to rim are darker (gradient). This gradient is determined by an an equation (Y= constant*X) where X is angle from center of circle, and Y is the relative brightness. The resultant image needs to be 800*800 pixels.
Any leads or tips on how to go about doing this would be greatly appreciated! Thanks, Belal
  2 件のコメント
Walter Roberson
Walter Roberson 2017 年 9 月 18 日
The image appears to be symmetric with angle, contrary to your requirement that the gradient depend linearly on the angle.
Now if the gradient were to decrease with linear radius from the center...
Belal Abboushi
Belal Abboushi 2017 年 9 月 18 日
The gradient should get darker towards the edge. Assuming center of circle is 0% and edge is 75%. Is there a way to map these values across the circle?

サインインしてコメントする。

回答 (1 件)

Rik
Rik 2017 年 9 月 18 日
  1. Get the 800x800 coordinates with meshgrid
  2. Convert the coordinates to polar coordinates wit cart2pol
  3. Apply the formula to find the value (make sure your formula uses element-wise operations only)
You can use reshape if you like to convert the coordinate matrices to a vector and the outcome back to a matrix.
Don't forget that imshow depends on the datatype.
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 9 月 18 日
[R,C] = meshgrid(-400:399);
d = sqrt(R.^2 + C.^2);
mask = d <= 375; %you do not want the circle to go edge to edge
d(~mask) = 0; %outside circle is black
maxd = max(d(:));
gradient = d ./ maxd * 0.75; %so 0 at center and 0.75 at radius
tone_down_by = 0.9;
d(mask) = (1 - gradient(mask)) .* tone_down_by;
imagesc(d, [0 1]); colormap(gray(256));
Belal Abboushi
Belal Abboushi 2017 年 9 月 20 日
Thank you this was helpful, Walter.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by