資源簡介
常用的圖像歸一化算法,將不同大小的圖像 歸一化成固定大小的圖像,對于做圖像模板有很好的用處,經過測試可用。。。。。。。。。。。。。。。。

代碼片段和文件信息
/*
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的學習資料匯總
評論
共有 條評論