sh 删除/剥离图像背景 - 粗略模式 - 需要ImageMagick

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 删除/剥离图像背景 - 粗略模式 - 需要ImageMagick相关的知识,希望对你有一定的参考价值。

# Requires ImageMagick


# Converting the source from JPEG to PNG - if necessary
convert my_src_image.jpg my_src_image.png


# Option A
#  - Requires a temporary intermediate file
#  - Drill more than 10 might result in poor results
DRILL=5
convert my_src_image.png \( +clone -fx "p{0,0}" \) -compose Difference -composite -modulate 100,0  +matte temp_image_xzy.png
convert temp_image_xzy.png -bordercolor white -border 1x1 -matte -fill none -fuzz $DRILL% -draw "matte 1,1 floodfill" -shave 1x1 temp_image_xzy.png
convert temp_image_xzy.png -channel matte -separate +matte temp_image_xzy.png
convert temp_image_xzy.png -negate -blur 0x1 temp_image_xzy.png
composite -compose CopyOpacity temp_image_xzy.png my_src_image.png final_image_option_A.png

# Remove the temp file 
rm -f temp_image_xzy.png

# below instruction is optional
composite -compose Dst_Over -tile pattern:checkerboard final_image_option_A.png final_image_option_A_check.png

# //End of Option A



# Option B
#  - Requires a temporary intermediate file
#  - Drill more than 10 might result in poor results
DRILL=5
convert my_src_image.png \( +clone -fx "p{0,0}" \) -compose Difference -composite -modulate 100,0 +matte temp_image_xzy.png
convert -fuzz $DRILL% -transparent black temp_image_xzy.png temp_image_xzy.png
convert temp_image_xzy.png -channel matte -separate +matte temp_image_xzy.png
convert temp_image_xzy.png -negate -blur 0x1 temp_image_xzy.png
composite -compose CopyOpacity temp_image_xzy.png my_src_image.png final_image_option_B.png

# Remove the temp file 
rm -f temp_image_xzy.png

# below instruction is optional
composite -compose Dst_Over -tile pattern:checkerboard final_image_option_B.png final_image_option_B_check.png

# //End of Option B



# Option C
#  - Drill more than 10 might result in poor results
DRILL=5
convert my_src_image.png -bordercolor white -border 1x1 -matte -fill none -fuzz $DRILL% -draw "matte 1,1 floodfill" -shave 1x1 final_image_option_C.png

# below instruction is optional
composite -compose Dst_Over -tile pattern:checkerboard final_image_option_C.png final_image_option_C_check.png

# //End of Option C



# Option D
#  - Drill more than 10 might result in poor results
DRILL=5
convert -fuzz $DRILL% -transparent white my_src_image.png final_image_option_D.png

# below instruction is optional
composite -compose Dst_Over -tile pattern:checkerboard final_image_option_D.png final_image_option_D_check.png

# //End of Option D

以上是关于sh 删除/剥离图像背景 - 粗略模式 - 需要ImageMagick的主要内容,如果未能解决你的问题,请参考以下文章

剥离 pdb 的路径

sh 在TAR剥离路径

sh [ssh-copy-id和ssh组合]这是一个粗略的脚本,如果需要,它会将本地ID密钥添加到客户端的授权密钥。

从图像中删除黑色背景。

sh 透明图像背景imagemagic cli转换

sh 用于导出magento 2数据库的Bash脚本 - 剥离的销售数据