Applying shading radially outwards on a circle
7 views (last 30 days)
Show older comments
Hello, wondering if you all can help me with an issue I'm having - at my wits end try to get it to work!
I'm doing a study of the limb darkening profile of the Sun, and part of this involves creating a 'fake sun' with a perfect profile. This essientially means I have to use an equation to add the shading to the fake sun I have created.
| needed a raduis value for each pixel and calculated cos(thetha) for each pixel to use the equation.
I have started with a binary image, with a plain circle for the Sun, of the correct size and position. So in my code this is called 'NewbinaryImage'. So its all zeros but with 1's to create the Sun.
I have then tried to create a point matrix with all the details I would need to add the shading correctly. I have the x and y values of all the pixels in the image, the radius, costhetha value, the binary image pixel value, and the calculated shading. I intended to mutliply the shading value across the 1's in the binary image to create the perfect radial profile.
I've included the relevent section of my code here.
[xdata,ydata]=meshgrid(1:size(NewbinaryImage,1), 1:size(NewbinaryImage,2)); %assign an x and y value for each pixel
result=[ydata(:) xdata(:) NewbinaryImage(:)]; %create long vevtor for each result, with x,y and the pixel values from the image
r = sqrt(((xdata(:)-2604).^2+(ydata(:)-1738).^2)); %find r for each x and y (the offset is due to centring the circle)
normr = r./(max(r)); %normalise so 0 at centre and 1 at max (at edge of circle)
costheta = sqrt(1-(normr.^2)); %assign a cosine value for all r in image
%Limb darkening (LD) is applied with a+bcostheta. Choose values for a and b
a= 0.4; %select values for a and b
b= 0.6;
LD = a+(b*costheta); %limb darkening equation
shading = (NewbinaryImage(:)).*LD; %apply shading - each 1 in the binary image will change
pointmatrix = [xdata(:) ydata(:) normr costheta LD NewbinaryImage(:) shading]; %create point matrix with all info needed
shadedimage = reshape(shading, [3476,5208]); %reshape the long vector to the same size as the original image
imshow(shadedimage)
But the final image has shading that is like stripes across the sun? Rather than being brighter in the centre and darker at the edges.
Can anyone see where I'm going wrong?
5 Comments
Accepted Answer
Star Strider
on 30 Mar 2019
I’m notr exactly certain what you want, however this should get you started:
rmax = 100;
r = linspace(0, 1, rmax); % Define Radius & Radius Gradient Vector
a = linspace(0, 2*pi, 150); % Angles (Radians)
[R,A] = ndgrid(r, a); % Create Grid
Z = -R; % Create Gradient Matrix
[X,Y,Z] = pol2cart(A,R,Z); % Convert To Cartesian
figure
surf(X, Y, Z)
view(0, 90)
axis('equal')
colormap(bone)
shading('interp')
producing:

If you want to eliminate the background grid and axes and just show the ‘sun’, add this set call after the plot:
set(gca, 'Visible','off')
to get this result:
%20-%202019%2003%2029.png)
Experiment to get the result you want.
8 Comments
Star Strider
on 2 Apr 2019
My pleasure!
If my Answer helps you solve your problem, please Accept it!
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

%20-%202019%2003%2029.png)