最大值、最小值、中值、均值滤波
来源:互联网 发布:java题目 编辑:程序博客网 时间:2024/05/02 01:49
0 定义及用途
均值滤波,即以模板内算术平均数的值代替中心像素值,可以降低高斯噪声。
中值滤波,即以模板内进行有序排列后位于中间的像素值代替中心像素值,可以降低椒盐噪声。
最大值滤波,即以模板内进行有序排列后最大像素值代替中心像素值,可以去除图像中的暗斑,使亮斑增大。
最小值滤波,即以模板内进行有序排列后最小像素值代替中心像素值,可以去除图像中的亮斑,使暗斑增大。
1 代码
class Filter{
public:
Filter(intwidth, int height) : width_(width),height_(height) {
dst_img_.create(height,width, CV_8UC1);
}
~Filter() {
}
virtual cv::Mat&do_filter(cv::Mat&src_img) = 0;
const int radius_ = 1; // 3 * 3 model
int height_;
int width_;
cv::Matdst_img_;
};
class MeanFilter : public Filter{
public:
MeanFilter(intwidth, int height) : Filter(width,height) {
};
~MeanFilter() {
};
cv::Mat&do_filter(cv::Mat&src_img) {
int template_size = (2 * radius_ + 1)*(2 * radius_ + 1);
for (inti = 0; i < src_img.rows; ++i) {
for (intj = 0; j < src_img.cols; ++j) {
int roi_sum = 0;
for (intm = -radius_; m <= radius_; m++) {
int r_offset = m + i;
r_offset = (r_offset < 0) ? 0 : (r_offset >=src_img.rows ?src_img.rows :r_offset);
for (intn = -radius_; n <= radius_; n++) {
int c_offset = n + j;
c_offset = (c_offset < 0) ? 0 : (c_offset >=src_img.cols ?src_img.cols :c_offset);
roi_sum +=static_cast<int>(src_img.at<unsignedchar>(r_offset, c_offset));
}
}
dst_img_.at<unsignedchar>(i, j) = roi_sum / template_size;
}
}
return dst_img_;
}
};
// 均值滤波,最大值滤波,最小值滤波
class MiddleFilter : public Filter {
public:
enum {
MIN = 0,
MIDDLE = 1,
MAX = 2
}Method;
MiddleFilter(intwidth, int height, int method =MIDDLE) : Filter(width,height),
method_(method){
};
~MiddleFilter() {
};
cv::Mat&do_filter(cv::Mat&src_img) {
int template_size = (2 * radius_ + 1)*(2 * radius_ + 1);
unsigned char *template_value = new unsigned char[template_size];
for (inti = 0; i < src_img.rows; ++i) {
for (intj = 0; j < src_img.cols; ++j) {
int index = 0;
memset(template_value, 0,template_size);
for (intm = -radius_; m <= radius_; m++) {
int r_offset = m + i;
r_offset = (r_offset < 0) ? 0 : (r_offset >=src_img.rows ?src_img.rows :r_offset);
for (intn = -radius_; n <= radius_; n++) {
int c_offset = n + j;
c_offset = (c_offset < 0) ? 0 : (c_offset >=src_img.cols ?src_img.cols :c_offset);
template_value[index++] =src_img.at<unsignedchar>(r_offset, c_offset);
}
}
quick_sort(template_value, 0,template_size - 1);
if (method_ ==MIN) {
dst_img_.at<uchar>(i,j) = template_value[0];
} else if (method_ == MIDDLE) {
dst_img_.at<uchar>(i,j) = template_value[template_size / 2];
} else {
dst_img_.at<uchar>(i,j) = template_value[template_size - 1];
}
}
}
delete[] template_value;
return dst_img_;
}
int method_;
};
- 最大值、最小值、中值、均值滤波
- 均值滤波,中值滤波,最大最小值滤波
- Matlab 最大值滤波 中值滤波 最小值滤波 ordfilt2
- Matlab 最大值滤波 中值滤波 最小值滤波 函数 ordfilt2
- Matlab 最大值滤波 中值滤波 最小值滤波 ordfilt2
- Matlab 最大值滤波 中值滤波 最小值滤波 ordfilt2
- Matlab 最大值滤波 中值滤波 最小值滤波 函数 ordfilt2
- 均值滤波 中值滤波 对称均值滤波
- 中值和均值滤波
- 中值滤波VS.均值滤波
- 均值滤波vs中值滤波
- 滤波算法(均值、中值、最大均值、最大中值、几何均值)
- 均值滤波、中值滤波、混合中值滤波C++源码实例
- MATLAB 图像 均值滤波 中值滤波
- 均值滤波、中值滤波的matlab实现
- 均值滤波、中值滤波的matlab实现
- 均值滤波、中值滤波的matlab实现
- 均值滤波、中值滤波的matlab实现
- electron 安装使用心酸入门随笔
- 浅析 Http Header 功能
- noip模拟 马云 Mr_H
- Hadoop2和Hadoop1的区别
- poj 1577 Falling Leaves(二叉搜索树)
- 最大值、最小值、中值、均值滤波
- 富文本编辑器ssm
- Android studio打开eclipse项目中文全部是乱码
- external table + alert_sid.log
- 【中兴笔试题】20选择+2编程
- Java数据类型与运算符面试题
- 12222
- Torry的困惑
- 为什么说持续学习才是AI的关键