当前位置:网站首页>MATLAB image histogram equalization, namely spatial filtering
MATLAB image histogram equalization, namely spatial filtering
2022-06-30 10:34:00 【Yangxiangrui】
1. Histogram equalization
1.1 The theoretical analysis
Define symbols in discussion
P ∈ R m × n , primary chart image Moment front S ∈ R m × n , straight Fang chart all equilibrium turn And after Of chart image [ 0 , L − 1 ] , image plain spot Of take value Fan around p ( r ) , primary chart image General rate The secret degree Letter Count T ( r ) , ash degree turn in Letter Count r o u n d ( x ) , Four House 5、 ... and Enter into Letter Count \begin{aligned} &P \in R^{m \times n}, Original image matrix \\ &S \in R^{m \times n}, Image after histogram equalization \\ &[0, L - 1], The value range of pixels \\ &p(r), The probability density function of the original image \\ &T(r), Grayscale conversion function \\ &round(x), Round function \end{aligned} P∈Rm×n, primary chart image Moment front S∈Rm×n, straight Fang chart all equilibrium turn And after Of chart image [0,L−1], image plain spot Of take value Fan around p(r), primary chart image General rate The secret degree Letter Count T(r), ash degree turn in Letter Count round(x), Four House 5、 ... and Enter into Letter Count
First, calculate the probability density function of the original image (PDF)
p ( r ) = 1 m n ∑ I ( P i j = r ) , r = 0 , ⋯ , L − 1 p(r) = \frac{1}{mn} \sum I(P_{ij} = r), r = 0, \cdots, L - 1 p(r)=mn1∑I(Pij=r),r=0,⋯,L−1
Next, calculate the grayscale conversion function
T ( r ) = r o u n d ( ( L − 1 ) ∑ i = 0 r p ( i ) ) T(r) = round((L - 1) \sum_{i = 0}^{r}p(i)) T(r)=round((L−1)i=0∑rp(i))
Then, according to the gray conversion function, the image after histogram equalization is obtained
S i j = T ( P i j ) S_{ij} = T(P_{ij}) Sij=T(Pij)
1.2 Result analysis
The original image is as follows 3-2.1 Shown , In the original image, there are a large number of pixels whose pixel values are almost 0( The histogram is shown in 3-2.2). after image process toolbox The processed image is as follows 3-2.3 Shown , The image itself has a large number of pixel values 0, Therefore, the result of histogram equalization will make the original result 0 The pixels of move to 50-100 Within the range of ( See histogram 3-2.4), The picture is too bright .
Specifically matlab The algorithm of histogram equalization with its own function is different from the textbook , therefore 3-2.5( The histogram equalization result obtained by using the algorithm in the textbook ) and 3-2.5( Use it directly matlab The histogram equalization result obtained by the self-contained function ) There must be a difference . But the results of both methods are not ideal , It means that the image is not suitable for histogram equalization .
1.3 result






2. Laplace filtering
2.1 The theoretical analysis
Use the following formula to find the Laplace transform of the image
∇ 2 f ( x , y ) = 8 f ( x , y ) − f ( x + 1 , y + 1 ) − f ( x + 1 , y ) − f ( x + 1 , y − 1 ) − f ( x , y + 1 ) − f ( x , y − 1 ) − f ( x − 1 , y + 1 ) − f ( x − 1 , y ) − f ( x − 1 , y − 1 ) \begin{aligned} \nabla^2 f(x, y) =& 8f(x, y) - f(x + 1, y + 1) - f(x + 1, y) -\\ &f(x + 1, y - 1) - f(x, y + 1) - f(x, y - 1) -\\ &f(x - 1, y + 1) - f(x - 1, y) - f(x - 1, y - 1) \end{aligned} ∇2f(x,y)=8f(x,y)−f(x+1,y+1)−f(x+1,y)−f(x+1,y−1)−f(x,y+1)−f(x,y−1)−f(x−1,y+1)−f(x−1,y)−f(x−1,y−1)
The mask is converted into a mask to obtain the following mask
[ − 1 − 1 − 1 − 1 8 − 1 − 1 − 1 − 1 ] \begin{bmatrix} -1& -1& -1\\ -1& 8& -1\\ -1& -1& -1\\ \end{bmatrix} ⎣⎡−1−1−1−18−1−1−1−1⎦⎤
Set the original image to f ( x , y ) f(x, y) f(x,y), The filtered function is f m a s k ( x , y ) f_{mask}(x, y) fmask(x,y), The final image is g ( x , y ) g(x, y) g(x,y)
g ( x , y ) = f ( x , y ) + f m a s k ( x , y ) g(x, y) = f(x, y) + f_{mask}(x, y) g(x,y)=f(x,y)+fmask(x,y)
2.2 Result analysis
First, the image 3-5.1 Sharpen , obtain 3-5.2. You can see that the edges of the sharpened image have been significantly enhanced , Noise also increases to a certain extent .
Then the image 3-5.3 Sharpen , obtain 3-5.4. Images 3-5.3 Image for text , The high frequency component of the image only appears at the edge of the text , Therefore, the sharpening process will only enhance the edges of the text , No more noise like normal images .
Comparing the results of two image sharpening, we can think that image sharpening is very suitable for processing text images .
2.3 result




