【发布时间】:2020-11-30 14:15:20
【问题描述】:
我有一张只有噪点的 344*344 灰度图像。现在我想在该灰色图像的中间绘制一个实心黑色圆圈作为背景。 我怎样才能做到这一点?我希望我也可以调整图像中间填充的黑色圆圈的大小(比例)。 非常感谢!!
【问题讨论】:
标签: matlab background grayscale
我有一张只有噪点的 344*344 灰度图像。现在我想在该灰色图像的中间绘制一个实心黑色圆圈作为背景。 我怎样才能做到这一点?我希望我也可以调整图像中间填充的黑色圆圈的大小(比例)。 非常感谢!!
【问题讨论】:
标签: matlab background grayscale
通过计算每个像素到图像中点的距离,可以生成一个圆。通过将每个像素设置为不满足半径阈值的强度为 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 运行
【讨论】: