%% imread 得到黑白原圖im(圖一)
>> im=rgb2gray(im);
>> im=im2double(im);
>> imshow(im);
%% 高斯核模糊 得到模糊後的b(圖二)
方法一》 sigma=11;
>> hsize=10;
>>h=fspecial('gaussian',hsize,sigma);
>> b=imfilter(im,h,'symmetric');
>> imshow(b);
方法二:
sigma=11;
>> hsize=10;
x=floor((hsize+1)/2);
for i=1:sigma
forj=1:sigma
h(i,j)=exp(-((i-x)^2+(j-x)^2)/(sigma*sigma))/(2*pi*sigma*sigma);
end
end
b=zeros(1184,720);
tem=zeros(11,11);
tem2=zeros(11,11);
for m=6:1184-5
for n=6:720-5
tem=im(m-5:m+5,n-5:n+5);
tem2=tem.*h;
b(m,n)=sum(tem2(:));
endend
imshow(b,);
%% 原圖以30%概率加上椒鹽雜訊 得到圖c(圖三)
方法一》 c=imnoise(im,'salt &pepper',0.3);
>> imshow(c);
方法二》 c=im;
for i=1:1184;
for j=1:720;
if rand >=0.7
ifrand>=0.5
c(i,j)=255;
else
c(i,j)=0;
endend
endend
>> imshow(c);
%% 將c中值濾波,得到圖median_img(圖四)
>> disp(size(c));
median_img=zeros(1184,720);
temp=zeros(5,5);
for i=3:1184-2
for j=3:720-2
temp=c(i-2:i+2,j-2:j+2);
median_img(i,j)=median(temp(:));
endend
imshow(median_img);
高斯雜訊和椒鹽雜訊python
高斯雜訊的 如下 def gaussiannoise src,means,sigma noiseimg src rows noiseimg.shape 0 cols noiseimg.shape 1 for i in range rows for j in range cols noiseimg i...
Python OpenCV寫椒鹽雜訊和高斯雜訊
import cv2 import numpy as np import random import tkinter import math def rgb2gray rgb gray np.zeros rgb.shape 0 rgb.shape 1 1 np.uint8 建立影象變數,防止gray...
高斯雜訊和椒鹽雜訊的python程式實現
首首先我們先來看下python中shape 函式的用法 from numpy import a array 1,2,3 2,3,4 3,4,5 4,5,6 a.shape 0 得到a的行數為 4 然後輸入 a.shape 1 得到a的列數為 3 圖1 執行在python的idle中示例 通過程式我們...