在Imagemagick 6中,可以执行以下操作列出两幅图像不同的坐标:
convert image1 image2 -compose difference -composite -threshold 0 txt: | tail -n +2 | grep "white" | awk '{print $1}' | sed 's/://g'
如果使用Imagemagick 7,请将convert更改为magick
如果需要两个图像中的一个同时包含坐标和颜色,则假设该图像没有完美的黑色像素,可以执行以下操作:
convert image1 image2 \
\( -clone 0,1 -compose difference -composite -threshold 0 \) \
-delete 1 \
-compose multiply -composite txt: |\
tail -n +2 | grep -v "black" | awk '{print $1,$4}'
例如,我取lena图像,在左上角放置一个蓝色正方形来生成第二个图像。
输入:
convert lena.png \( -clone 0 -size 5x5 xc:blue -composite \) \
\( -clone 0,1 -compose difference -composite -threshold 0 \) \
-delete 1 \
-compose multiply -composite txt: |\
tail -n +2 | grep -v "black" | awk '{print $1,$4}'
结果:
0,0: srgb(226,137,124)
1,0: srgb(224,137,130)
2,0: srgb(225,135,121)
3,0: srgb(228,134,121)
4,0: srgb(227,138,125)
0,1: srgb(226,137,124)
1,1: srgb(224,137,131)
2,1: srgb(225,135,121)
3,1: srgb(228,134,121)
4,1: srgb(227,138,126)
0,2: srgb(226,138,124)
1,2: srgb(224,136,127)
2,2: srgb(225,135,120)
3,2: srgb(228,134,121)
4,2: srgb(227,137,121)
0,3: srgb(228,137,122)
1,3: srgb(225,134,114)
2,3: srgb(225,134,118)
3,3: srgb(229,132,112)
4,3: srgb(227,133,113)
0,4: srgb(224,130,109)
1,4: srgb(223,132,110)
2,4: srgb(224,132,116)
3,4: srgb(226,131,112)
4,4: srgb(226,134,117)
convert image1 image2 \
\( -clone 0,1 -compose difference -composite -threshold 0 \) \
-delete 1 \
-alpha off -compose copy_opacity -composite \
-background black -alpha background txt: |\
tail -n +2 | grep -v "none" | awk '{print $1,$4}'
例如:
convert lena.png \( -clone 0 -size 5x5 xc:blue -composite \) \
\( -clone 0,1 -compose difference -composite -threshold 0 \) \
-delete 1 \
-alpha off -compose copy_opacity -composite \
-background black -alpha background txt: |\
tail -n +2 | grep -v "none" | awk '{print $1,$4}'
结果:
0,0: srgba(226,137,124,1)
1,0: srgba(224,137,130,1)
2,0: srgba(225,135,121,1)
3,0: srgba(228,134,121,1)
4,0: srgba(227,138,125,1)
0,1: srgba(226,137,124,1)
1,1: srgba(224,137,131,1)
2,1: srgba(225,135,121,1)
3,1: srgba(228,134,121,1)
4,1: srgba(227,138,126,1)
0,2: srgba(226,138,124,1)
1,2: srgba(224,136,127,1)
2,2: srgba(225,135,120,1)
3,2: srgba(228,134,121,1)
4,2: srgba(227,137,121,1)
0,3: srgba(228,137,122,1)
1,3: srgba(225,134,114,1)
2,3: srgba(225,134,118,1)
3,3: srgba(229,132,112,1)
4,3: srgba(227,133,113,1)
0,4: srgba(224,130,109,1)
1,4: srgba(223,132,110,1)
2,4: srgba(224,132,116,1)
3,4: srgba(226,131,112,1)
4,4: srgba(226,134,117,1)