3. Unsharp mask
3.1 The theoretical analysis
Define symbols in discussion :
f ( x , y ) , primary chart image f ˉ ( x , y ) , the too flat slide filter wave Of chart image g m a s k ( x , y ) , increase strong send use Of Mask membrane g ( x , y ) , increase strong after Of chart image \begin{aligned} &f(x, y), Original image \\ &\bar f (x, y), Smoothed filtered image \\ &g_{mask}(x, y), Enhance the mask used \\ &g(x, y), Enhanced image \end{aligned} f(x,y), primary chart image fˉ(x,y), the too flat slide filter wave Of chart image gmask(x,y), increase strong send use Of Mask membrane g(x,y), increase strong after Of chart image
First, use the following smoothing filter to get f ˉ ( x , y ) \bar{f}(x, y) fˉ(x,y)
1 9 × [ 1 1 1 1 1 1 1 1 1 ] \frac{1}{9} \times \begin{bmatrix} 1& 1& 1\\ 1& 1& 1\\ 1& 1& 1\\ \end{bmatrix} 91×⎣⎡111111111⎦⎤
Then according to f ˉ ( x , y ) \bar f(x, y) fˉ(x,y) and f ( x , y ) f(x, y) f(x,y) obtain g m a s k ( x , y ) g_{mask}(x, y) gmask(x,y)
g m a s k ( x , y ) = f ( x , y ) − f ˉ ( x , y ) g_{mask}(x, y) = f(x, y) - \bar f(x, y) gmask(x,y)=f(x,y)−fˉ(x,y)
The final enhanced image is obtained from the mask ( Coefficient in the experiment k = 1)
g ( x , y ) = f ( x , y ) + k g m a s k ( x , y ) g(x, y) = f(x, y) + kg_{mask}(x, y) g(x,y)=f(x,y)+kgmask(x,y)
3.2 Result analysis
The original image is 3-6.1, The original image is smoothed and filtered to obtain an image 3-6.2. because g m a s k ( x , y ) g_{mask}(x, y) gmask(x,y) The displayed results are difficult to observe with the naked eye, so they are not displayed . The final enhanced image is 3-6.3. In fact, if g m a s k ( x , y ) g_{mask}(x, y) gmask(x,y) The coefficient before is 1, The present situation , Image enhancement is difficult to show , However, if the coefficient is increased, a lot of noise will appear .
3.3 result



