简体   繁体   中英

Plot a filled black circle on a certain background in Matlab

I have a 344*344 grey-level image with noise only. Now I want to plot a filled black circle in the middle of that gray image as background. How can I achieve that? And I hope I can also adjust the size (scale) of the filled black circle in the middle of the image. Thanks so much!!

Plotting Filled Circle On Greyscale Image

By calculating the distance from the midpoint of the image for each of the pixels a circle can be generated. By setting each of the pixels to an intensity of 0 that does not satisfy the radius threshold the impression of a circle can be achieved.

• Magnitude From Centre = (X - X_Midpoint)^2 + (Y - Y_Midpoint)^2

带有可调圆形填充的图像

带有可调椭圆的图像

%Adjust for ellipse%
Scaling_Factor_1 = 3;
Scaling_Factor_2 = 1;


%Importing image%
Image = imread('Tiger_Drawing.jpg');
Image = rgb2gray(Image);

%The radius of the filled circle%
Radius = 100;

%Grabbing the dimensions of the image%
[Image_Height,Image_Width] = size(Image);

%Evaluating the midpoint of the image%
Image_Midpoint = [round(Image_Height/2), round(Image_Width/2)];

%Scanning through the pixels of the image%
for Row_Scanner = 1: +1: Image_Height
   for Column_Scanner = 1: +1: Image_Width 
      
      
      
%The pixel coordinate%
Pixel_Coordinate = [Row_Scanner Column_Scanner];
Magnitude_From_Centre = sqrt((abs(Pixel_Coordinate(1,1) - Image_Midpoint(1,1))^2)/Scaling_Factor_1 + abs(Pixel_Coordinate(1,2) - Image_Midpoint(1,2))^2/Scaling_Factor_2);



%If the magnitude from the centre is smaller than the set radius set
%intensity to 0%
if(Magnitude_From_Centre <= Radius) 
    Image(Row_Scanner,Column_Scanner) = 0; 
end 

   end 
end


imshow(Image);

Ran using MATLAB R2019b

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM