在Matlab中的特定背景上绘制实心黑色圆圈

问题描述

我有一个仅带噪声的344 * 344灰度图像。现在,我想在该灰色图像的中间绘制一个填充的黑色圆圈作为背景。 我该如何实现?而且我希望我也可以调整图像中间实心黑色圆圈的大小(比例)。 非常感谢!

解决方法

在灰度图像上绘制实心圆

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

•中心幅度=(X-X_Midpoint)^ 2 +(Y-Y_Midpoint)^ 2

Image with Adjustable Circle Fill

Image with Adjustable Ellipse

%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运行

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...