I'd like to create custom filter

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
lojesus75
Posts: 9
Joined: 2017-02-01T19:50:50-07:00
Authentication code: 1151

I'd like to create custom filter

Post by lojesus75 »

Imagemagick is the best for effecting images or creating filters.

I am testing new filter functions using Image Magic.

Change the color RGB image to GrayScale and change the Pixel Point value of the GrayScaled image to the Opacity value.

And finally, I want to change all the colors to black while maintaining the Opacity value.

In short

1. Convert RGB -> GrayScale
2. Convert GrayScale Image Pixel Value to Opacity Value
3. Convert GrayScale Color to Black Color (Keep Transparency)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: I'd like to create custom filter

Post by fmw42 »

What is your IM version and platform/OS? Please always provide that since syntax differs. Here is the command line code if you want the output to be grayscale with transparency.

Code: Select all

convert rgbimage -colorspace gray -alpha copy -background black -alpha background transparentgrayimage.png
The output cannot be jpg because it does not support transparency. GIF only provides binary (on/off) transparency. So for 8-bit transparency, you should use either PNG or TIFF. You can start with any color image format, even jpg. So I did not put the suffix on the input, but you need to add whatever format suffix corresponds to your actual image.

If you want to keep the image as color and put the grayscale version in the alpha channel, then do the following (unix syntax)

Code: Select all

convert rgbimage \( -clone 0 -colorspace gray \) -alpha off -compose copy_opacity -composite -background black -alpha background transparentcolorimage.png
See
http://www.imagemagick.org/Usage/masking/


Sorry, I do not know how to do this in any API such as Magickwand.
lojesus75
Posts: 9
Joined: 2017-02-01T19:50:50-07:00
Authentication code: 1151

Re: I'd like to create custom filter

Post by lojesus75 »

Thank you for quick response.

The current operating system is Windows-based, and the -clone command of the current command does not work
not.

When you run the command

Error Message

C:\work>convert rgbimage.png -colorspace Gray -alpha off -compose copy_opacity -
composite -background black -alpha background mask_1.png
convert.exe: no images defined `mask_1.png' @ error/convert.c/ConvertImageComman
d/3241.

-----------------------------------------------------

And to help you get a better understanding


There is no Alpha value in the original file
I want to implement Opacity using color value.

If the K value is 20 then Opacity 20, K value is 100 then Opacity 100, and K value is 5 then Opacity 5 should be treated as GrayScale.

Please check and answer.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: I'd like to create custom filter

Post by fmw42 »

What version of IM are you using? Are you running IM convert.exe or Windows convert.exe? If you IM version is too old, then -alpha may not have been defined. That is why I keep asking what your IM verison is.

I do not see any clone command in the command line you ran and provided above with the mask_1.png error.

In windows \( ... \) become ( ... ) (remove the \). That is why I asked what your OS was, since syntax is different. See http://www.imagemagick.org/Usage/windows/
lojesus75
Posts: 9
Joined: 2017-02-01T19:50:50-07:00
Authentication code: 1151

Re: I'd like to create custom filter

Post by lojesus75 »

First, we processed the instruction as given, and we confirmed that the instruction was working.

Command Execution

C:\work>convert rgbimage.png -clone 0 -colorspace Gray -alpha off -compose copy_
opacity -composite -background black -alpha background mask_1.png

===============================================

What I want is to reflect the transparency using the color values of the original file.

For example, if K is 30 then Opacity is 70 and if K is 100 then Opacity is 0.
Since the original file does not have transparency, I want to create transparency using the K value.

Please check one more time.

And I am grateful for this interest.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: I'd like to create custom filter

Post by fmw42 »

convert rgbimage.png -clone 0 -colorspace Gray -alpha off -compose copy_opacity -composite -background black -alpha background mask_1.png
You cannot have clones without parentheses. Window syntax makes the grayscale image as the alpha channel with reverse values and puts it into the color image as its alpha channel. Be sure convert.exe is the IM convert.exe and not the Windows convert.exe.

Code: Select all

convert.exe rgbimage.png ( -clone 0 -colorspace Gray -negate ) -alpha off -compose copy_opacity -composite -background black -alpha background result.png
But I am not sure I understand if this is really what you want as the result. Your original steps suggested you wanted a grayscale result with an alpha channel the same as the grayscale image.
1. Convert RGB -> GrayScale
2. Convert GrayScale Image Pixel Value to Opacity Value
3. Convert GrayScale Color to Black Color (Keep Transparency)
If this is what you want, then

Code: Select all

convert.exe  ( rgbimage.png -colorspace Gray ) ( -clone 0 -negate )  -alpha off -compose copy_opacity -composite -background black -alpha background result.png

Please clarify what you want and provide your IM version.
lojesus75
Posts: 9
Joined: 2017-02-01T19:50:50-07:00
Authentication code: 1151

Re: I'd like to create custom filter

Post by lojesus75 »

Hello fmw42~

I was able to solve the problem I was trying to solve with the command you gave me.

Thank you again.
Post Reply