appendix 1: Histogram equalization
% Read images
pic = imread('./DIP3E_Original_Images_CH03/Fig0308(a)(fractured_spine).tif');
% pic = int64(pic);
% Original image and histogram
count = count_histogram(pic);
x = 0:255;
subplot(3, 2, 1);
imshow(pic);
subplot(3, 2, 2);
bar(x, count);
% Use matlab Its own histogram equalization
pic_hiseq = histeq(pic);
subplot(3, 2, 3);
imshow(pic_hiseq);
subplot(3, 2, 4);
imhist(pic_hiseq);
% Use their own histogram equalization
pic_new = histogram_equalization(pic);
subplot(3, 2, 5);
imshow(pic_new, []);
count = count_histogram(pic_new);
x = 0:255;
subplot(3, 2, 6);
bar(x, count);
% Function for calculating histogram
function count = count_histogram(pic)
[m, n] = size(pic);
count = zeros(1, 256);
for i = 1:m
for j = 1:n
count(pic(i, j) + 1) = count(pic(i, j) + 1) + 1;
end
end
end
% Histogram equalization of the image
function new_pic = histogram_equalization(pic)
[m, n] = size(pic);
count = count_histogram(pic);
new_pic = zeros(m, n);
s = zeros(1, 256);
for i = 1:256
for j = 1:i
s(i) = s(i) + 255 * count(j) / (m * n);
end
s(i) = round(s(i));
end
for i = 1:m
for j = 1:n
new_pic(i, j) = s(pic(i, j) + 1);
end
end
end
appendix 2: Sharpening image code
pic = imread("./DIP3E_Original_Images_CH03/Fig0338(a)(blurry_moon).tif");
mask = [-1, -1, -1; -1, 8, -1; -1, -1, -1];
pic_new = imfilter(pic, mask);
pic_new = pic_new + pic;
% Processing images of the moon
subplot(2, 2, 1);
imshow(pic);
subplot(2, 2, 2);
imshow(pic_new);
% Working with text images
pic_word = imread("./DIP3E_Original_Images_CH03/Fig0340(a)(dipxe_text).tif");
pic_word_new = pic_word + imfilter(pic_word, mask);
subplot(2, 2, 3);
imshow(pic_word);
subplot(2, 2, 4);
imshow(pic_word_new);
appendix 3: Unsharp mask enhanced image
pic = imread("./DIP3E_Original_Images_CH03/Fig0343(a)(skeleton_orig).tif");
smooth_mask = [1, 1, 1; 1, 1, 1; 1, 1, 1] ./ 9;
% Smooth filtering
smooth_pic = imfilter(pic, smooth_mask);
% Get mask
g_mask = pic - smooth_pic;
% Image enhancement
new_pic = pic + g_mask ;
subplot(1, 3, 1);
imshow(pic);
subplot(1, 3, 2);
imshow(smooth_pic);
subplot(1, 3, 3);
imshow(new_pic);
边栏推荐
- The performance of arm's new CPU has been improved by 22%, up to 12 cores can be combined, and the GPU is first equipped with hardware optical tracking. Netizen: the gap with apple is growing
- Get through the supply chain Shenzhen gift show helps cross-border e-commerce find ways to break the situation
- Detailed explanation of commissioning methods and techniques
- "Kunming City coffee map" was opened again, and coffee brought the city closer
- 孙安民作品《莲花净心》数字藏品上线长城数艺
- Go -- maximum heap and minimum heap
- 乡村振兴公益基金启动暨古茶树非遗保护公益行发布
- R language plot visualization: use plot to visualize the prediction confidence of the multi classification model, the prediction confidence of each data point of the model in the 2D grid, and the conf
- train_ de.py: error: argument --save_ steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
- The famous painter shiguoliang's "harvest season" digital collection was launched on the Great Wall Digital Art
猜你喜欢

著名画家史国良《丰收时节》数字藏品上线长城数艺

Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development

MySQL index, transaction and storage engine of database (2)

“昆明城市咖啡地图”再度开启,咖啡拉近城市距离

RobotFramework学习笔记:环境安装以及robotframework-browser插件的安装
[email protected]在oled上控制一条狗的奔跑"/>技能梳理[email protected]在oled上控制一条狗的奔跑
[email protected]基于51系列单片机的智能仪器教具"/>技能梳理[email protected]基于51系列单片机的智能仪器教具

ArcGIS PRO + PS vectorized land use planning map

GeoffreyHinton:我的五十年深度学习生涯与研究心法

Chen Haotian won the national championship of the national finals of the 7th children's model star ceremony
随机推荐
"Kunming City coffee map" activity was launched again
Who should the newly admitted miners bow to in front of the chip machine and the graphics card machine
技能梳理[email protected]语音模块+stm32+nfc
Gd32 RT thread ota/bootloader driver function
Es common curl finishing
GD32 RT-Thread PWM驱动函数
Skill combing [email protected] somatosensory manipulator
Jinbei LT6 is powerful in the year of the tiger, making waves
Notes on numerical calculation - iterative solution of linear equations
孙安民作品《莲花净心》数字藏品上线长城数艺
Migrate full RT thread to gd32f4xx (detailed)
安徽《合肥市装配式建筑施工图审查设计深度要求》印发;河北衡水市调整装配式建筑预售许可标准
Configure Yii: display MySQL extension module verification failed
MySQL index, transaction and storage engine of database (3)
转卡通学习笔记
I found a wave of "alchemy artifact" in the goose factory. The developer should pack it quickly
MySQL log management, backup and recovery of databases (2)
[AGC] build service 3- authentication service example
The digital collection of sunanmin's lotus heart clearing was launched on the Great Wall Digital Art
Criu enables hot migration