资源简介
常用的图像归一化算法,将不同大小的图像 归一化成固定大小的图像,对于做图像模板有很好的用处,经过测试可用。。。。。。。。。。。。。。。。
代码片段和文件信息
/*
Clean C reimplementation of three Character Normalization algorithms.
Copyright (C) 2012 UnilVision.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation either version 3 of the
License or (at your option) any later version.
This program is distributed in the hope that it will be useful
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not see .
*/
#include “chanorm.h“
#ifndef min
#define min(ab) ((a)<(b)? (a):(b))
#endif
#ifndef max
#define max(ab) ((a)>(b)? (a):(b))
#endif
#ifndef PI
#define PI 3.1415926f
#endif
float aspect_radio_mapping(float r1 int dst_wid int dst_hei
int ratio_preserve_func)
{
switch( ratio_preserve_func )
{
case RADIOFUNC_ASPECT:
return r1;
case RADIOFUNC_SQUARE:
return (float) sqrt(r1);
case RADIOFUNC_CUBIC:
return (float) pow(r1 0.3333f);
case RADIOFUNC_SINE:
return (float) sqrt(sin(PI*r1/2));
default:
return (float) min( dst_wid dst_hei ) / max( dst_wid dst_hei );
}
}
void backward_linear(unsigned char* src int src_wid int src_hei int src_widstep
CHARECT_t* region
unsigned char* dst int dst_wid int dst_hei int dst_widstep
int ratio_preserve_func)
{
float r1 r2;
int w1 h1;
int w2 h2;
int x y;
int xoffset yoffset;
int src_xoffset src_yoffset;
float xscale yscale;
w1 = region->right-region->left;
h1 = region->bottom-region->top;
src_xoffset = region->left;
src_yoffset = region->top;
r1 = (float) min( w1 h1 ) / max( w1 h1 );
r2 = aspect_radio_mapping(r1 dst_wid dst_hei ratio_preserve_func);
memset( dst 0 dst_hei * dst_widstep);
if( w1 > h1 )
{
w2 = dst_wid;
h2 = (int) (w2 * r2);
xoffset = 0;
yoffset = (dst_hei - h2)/2;
}
else
{
h2 = dst_hei;
w2 = (int) (h2 * r2);
xoffset = (dst_wid - w2)/2;
yoffset = 0;
}
xscale = (float)w1 / w2;
yscale = (float)h1 / h2;
for (y=yoffset;y {
int j = y-yoffset;
if( j < 0 )
continue;
for (x=xoffset;x {
unsigned char* psrc *psrc1 *psrc2 *psrc3;
float tmp0;
int i = x-xoffset;
float x0 = i * xscale + src_xoffset;
float y0 = j * yscale + src_yoffset;
int x0left = (int) x0;
int y0left = (int) y0;
if( i < 0 )
continue;
if( x0left >= src_wid-1 )
{
if( y0left >= src_hei-1 )
{
psrc = src + (src_hei-1)*src_widstep + (src_wid-1);
psrc1 = psrc;
psrc2 = psrc;
psrc3 = psrc;
}
else
{
psrc = src + y0left*src_widstep + (src_wid-1);
psrc1 = sr
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 14527 2017-03-22 09:23 归一化算法代码\chanorm.c
文件 1516 2017-03-22 09:23 归一化算法代码\chanorm.h
文件 4306 2017-03-22 09:24 归一化算法代码\main.c
文件 144 2017-03-22 09:26 归一化算法代码\readme.txt
目录 0 2017-04-25 22:02 归一化算法代码
----------- --------- ---------- ----- ----
20493 5
- 上一篇:拟合函数--高斯,拉普拉斯,双高斯拟合
- 下一篇:mapx+vc的学习资料汇总
评论
共有 条评论