最小值滤波 (C 语言实现)
最小值滤波 (C 语言实现)
遇到最小值滤波的问题,小白不知道。一个程序写了三天,最终今天傍晚出来了。
。。
非常easy的for循环。可是没有理解最小值滤波。怎么写都是错啊~
这是我见过做好的描写叙述,关于最小值滤波:
3*3的像素点阵,对于中心点做最小值滤波的话,它的值将从77变换到0
处理结果图:
我一直支持也坚持开源分享的原则。为大家更好的相互学习,给出源码
/******************************************************************
code writer : EOF
code date : 2014.08.07
e-mail : jasonleaster@gmail.com jasonleaster@163.com code purpose:
This demo is coded for mininum value filter.
If you find something wrong with my code, please touch me by e-mail.
Thank you. *******************************************************************/ #include "opencv2/highgui/highgui_c.h"
#include "opencv2/imgproc/imgproc_c.h" #include <stdio.h> /*------------------------------------------------------------------------------ This two Macro are used for debugging, if you are begginer with OpenCV,
it will help you to know and test what inside of the data struture in OpenCV -------------------------------------------------------------------------------*/ //#define RGB_TEST_DEBUG
//#define CHANNEL_TEST_DEBUG /* the offset of three channel RGB */
#define RED_BIT 2
#define GREEN_BIT 1
#define BLUE_BIT 0 #define SQUARE_LENGTH 15 int get_dark_imagine(IplImage* const img_origin,IplImage* const img_win_dark); int main(int argc,char* argv[])
{
char* win_name_bf = "Before Processing";
char* win_name_af = "After Processing"; CvSize size; IplImage* img_origin = cvLoadImage(argv[1],CV_LOAD_IMAGE_COLOR); size.height = img_origin->height;
size.width = img_origin->width; IplImage* img_win_dark = cvCreateImage(size,IPL_DEPTH_8U,1);//single channel get_dark_imagine(img_origin,img_win_dark); cvNamedWindow(win_name_bf,CV_WINDOW_AUTOSIZE);
//cvNamedWindow is a function which would help you to creat a window. cvShowImage(win_name_bf,img_origin);
//Obviously, show the picture that you inputed. cvNamedWindow(win_name_af,CV_WINDOW_AUTOSIZE);
//cvNamedWindow is a function which would help you to creat a window. cvShowImage(win_name_af,img_win_dark);
//Obviously, show the picture that you inputed. cvWaitKey(0);
//pause and let the user see the picture. cvReleaseImage(&img_origin);
cvReleaseImage(&img_win_dark);
//Finally, release the struture, otherwise, memory leak ! return 0;
} int get_dark_imagine(IplImage* const img_origin,IplImage* const img_win_dark)
{
/*
Varible description: @img_origin : A pointer which point to the original picture's IplImage-structure.
@img_win_dark: A pointer which point to the dark-window's IplImage-structure.
*/ if(img_origin == NULL || img_win_dark == NULL)
{
printf("Error! img_origin or img_win_dark is NULL\n"); return 1;
} int height_origin = img_origin->height ;
int width_origin = img_origin->width ;//the search band width. unsigned char * const ptr_array_origin = (unsigned char*)img_origin->imageData;
unsigned char * const ptr_array_win_dark = (unsigned char*)img_win_dark->imageData; unsigned char* ptr_header_origin = NULL; int row = 0;
int col = 0;
int square_row = 0;
int square_col = 0; int min = 0;
int T_min = 0;
int temp_R = 0;
int temp_G = 0;
int temp_B = 0;
int temp = 0; int search_win_start = SQUARE_LENGTH/2; /*
define two varible -- height_origin & width_origin for up band-width of the search-window
*/ int search_win_height_end = img_win_dark->height - SQUARE_LENGTH/2;
int search_win_width_end = img_win_dark->width - SQUARE_LENGTH/2; //initializition of the picture's data that 'ptr_array_win_dark' point to.
for(row = 0; row < height_origin; row++)
{
for(col = 0; col < width_origin ;col++)
{
*(ptr_array_win_dark + col + row*(img_win_dark->widthStep)) = 255; }
} //Mininum value filter
for(row = search_win_start; row < search_win_height_end; row++)
{ for(col = search_win_start; col < search_win_width_end ;col++)
{ ptr_header_origin = ptr_array_origin + (row)*(img_origin->widthStep) + (col)*3; temp_B = *(ptr_header_origin + BLUE_BIT );
temp_G = *(ptr_header_origin + GREEN_BIT );
temp_R = *(ptr_header_origin + RED_BIT ); min = (temp_G < temp_B) ? temp_G : temp_B;
min = (min < temp_R) ? min : temp_R; T_min = min; for(square_row = (row - search_win_start); square_row < (row + search_win_start + 1);square_row++)
{
for(square_col = (col - search_win_start); square_col < (col+search_win_start + 1);square_col++)
{
min = *(ptr_array_win_dark + square_col + square_row*(img_win_dark->widthStep)); if (min > T_min)
{
*(ptr_array_win_dark + square_col + square_row*(img_win_dark->widthStep)) = (T_min);
}
}
}
}
} return 0;
}
如有错误。欢迎交流指正
—— EOF
update : 2014.10.05
写了一个matlab版本号的最小滤波算法框架
Img_filted = dark_channel;
for row = 1 : height
for col = 1 : width min_value = dark_channel(row,col);
for patch_row = (row -floor(search_win_height/2)) : (row + floor(search_win_height/2))
for patch_col = (col - floor(search_win_width/2)) : (col + floor(search_win_width/2)) if patch_row > 0 && patch_col > 0 && patch_row <= height && patch_col <= width
if min_value < Img_filted(patch_row,patch_col)
Img_filted(patch_row,patch_col) = min_value;
end
end
end
end
end
end
最小值滤波 (C 语言实现)的更多相关文章
- 中值滤波C语言优化
中值滤波C语言优化 图像平滑是图像预处理的基本操作,本文首先用不同的方法对一张图片做预处理比较它们效果的不同,然后针对中值滤波,实现了一种快速实现.(其实是copy的opencv实现,呵呵).因为op ...
- OpenCV之邻域运算之最值滤波
写了一段小程序,分享给大家! //==================================================================== // 作者 : quarry ...
- 基于R语言的数据分析和挖掘方法总结——描述性统计
1.1 方法简介 描述性统计包含多种基本描述统计量,让用户对于数据结构可以有一个初步的认识.在此所提供之统计量包含: 基本信息:样本数.总和 集中趋势:均值.中位数.众数 离散趋势:方差(标准差).变 ...
- Opencv中常见的滤波方法
滤波(模糊)的概念和作用: 图像滤波增强处理实质上就是运用滤波技术来增强图像的某些空间频率特征,以改善地物目标与领域或背景之间的灰度反差. 遥感系统成像过程中可能产生的”模糊”作用,常使遥感图像上某些 ...
- 《Single Image Haze Removal Using Dark Channel Prior》一文中图像去雾算法的原理、实现、效果(速度可实时)
最新的效果见 :http://video.sina.com.cn/v/b/124538950-1254492273.html 可处理视频的示例:视频去雾效果 在图像去雾这个领域,几乎没有人不知道< ...
- paper 105: 《Single Image Haze Removal Using Dark Channel Prior》一文中图像去雾算法的原理、实现、效果及其他
在图像去雾这个领域,几乎没有人不知道<Single Image Haze Removal Using Dark Channel Prior>这篇文章,该文是2009年CVPR最佳论文.作者 ...
- Single Image Haze Removal Using Dark Channel Prior
<Single Image Haze Removal Using Dark Channel Prior>一文中图像去雾算法的原理.实现.效果及其他. Posted on 2013-08-2 ...
- MinFilter(MaxFilter)快速算法C++实现
目录 1.算法简述 1.1.MinFilter(MaxFilter) 算法简述 1.2.MinFilter(MaxFilter) 快速算法简述 2.实现代码 2.1.MinFilterOneRow 单 ...
- 任意半径局部直方图类算法在PC中快速实现的框架。
在图像处理中,局部算法一般来说,在很大程度上会获得比全局算法更为好的效果,因为他考虑到了图像领域像素的信息,而很多局部算法可以借助于直方图获得加速.同时,一些常规的算法,比如中值滤波.最大值滤波.最小 ...
随机推荐
- MSSQL:修改tempdb设置增加DW性能
Temp DB 在DW中变得非常重要,因为要进行大量的运算,如果内存不够数据就会放在Temp DB中 1. 把Temp DB移动到高性能的磁盘上. 2. 增加tempdb 的大小 3. 把Auto S ...
- ajax_异步交互-get/post方式
Ajax的异步交互: 客户端向服务器端发送请求,直到服务器端进行响应,这个过程中,用户可以做任何其他事情(不等). 实现Ajax的异步交互步骤(举例说明): get方式: 1.创建XMLHttpReq ...
- js 中日期 转换成时间戳 例如2013-08-30 转换为时间戳
//时间格式2014-02-02 14:10:00改成时间戳 //此时构造出来的时间是:2013/03/08 00:00:00. //这样得到的是一个数值,表示的是从1970年1月1日0点0分0秒到d ...
- 控制所生成的servlet的结构: JSP page指令
在JSP中,主要有3种类型的指令:page, include和taglib.page指令允许我们通过类的导入.servlet超类的定制.内容类型的设置.以及诸如此类的事物来控制servlet的结构.p ...
- C语言:类似linux内核的分等级DEBUG宏(打印宏)
总结几种log打印printf函数的宏定义 http://blog.chinaunix.net/uid-20564848-id-73402.html #include <stdio.h> ...
- Codecademy学习打卡1
————————————————————————— 想学习编程,并且打算“闭门造车”式的开启我的自学生涯. 前段时间买了一门厚重的“Java从入门到精通”.或许是对代码,电脑编程环境的陌生,再加上纯小 ...
- Protel99se教程五:protel99se的自动布线
在上一节课的protel99se教程中,我们给大家演示的是,如何快速的将SCH原理PCB,也就是将元件转到PCB中,在这一节课,我们主要给大家讲解的是何在protel99se快速布线,我们在这节课当中 ...
- HDU 1276 士兵队列训练问题
模拟题,学了一下list it=li.erase(it):指向删除后的第一个元素 #include <cstdio> #include <list> using namespa ...
- Oracle DBA常用的系统表
1.2 DBA常用的表1.2.1 dba_开头 dba_users数据库用户信息 dba_segments 表段信息 dba_extents 数据区信息 dba_ob ...
- BZOJ 3402: [Usaco2009 Open]Hide and Seek 捉迷藏
题目 3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec Memory Limit: 128 MB Description 贝 ...