当前位置:网站首页>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);
边栏推荐
- "Kunming City coffee map" activity was launched again
- train_ de.py: error: argument --save_ steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
- R语言plotly可视化:使用plotly可视化多分类模型的预测置信度、模型在2D网格中每个数据点预测的置信度、置信度定义为在某一点上最高分与其他类别得分之和之间的差值
- Eth is not connected to the ore pool
- Ant s19xp appeared in 140t, why is it called the computing power ceiling by the world
- CVPR 2022 | Tsinghua & bytek & JD put forward BRT: Bridging Transformer for vision and point cloud 3D target detection
- ArcGIS Pro脚本工具(6)——修复CAD图层数据源
- Leetcode question brushing (IV) -- greedy thought (go Implementation)
- Action bright: take good care of children's eyes together -- a summary of the field investigation on the implementation of action bright in Guangxi
- GNN hands on practice (II): reproduction graph attention network gat
猜你喜欢
新冠无情人有情,芸众惠爱心善举暖人间——捐赠商丘市儿童福利院公益行动
CVPR 2022 | 清华&字节&京东提出BrT:用于视觉和点云3D目标检测的桥接Transformer
MIT-6874-Deep Learning in the Life Sciences Week4
Dyson design award, changing the world with sustainable design
从0使用keil5软件仿真调试GD32F305
MySQL index, transaction and storage engine of database (2)
Eth is not connected to the ore pool
The preliminary round of the sixth season of 2022 perfect children's model Hefei competition area was successfully concluded
长城数艺数字藏品平台发布创世徽章
CSDN博客运营团队2022年H1总结
随机推荐
MySQL log management, backup and recovery of databases (2)
Skill combing [email protected] control a dog's running on OLED
The programmer was beaten.
Test memory read rate
GD32 RT-Thread flash驱动函数
Who should the newly admitted miners bow to in front of the chip machine and the graphics card machine
The latest SCI impact factor release: the highest score of domestic journals is 46! Netizen: I understand if
CSDN博客运营团队2022年H1总结
Configure Yii: display MySQL extension module verification failed
Go -- standard library sort package
Automated stock trading ensemble strategy based on Reinforcement Learning
Guolin was crowned the third place of global popularity of perfect master in the third quarter of 2022
SGD有多种改进的形式,为什么大多数论文中仍然用SGD?
The preliminary round of the sixth season of 2022 perfect children's model Hefei competition area was successfully concluded
Use keil5 software to simulate and debug gd32f305 from 0
ArcGIS PRO + PS vectorized land use planning map
"Kunming City coffee map" activity was launched again
今晚19:00知识赋能第2期直播丨OpenHarmony智能家居项目之控制面板界面设计
华南产业集团发力数字经济,城链科技发布会成功召开
Splendid China: public welfare tourism for the middle-aged and the elderly - entering Foshan nursing home