#include "image.h"
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Some of the code are from elsewhere. The PGM routines are taken from
* G. Daivs code.
*
* Mow-Song, Ng 2/9/2002
* msng@mmu.edu.my
* http://www.pesona.mmu.edu.my/~msng
*
* I do not claim copyright to the code, but if you use them or modify them,
* please drop me a mail.
*
*/
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
int SetImage(PIMAGE pimageSrc, unsigned char val)
{
if (pimageSrc->pixel[0] != NULL){
memset(pimageSrc->pixel[0], val, (pimageSrc->xsize) * (pimageSrc->ysize) * sizeof(unsigned char));
return 1;
}
else{
return 0;
}
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
int ImageDynamicRange(PIMAGE pimage, unsigned char *MaxPixel, unsigned char *MinPixel)
{
unsigned char TempPixel;
int i, j;
*MaxPixel=MIN_GREY;
*MinPixel=MAX_GREY;
if (pimage->pixel[0] != NULL){
for (j=0; j<pimage->ysize; j++){
for (i=0; i<pimage->xsize; i++){
TempPixel=pimage->pixel[j][i];
if (TempPixel > *MaxPixel){
*MaxPixel=TempPixel;
}
if (TempPixel < *MinPixel){
*MinPixel=TempPixel;
}
}
}
return 1;
}
else{
return 0;
}
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
PIMAGE ReadRawGreyFile(int xsize, int ysize, char *filename)
{
int i;
PIMAGE pimage;
FILE *fp;
pimage = (PIMAGE)malloc(sizeof(IMAGE));
pimage->xsize=xsize;
pimage->ysize=ysize;
/* Allocate memory */
if(!ImageBufferAlloc(pimage)){
free(pimage);
return NULL;
}
/* open the file */
if ((fp=fopen(filename, "rb"))==NULL){
ImageBufferFree(pimage);
free(pimage);
return NULL;
}
i=fread(pimage->pixel[0], sizeof(unsigned char),
(pimage->xsize)*(pimage->ysize), fp);
fclose(fp);
if (i!=(pimage->ysize)*(pimage->xsize)){
ImageBufferFree(pimage);
free(pimage);
return NULL;
}
else{
return pimage;
}
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
PFIMAGE ReadRawGreyFileToFloat(int xsize, int ysize, char *filename)
{
int i;
PFIMAGE pfimage;
FILE *fp;
unsigned char **temp, *tempLinear;
/* temporary buffer */
temp = Byte_Alloc(ysize , xsize);
tempLinear=temp[0];
if(temp == NULL){
return NULL;
}
/* open the file */
if ((fp=fopen(filename, "rb"))==NULL){
free(temp[0]);
return NULL;
}
/* read the image */
i=fread(temp[0], sizeof(unsigned char), xsize*ysize, fp);
fclose(fp);
if (i!=ysize*xsize){
free(temp[0]);
return NULL;
}
pfimage = (PFIMAGE)malloc(sizeof(FIMAGE));
pfimage->xsize=xsize;
pfimage->ysize=ysize;
/* Allocate memory */
if(!FImageBufferAlloc(pfimage)){
free(pfimage);
free(temp[0]);
return NULL;
}
/* Copy */
for (i=0; i< xsize*ysize; i++){
pfimage->pixelLinear[i]=(double)tempLinear[i];
}
free(temp[0]);
return pfimage;
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
int WriteFloatToRawGreyFile(PFIMAGE pfimage, char *filename)
{
int i;
FILE *fp;
unsigned char **temp, *tempLinear;
temp=Byte_Alloc(pfimage->ysize, pfimage->xsize);
tempLinear=temp[0];
if (temp==NULL){
return 0;
}
if((fp=fopen(filename, "wb"))==NULL){
free(temp[0]);
return 0;
}
/* Copy */
for (i=0; i<pfimage->xsize*pfimage->ysize; i++){
tempLinear[i]=(int)((pfimage->pixelLinear[i]+0.5) < 0.0 ? 0 :
((pfimage->pixelLinear[i]+0.5) > 255.0 ? 255 :
(pfimage->pixelLinear[i]+0.5)));
}
i=fwrite(temp[0], sizeof(unsigned char), (pfimage->ysize)*(pfimage->xsize), fp);
fclose(fp);
free(temp[0]);
if (i!=(pfimage->ysize)*(pfimage->xsize)){
return 0;
}
else{
return i;
}
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
PLIMAGE ReadRaw32File(int xsize, int ysize, char *filename)
{
int i;
PLIMAGE plimage;
FILE *fp;
plimage = (PLIMAGE)malloc(sizeof(LIMAGE));
plimage->xsize=xsize;
plimage->ysize=ysize;
/* Allocate memory */
if(!LImageBufferAlloc(plimage)){
free(plimage);
return NULL;
}
/* open the file */
if ((fp=fopen(filename, "rb"))==NULL){
LImageBufferFree(plimage);
free(plimage);
return NULL;
}
i=fread(plimage->pixel[0], sizeof(int),
(plimage->xsize)*(plimage->ysize), fp);
fclose(fp);
if (i!=(plimage->ysize)*(plimage->xsize)){
LImageBufferFree(plimage);
free(plimage);
return NULL;
}
else{
return plimage;
}
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
PFIMAGE ReadRawFloatFile(int xsize, int ysize, char *filename)
{
int i;
PFIMAGE pfimage;
FILE *fp;
pfimage = (PFIMAGE)malloc(sizeof(FIMAGE));
pfimage->xsize=xsize;
pfimage->ysize=ysize;
/* Allocate memory */
if(!FImageBufferAlloc(pfimage)){
free(pfimage);
return NULL;
}
/* open the file */
if ((fp=fopen(filename, "rb"))==NULL){
FImageBufferFree(pfimage);
free(pfimage);
return NULL;
}
i=fread(pfimage->pixel[0], sizeof(double),
(pfimage->xsize)*(pfimage->ysize), fp);
fclose(fp);
if (i!=(pfimage->ysize)*(pfimage->xsize)){
FImageBufferFree(pfimage);
free(pfimage);
return NULL;
}
else{
return pfimage;
}
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
int WriteRawGreyFile(PIMAGE pimage, char *filename)
{
int i;
FILE *fp;
if((fp=fopen(filename, "wb"))==NULL){
return 0;
}
i=fwrite(pimage->pixel[0], sizeof(unsigned char),
(pimage->ysize)*(pimage->xsize), fp);
fclose(fp);
if (i!=(pimage->ysize)*(pimage->xsize)){
return 0;
}
else{
return i;
}
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
int WriteRaw32File(PLIMAGE plimage, char *filename)
{
int i;
FILE *fp;
if((fp=fopen(filename, "wb"))==NULL){
return 0;
}
i=fwrite(plimage->pixel[0], sizeof(int),
(plimage->xsize)*(plimage->ysize), fp);
fclose(fp);
if (i!=(plimage->ysize)*(plimage->xsize)){
return 0;
}
else{
return i;
}
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
int WriteRawFloatFile(PFIMAGE pfimage, char *filename)
{
int i;
FILE *fp;
if((fp=fo
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
程序.rar (85个子文件)
程序
EZW-VC++
GLOBAL.H 2KB
MAP.C 5KB
subbandsymbol.h 1KB
wtransform.h 4KB
IMAGE.H 5KB
IMAGE.C 37KB
MEM.C 4KB
subbandsymbol.c 5KB
EZW.H 4KB
UNEZW.C 19KB
EZW.C 25KB
BITIO.H 2KB
MEM.H 1KB
EZW
EZW.OPT 52KB
EZW.ncb 193KB
EZW.DEP 1023B
EZW.PLG 240B
_tmp_project.h 233B
EZW.DSW 514B
Debug
bitio.obj 11KB
vc60.pdb 60KB
mem.obj 9KB
global.obj 10KB
filter.obj 24KB
map.obj 7KB
wavelet.obj 21KB
vc60.idb 57KB
image.obj 59KB
EZW.pdb 609KB
EZW.exe 332KB
ezw.obj 35KB
subbandsymbol.obj 8KB
aricacm.obj 39KB
EZW.ilk 354KB
wtransform.obj 23KB
memchk.obj 11KB
EZW.MAK 7KB
EZW.DSP 6KB
MEMCHK.H 3KB
WAVELET.H 3KB
wtransform.c 17KB
EZW2.OPT 64KB
ARICACM.C 30KB
EZW2.DSW 724B
GLOBAL.C 4KB
BITIO.C 5KB
ARICACM.H 10KB
FILTER.H 3KB
FILTER.C 24KB
EZW2.NCB 281KB
MEMCHK.C 11KB
WAVELET.C 19KB
MAP.H 2KB
UNEZW
UNEZW.OPT 49KB
UNEZW.DSW 518B
_tmp_project.h 233B
UNEZW.ncb 193KB
UNEZW.DSP 6KB
Debug
bitio.obj 11KB
vc60.pdb 60KB
mem.obj 9KB
UNEZW.exe 328KB
global.obj 10KB
unezw.obj 28KB
filter.obj 24KB
UNEZW.ilk 360KB
map.obj 7KB
wavelet.obj 21KB
vc60.idb 57KB
image.obj 59KB
UNEZW.pdb 745KB
subbandsymbol.obj 8KB
aricacm.obj 39KB
wtransform.obj 23KB
memchk.obj 11KB
UNEZW.DEP 1KB
UNEZW.MAK 7KB
UNEZW.PLG 2KB
readme.doc 25KB
BARBARA.PGM 256KB
MATLAB
barbara_1.000000_6_antonini_256_0.unezw.pgm 256KB
barbara_0.500000_6_antonini_256_0.unezw.pgm 256KB
PSNRandMSE.m 588B
BARBARA.PGM 256KB
barbara_0.250000_6_antonini_256_0.unezw.pgm 256KB
共 85 条
- 1
资源评论
- 龚1正2015-08-26为什么打不开.pgm的图片
N091120081
- 粉丝: 27
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- OpenCv 使用fffffffff
- 正点原子开拓者FPGA多人表决器代码项目
- EOP-Last5Years.txt
- windows 32位、64位系统常见缺少的库
- 毕业设计基于springboot+vue实现的求职招聘类型网站源码+数据库(高分项目).zip
- 535springboot + vue 体质测试数据分析及可视化设计.zip(可运行源码+数据库文件+文档)
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统源码.zip
- 基于springboot+vue实现的求职招聘类型网站源代码+数据库(优质毕设项目).zip
- iOS APP提审checklist
- 第十四届中北大学ACM程序设计竞赛.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功