带有ImageMagick的多个图像中的散装提取物占主导地位

发布于 2025-01-30 13:28:39 字数 590 浏览 1 评论 0原文

我想从使用ImageMagick中提取最主要的颜色的许多图像。使用此脚本:

area=$(magick *.png -format "%[fx:w*h]" info:)
magick *.png -kmeans 10 -format "%c" histogram:info:  | sed 's/://g' | awk -v area=$area '{print 100*$1/area, "%,", $3}' | sed 's/ *//g' | sort -nr -k1,1 -t ","

我可以在文件夹中的.png中获取有关颜色的大量信息,但是我看不到信息与哪个图像有关!

我还查看了此脚本:

convert *.png -gravity center -crop 1x1+0+0 -format "%f,%[fx:int(mean.r*255)],%[fx:int(mean.g*255)],%[fx:int(mean.b*255)]\n" info:

它在每个图像中心的像素上都提供了很棒的工作,但是我看不到我缺少的是获得第一个输出原始文件名的脚本和该文件中的主要颜色?我现在真的很困难,而且我敢肯定这是非常明显的!

I've a number of images that I want to extract the most dominant colors from using Imagemagick. Using this script:

area=$(magick *.png -format "%[fx:w*h]" info:)
magick *.png -kmeans 10 -format "%c" histogram:info:  | sed 's/://g' | awk -v area=$area '{print 100*$1/area, "%,", $3}' | sed 's/ *//g' | sort -nr -k1,1 -t ","

I can get a lot of information about the colors in the .pngs in my folder, but I can't see which of the images the information relates to!

I have also looked at this script:

convert *.png -gravity center -crop 1x1+0+0 -format "%f,%[fx:int(mean.r*255)],%[fx:int(mean.g*255)],%[fx:int(mean.b*255)]\n" info:

Which does a great job of giving me info on the pixel in the center of each image, but I can't see what I'm missing to get the first script to output the the original file name and the dominant colors in that file at all? I'm really stumped now, and I'm sure it's something super obvious!

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

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

发布评论

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

评论(1

回忆躺在深渊里 2025-02-06 13:28:39

我认为您将不得不在图像上写一个脚本循环,而不是在输入中使用通配符。 ImageMagick只会在列表中的第一个图像上报告。如果您使用脚本循环,则可以执行诸如Convert image.suffix -set文件名之类的事情:f“%t _%[平均值]“”%[filename:f] .suffix”。请参阅ImageMagick.org/script/escape.php

例如:

输入:

”在此处输入图像描述“

convert lena.png \
-set filename:f "%t_%[fx:round(255*mean.r)]_%[fx:round(255*mean.g)]_%[fx:round(255*mean.g)]" \
"%[filename:f].png"

结果(lena_180_99_99.png):

“在此处输入图像说明”

I think you will have to write a script loop over your images rather than using wild cards in the input. Imagemagick will only report on the first image in the list. If you use a script loop, then you can do something like convert image.suffix -set filename:f "%t_%[mean]" "%[filename:f].suffix". See imagemagick.org/script/escape.php

For example:

Input:

enter image description here

convert lena.png \
-set filename:f "%t_%[fx:round(255*mean.r)]_%[fx:round(255*mean.g)]_%[fx:round(255*mean.g)]" \
"%[filename:f].png"

Result (lena_180_99_99.png):

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文