社区
新手乐园
帖子详情
怎样用c读取pgm格式的图像文件
1062
2008-10-26 10:28:19
有c源码的最好
现在需要读取pgm格式文件,将其转换为灰度值矩阵
如一个112×92的图像
结果应是一个112×92的矩阵,其中元素是原图像的灰度值
...全文
763
2
打赏
收藏
怎样用c读取pgm格式的图像文件
有c源码的最好 现在需要读取pgm格式文件,将其转换为灰度值矩阵 如一个112×92的图像 结果应是一个112×92的矩阵,其中元素是原图像的灰度值
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
碎片球球
2012-06-20
打赏
举报
回复
http://blog.pfan.cn/miaowei/50921.html
http://download.csdn.net/download/zt0621/2366090
或者public void LoadPgmFile(string path)
...{
fileStream = new FileStream(path, FileMode.Open);
stringReader = new StreamReader(fileStream);
string typeHead = stringReader.ReadLine();
string sizeHead = stringReader.ReadLine();
if (typeHead[1] == '5')
...{
data.Type = PGMType.P5;
}
else
...{
if (typeHead[1] == '2')
...{
data.Type = PGMType.P2;
}
else
...{
data.Type = PGMType.UNKOWN;
throw new UnKonwPGMTypeException ();
return;
}
}
int midPosit = 0;
for (int posit = 0; posit < sizeHead.Length; posit++)
...{
if (sizeHead[posit] == ' ')
...{
midPosit = posit;
break;
}
}
if (midPosit == 0)
...{
data.Width = Convert.ToUInt32(sizeHead);
sizeHead = null;
sizeHead = stringReader.ReadLine();
data.Height = Convert.ToUInt32(sizeHead);
}
else
...{
StringBuilder sizeHead2 = new StringBuilder();
for(int posit = 0 ; posit < midPosit ; posit++)
...{
sizeHead2.Append(sizeHead[posit]);
}
data.Width = Convert.ToUInt32(sizeHead2.ToString());
sizeHead2 = new StringBuilder();
for (int posit = midPosit; posit < sizeHead.Length; posit++)
...{
sizeHead2.Append(sizeHead[posit]);
}
data.Height = Convert.ToUInt32(sizeHead2.ToString());
}
string grayMax = stringReader.ReadLine();
data.GrayMax = Convert.ToByte(grayMax);
if (data.Type == PGMType.P5)
...{
binaryReader = new BinaryReader(fileStream);
data.PgmByteData = new byte[data.PixelCount];
binaryReader.Read(data.PgmByteData, 0, data.PixelCount);
stringReader.Close();
binaryReader.Close();
}
if (data.Type == PGMType.P2)
...{
data.PgmStringData = new string[data.Height,data.Width];
data.PgmByteData = new byte[data.PixelCount];
char[] temp0, temp;
int lineLength = 0;
for (int row = 0; row < data.Height; row++)
...{
for (int col = 0; col < data.Width; col++)
...{
if (row == 3&& col == 0x12)
col = col;
temp0 = new char[4];
stringReader.Read(temp0, 0, 4);
lineLength += 4;
int posit = 0;
for (int i = 0; i < 4; i++)
...{
if (temp0[i] == ' ')
...{
posit = i;
break;
}
}
temp = new char[posit];
for (int i = 0; i < posit; i++)
...{
temp[i] = temp0[i];
}
data.PgmStringData[row, col] = new String(temp);
data.PgmByteData[row * data.Width + col] =
Convert.ToByte(data.PgmStringData[row, col]);
if (lineLength >= 70)
...{
stringReader.Read();
lineLength = 0;
if (col == (data.Width - 1))
continue;
}
if (col == (data.Width - 1))
...{
stringReader.Read();
lineLength = 0;
}
}
}
}
fileStream.Close();
}
1062
2008-10-30
打赏
举报
回复
哪位大虾帮帮忙啊
pgm
数据
读取
与保存
该程序用于
pgm
格式
的图像
读取
与保存,C++编写,可直接运行,希望能够帮助到有需要的人。
PGM
格式
的图像由头信息和数据信息构成。
PGM
:Java中一个简单的
PGM
操作工具
Java 中的便携式 GrayMap 工具贡献者:Thomas BUICK、Thomas DURAND 和 Loïc MOLLET-PADIER特征该工具允许对
PGM
文件进行可视化、保存和应用一些功能。图像处理直方图调整图像大小(最近、方框或双线性)图像过滤...
dicomreader:DicomReader是一个简单的Java Dicom文件解密程序
如果还需要
pgm
图像,则其名称是根据ascii文本图像的文件名自动生成的。 DicomReader需要一台Dicom词典才能工作,它可以从中
读取
Dicom标签并据此对每个标签采取正确的措施。 如果提供了多个切片的Dicom文件,则...
PGM
图像
读取
与存储(C语言)
PGM
图像
读取
与存储(C语言) 01 图片
格式
介绍
PGM
是一种灰度图像的存储
格式
,下分P5和P2两种类型;P2以ASCII码形式存储,P5以二进制形式存储。 图片由两部分数据组成,一部分是文件头部分(包含图片类型、图片宽度、...
CUDA:使用C/C++获取输入
PGM
图像并生成输出
PGM
图像的示例
我们将编写一个程序,该程序将
读取
输入的
PGM
图像文件
,对其进行处理,然后将处理后的图像保存为输出的
PGM
图像文件
。函数中,我们首先打开输入
图像文件
,并
读取
PGM
文件头信息,包括图像的宽度、高度和最大灰度值。...
新手乐园
33,311
社区成员
41,784
社区内容
发帖
与我相关
我的任务
新手乐园
C/C++ 新手乐园
复制链接
扫一扫
分享
社区描述
C/C++ 新手乐园
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章