image - RGB 图像的 Matlab 低通滤波器

标签 image matlab image-processing gaussian lowpass-filter

我有这段代码可以对图像执行高斯滤波器(低通滤波器)。但是,该滤镜仅适用于灰度图像。我该如何改进它才能处理彩色图像?我知道有很多内置函数,但我是图像处理新手,我正在尝试学习基础知识。

%Read an Image
Img = imread('peppers.png');
Im = rgb2gray(Img);
I = double(Im);

%Design the Gaussian Kernel
%Standard Deviation
sigma = 1.76;

%Window size
sz = 4;
[x,y]=meshgrid(-sz:sz,-sz:sz);

M = size(x,1)-1;
N = size(y,1)-1;
Exp_comp = -(x.^2+y.^2)/(2*sigma*sigma);
Kernel= exp(Exp_comp)/(2*pi*sigma*sigma);

%Initialize
Output=zeros(size(I));
%Pad the vector with zeros
I = padarray(I,[sz sz]);

%Convolution
for i = 1:size(I,1)-M
    for j =1:size(I,2)-N
        Temp = I(i:i+M,j:j+M).*Kernel;
        Output(i,j)=sum(Temp(:));
    end
end
%Image without Noise after Gaussian blur
Output = uint8(Output);
figure,imshow(Output);

最佳答案

RGB 图像由红、绿、蓝颜色 channel 组成。对RGB图像进行图像处理

  1. 您必须分离出图像的三个组成部分
  2. 处理每个组件(R、G、B)一次
  3. 根据修改后的 R、G、B 重建图像

    img = imread('peppers.png');
    R = img(:,:,1); %get the Red part
    G = img(:,:,2); %get the Blue part
    B = img(:,:,3); %get the Green part
    R_gaussian = gaussianFilter(R); %write your own function name
    G_gaussian = gaussianFilter(G); %or repeat the code by REPLACING I as 
    B_gaussian = gaussianFilter(B); %Red Green Blue components
    RGB_gaussian = cat(3,R_gaussian, G_gaussian, B_gaussian); %merging the components
    %since you are learning you can do this for better unedrstanding
    RGB_gaussian = zeros(size(img)); %make a matrix of size  of original image
    RGB_gaussian(:,:,1)=R_gaussian; % Replace the values  
    RGB_gaussian(:,:,2)=G_gaussian;
    RGB_gaussian(:,:,3)=B_gaussian;
    

有关更多信息,这可能会有所帮助:http://www.bogotobogo.com/Matlab/Matlab_Tutorial_Digital_Image_Processing_6_Filter_Smoothing_Low_Pass_fspecial_filter2.php

关于image - RGB 图像的 Matlab 低通滤波器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40325530/

相关文章:

css - 似乎无法修复我图像的 css

python - 我无法使用箭头键在 pygame 中移动图像

python - ndarray.tofile 的奇怪行为

image - 如何从此图像中删除此非红色和非圆形对象?把红色变成白色,其余的变成黑色

java - Java 中是否有用于变形图像(或处理)的库?

php - 如何检查 jpeg 是否适合内存?

linux - 适用于 LINUX 的 MATLAB 编译器

matlab - 在不同大小的不同单元格数组中查找重复值的最快方法

python - 使用python进行边缘检测

image-processing - 为什么 SIFT 描述符具有尺度不变性?