Newbie needs help with "color splash" using Python

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ram
Posts: 5
Joined: 2019-10-16T16:35:25+00:00
Authentication code: 1152

Newbie needs help with "color splash" using Python

Post 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:

Image

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
snibgo
Posts: 12159
Joined: 2010-01-24T06:01:33+00:00
Authentication code: 1151
Location: England, UK

Re: Newbie needs help with "color splash" using Python

Post by snibgo »

You have omitted the parentheses ( and ).
snibgo's IM pages: im.snibgo.com
ram
Posts: 5
Joined: 2019-10-16T16:35:25+00:00
Authentication code: 1152

Re: Newbie needs help with "color splash" using Python

Post 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"
Image

output file "all_blue_colors.png"
Image

my goal is to make the other pixel in gray scale color instead of transparent, can you pls help me with this?
ram
Posts: 5
Joined: 2019-10-16T16:35:25+00:00
Authentication code: 1152

Re: Newbie needs help with "color splash" using Python

Post by ram »

snibgo wrote: 2019-10-17T11:55:45+00:00 You have omitted the parentheses ( and ).
thx much!!
snibgo
Posts: 12159
Joined: 2010-01-24T06:01:33+00:00
Authentication code: 1151
Location: England, UK

Re: Newbie needs help with "color splash" using Python

Post 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.
snibgo's IM pages: im.snibgo.com
ram
Posts: 5
Joined: 2019-10-16T16:35:25+00:00
Authentication code: 1152

Re: Newbie needs help with "color splash" using Python

Post by ram »

snibgo wrote: 2019-10-17T12:25:18+00: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?
snibgo
Posts: 12159
Joined: 2010-01-24T06:01:33+00:00
Authentication code: 1151
Location: England, UK

Re: Newbie needs help with "color splash" using Python

Post 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
snibgo's IM pages: im.snibgo.com
ram
Posts: 5
Joined: 2019-10-16T16:35:25+00:00
Authentication code: 1152

Re: Newbie needs help with "color splash" using Python

Post by ram »

snibgo wrote: 2019-10-17T14:37:31+00: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)
Post Reply