如何使用ImageMagick生成灰度PAM文件?

发布于 2025-01-19 20:43:22 字数 958 浏览 2 评论 0原文

使用 imagemagick 生成 P5 PGM / P6 PPM 是微不足道的,简单地使用

$ convert -depth 12 -size 512x512 xc:white white12.pgm
$ convert -depth 12 -size 512x512 xc:white white12.ppm

哪个正确给出:

% head -3 white12.ppm white12.pgm
==> white12.ppm <==
P6
512 512
4095

==> white12.pgm <==
P5
512 512
4095

现在我正在努力获取 PAM:P7 + 灰度工作,我能找到的是:

$ convert -depth 12 -size 512x512 xc:white white12.pam

它给出了 RGB 一个:

% head -7 white12.pam
P7
WIDTH 512
HEIGHT 512
DEPTH 3
MAXVAL 4095
TUPLTYPE RGB
ENDHDR

如何生成GRAYSCALE帕姆一?


我确实向上游报告了一个错误,也许我的 imagemagick 版本中有一些虚假内容:

It is trivial to generate P5 PGM / P6 PPM using imagemagick, using simply

$ convert -depth 12 -size 512x512 xc:white white12.pgm
$ convert -depth 12 -size 512x512 xc:white white12.ppm

Which correctly gives:

% head -3 white12.ppm white12.pgm
==> white12.ppm <==
P6
512 512
4095

==> white12.pgm <==
P5
512 512
4095

Now I am struggling to get PAM: P7 + Grayscale working, all I could find is:

$ convert -depth 12 -size 512x512 xc:white white12.pam

which gives the RGB one:

% head -7 white12.pam
P7
WIDTH 512
HEIGHT 512
DEPTH 3
MAXVAL 4095
TUPLTYPE RGB
ENDHDR

How can I generate the GRAYSCALE PAM one ?


I did report a bug upstream, maybe there is something bogus in my imagemagick version:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟酒忠诚 2025-01-26 20:43:22

我认为 ImageMagick 中有一个错误。这可能是一个解决方法:

magick -depth 12 -size 512x512 gradient: -colorspace gray -compress none pgm:- | awk '
   NR==2 {w=$1; h=$2}     # pick up and save height and width on line 2
   NR<4  {next}           # ignore lines 1-3
   NR==4 {printf("P7\nWIDTH %d\nHEIGHT %d\nDEPTH 1\nMAXVAL 4095\nTUPLTYPE GRAYSCALE\nENDHDR\n", w,h);}
   1                      # pass remaining lines through unchanged' > result.pam

产生这一点:

P7
WIDTH 512
HEIGHT 512
DEPTH 1
MAXVAL 4095
TUPLTYPE GRAYSCALE
ENDHDR
65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 

I think there is a bug here in ImageMagick. This might be a workaround:

magick -depth 12 -size 512x512 gradient: -colorspace gray -compress none pgm:- | awk '
   NR==2 {w=$1; h=$2}     # pick up and save height and width on line 2
   NR<4  {next}           # ignore lines 1-3
   NR==4 {printf("P7\nWIDTH %d\nHEIGHT %d\nDEPTH 1\nMAXVAL 4095\nTUPLTYPE GRAYSCALE\nENDHDR\n", w,h);}
   1                      # pass remaining lines through unchanged' > result.pam

That produces this:

P7
WIDTH 512
HEIGHT 512
DEPTH 1
MAXVAL 4095
TUPLTYPE GRAYSCALE
ENDHDR
65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 
撩起发的微风 2025-01-26 20:43:22

在ImageMagick中,要创建文本格式NetPBM文件,请添加-compress无。

convert -depth 12 -size 512x512 xc:white -compress none white12.pam

head -7 white12.pam
P7
WIDTH 512
HEIGHT 512
DEPTH 3
MAXVAL 4095
TUPLTYPE RGB
ENDHDR

In Imagemagick, to create text format NetPBM files, add -compress none.

convert -depth 12 -size 512x512 xc:white -compress none white12.pam

head -7 white12.pam
P7
WIDTH 512
HEIGHT 512
DEPTH 3
MAXVAL 4095
TUPLTYPE RGB
ENDHDR
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文