【问题标题】:Plot a filled black circle on a certain background in Matlab在 Matlab 中的某个背景上绘制一个实心黑色圆圈
【发布时间】:2020-11-30 14:15:20
【问题描述】:

我有一张只有噪点的 344*344 灰度图像。现在我想在该灰色图像的中间绘制一个实心黑色圆圈作为背景。 我怎样才能做到这一点?我希望我也可以调整图像中间填充的黑色圆圈的大小(比例)。 非常感谢!!

【问题讨论】:

    标签: matlab background grayscale


    【解决方案1】:

    在灰度图像上绘制实心圆

    通过计算每个像素到图像中点的距离,可以生成一个圆。通过将每个像素设置为不满足半径阈值的强度为 0,可以获得圆形的印象。

    • 距中心的幅度 = (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);
    

    使用 MATLAB R2019b 运行

    【讨论】:

    • 非常感谢!现在的挑战是……椭圆呢?
    • 没问题,为简单起见,我会添加缩放因子。我用那个更新了答案。您需要多少精度和灵活性?这个等式解释了比例因子 [a] 和 [b] google.com/…
    • 基本上可以将缩放因子视为权重,指示 x 分量和 y 分量在计算距图像中心的幅度/距离时的重要性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多