Page 1 of 1
Newbie needs help with "color splash" using Python
Posted: 2019-10-17T02:21:35-07:00
by ram
Hello,
I'm a Newbie trying to create "color-spotting" or "color splash" based on
this post using Python on RaspbianGNU/Linux10(buster), the image below shows the wanted result which is convert an image to gray-scale color except
one color:
the code I'm running is:
Code: Select all
import subprocess
imageMagicCmd = ["sudo", "/usr/bin/convert", "/home/pi/Desktop/imageMagicTest/1.jpg", "-matte", "+clone", "-fuzz", "30%", "-transparent", "blue", "-compose", "DstOut", "-composite", "/home/pi/Desktop/imageMagicTest/all_blue_colors.png"]
subprocess.call(imageMagicCmd)
however the result is an empty file... obviously i'm missing something in the syntax here which i don't know what, any thoughts will be highly appreciated!
many thanks in advance,
Ram
Re: Newbie needs help with "color splash" using Python
Posted: 2019-10-17T04:55:45-07:00
by snibgo
You have omitted the parentheses ( and ).
Re: Newbie needs help with "color splash" using Python
Posted: 2019-10-17T04:57:13-07:00
by ram
so I've got some progress with the syntax, i get to create an output image but now I see that it doesnt do what i need, the current convert command changes every none blue pixel to transparent:
Code: Select all
import subprocess
imageMagicCmd = ["sudo", "/usr/bin/convert", "/home/pi/Desktop/imageMagicTest/colorWheel.png", "-matte", "(", "+clone", "-fuzz", "30%", "-transparent", "blue",")", "-compose", "DstOut", "-composite", "/home/pi/Desktop/imageMagicTest/all_blue_colors.png"]
subprocess.call(imageMagicCmd)]
input file "colorWheel.png"
output file "all_blue_colors.png"
my goal is to make the other pixel in gray scale color instead of transparent, can you pls help me with this?
Re: Newbie needs help with "color splash" using Python
Posted: 2019-10-17T04:57:49-07:00
by ram
snibgo wrote: ↑2019-10-17T04:55:45-07:00
You have omitted the parentheses ( and ).
thx much!!
Re: Newbie needs help with "color splash" using Python
Posted: 2019-10-17T05:25:18-07:00
by snibgo
ram wrote:my goal is to make the other pixel in gray scale color instead of transparent,...
Make a monochrome version of the input, eg with "-colorspace Gray". Compose the all_blue_colors.png over that monochrome image.
Re: Newbie needs help with "color splash" using Python
Posted: 2019-10-17T07:01:01-07:00
by ram
snibgo wrote: ↑2019-10-17T05:25:18-07:00
ram wrote:my goal is to make the other pixel in gray scale color instead of transparent,...
Make a monochrome version of the input, eg with "-colorspace Gray". Compose the all_blue_colors.png over that monochrome image.
super! it works great!
currently I have three different calls (1. create transparent, 2. create gray scale and 3. compose the two), is there a way to make it in one call?
Re: Newbie needs help with "color splash" using Python
Posted: 2019-10-17T07:37:31-07:00
by snibgo
I don't use Python. A command line could be (Windows BAT syntax):
Code: Select all
convert ^
colorWheel.png +write mpr:INPT ^
-alpha Set ^
( +clone -fuzz 30%% -transparent Blue ) ^
-compose DstOut -composite ^
( mpr:INPT -colorspace Gray ) ^
+swap ^
-compose Over -composite ^
out.png
Re: Newbie needs help with "color splash" using Python
Posted: 2019-10-17T10:07:18-07:00
by ram
snibgo wrote: ↑2019-10-17T07:37:31-07:00
I don't use Python. A command line could be (Windows BAT syntax):
Code: Select all
convert ^
colorWheel.png +write mpr:INPT ^
-alpha Set ^
( +clone -fuzz 30%% -transparent Blue ) ^
-compose DstOut -composite ^
( mpr:INPT -colorspace Gray ) ^
+swap ^
-compose Over -composite ^
out.png
Awesome!!! many many thanks mate!!!
for anyone who's using Python, this works for me:
Code: Select all
import subprocess
imageMagicCmd = ["sudo", "/usr/bin/convert", "/home/pi/Desktop/imageMagicTest/1.jpg", "+write", "mpr:INPT", "-alpha", "Set", "(", "+clone", "-fuzz", "50%", "-transparent", "blue",")", "-compose", "DstOut", "-composite", "(", "mpr:INPT", "-colorspace", "Gray", ")", "+swap", "-compose", "Over", "-composite", "/home/pi/Desktop/imageMagicTest/out.png"]
subprocess.call(imageMagicCmd)