Page 1 of 1

Spread and image with opacity

Posted: 2015-12-22T08:14:24-07:00
by excel
There is image.png with opacity.


Image

How to use -virtual-pixel white -spread and get this spread_image.png with opacity?

Image

The sample (spread_image.png) is not very nice, I tried to do it in Photoshop


Is it possible to do a similar actions with -raise (+raise) ?

Re: Spread and image with opacity

Posted: 2015-12-22T08:33:11-07:00
by Bonzo
Not quite sure what you are after but there may be an example of what you want here: http://www.imagemagick.org/Usage/thumbnails/

Re: Spread and image with opacity

Posted: 2015-12-22T11:25:18-07:00
by fmw42
try this (unix syntax)

Code: Select all

convert image.png \
\( -clone 0 -virtual-pixel white -spread 15 -blur 0x0.5 \) \
\( -clone 0 -alpha extract -virtual-pixel black -morphology erode diamond:15 -negate \) \
\( -clone 0-2 -compose over -composite \) \
-delete 1,2 \
\( -clone 0 -alpha extract \) \
-delete 0 \
 -alpha off -compose copy_opacity -composite result.png 

Re: Spread and image with opacity

Posted: 2015-12-22T12:40:37-07:00
by excel
fmw42 wrote:try this (unix syntax)

Code: Select all

convert image.png \
\( -clone 0 -virtual-pixel white -spread 15 -blur 0x0.5 \) \
\( -clone 0 -alpha extract -virtual-pixel black -morphology erode diamond:15 -negate \) \
\( -clone 0-2 -compose over -composite \) \
-delete 1,2 \
\( -clone 0 -alpha extract \) \
-delete 0 \
 -alpha off -compose copy_opacity -composite result.png 


Hello, fmw42!
I placed a blue background to see white pixels

Your result has not white pixels at the bottom of inclined lines:


Image


It's my variant but need to lay the white pixels in the inclined lines

Code: Select all

convert -size 300x226 xc:none -background transparent -virtual-pixel white -spread 15 +write mpr:spread1 \
	\( image.png mpr:spread1 -composite +write result.png \)
Image

Re: Spread and image with opacity

Posted: 2015-12-22T14:39:26-07:00
by fmw42
try this:

Code: Select all

convert image.png \
\( -clone 0 -alpha off -virtual-pixel white -spread 15 -blur 0x0.5 \) \
\( -clone 0 -alpha extract -virtual-pixel black -morphology erode diamond:15 -negate \) \
\( -clone 0-2 -compose over -composite \) \
-delete 1,2 \
\( -clone 0 -alpha extract \) \
-delete 0 \
 -alpha off -compose copy_opacity -composite result.png 
You can leave out the -blur if you don't want the spread softened.


This should be slightly more efficient:

Code: Select all

convert image.png -write mpr:img \
\( mpr:img -alpha off -virtual-pixel white -spread 15 \) \
\( mpr:img -alpha extract -virtual-pixel black -morphology erode diamond:15 \) \
-swap 0,1 -compose over -composite \
\( mpr:img -alpha extract \) \
 -alpha off -compose copy_opacity -composite result.png

Re: Spread and image with opacity

Posted: 2015-12-22T19:13:47-07:00
by excel
fmw42 wrote:try this:

Code: Select all

convert image.png -write mpr:img \
\( mpr:img -alpha off -virtual-pixel white -spread 15 \) \
\( mpr:img -alpha extract -virtual-pixel black -morphology erode diamond:15 \) \
-swap 0,1 -compose over -composite \
\( mpr:img -alpha extract \) \
 -alpha off -compose copy_opacity -composite result.png


I have a question.
Why this image has some black pixels?
On the top of image and on the grass.

Image


Image

Re: Spread and image with opacity

Posted: 2015-12-22T19:18:46-07:00
by fmw42
The top is from the spread from her hair

Re: Spread and image with opacity

Posted: 2015-12-22T19:24:14-07:00
by fmw42
The two different input images you have provide have different colors in the transparent area. The first one was white and this one is black.

Look at:

Code: Select all

convert image.png -alpha off tmp1.png
convert black_pix.png -alpha off tmp2.png
This will replace the black in the second image with white and make the bottom spread white. Note that -virtual-pixel white only affects the area near the real border of the image (not where the image is transparent).

Code: Select all

 convert black_pix.png -background white -alpha background -write mpr:img \
\( mpr:img -alpha off -alpha off -virtual-pixel white -spread 15 \) \
\( mpr:img -alpha extract -virtual-pixel black -morphology erode diamond:15 \) \
-swap 0,1 -compose over -composite \
\( mpr:img -alpha extract \) \
 -alpha off -compose copy_opacity -composite result2.png
It does not change the top, since the black is her hair.

Re: Spread and image with opacity

Posted: 2015-12-23T10:08:36-07:00
by excel
fmw42 wrote:The two different input images you have provide have different colors in the transparent area. The first one was white and this one is black.

It does not change the top, since the black is her hair.

Can we do it in a few steps for a perfect white pixels?
May be several exec-commands?

Image

Re: Spread and image with opacity

Posted: 2015-12-23T10:27:41-07:00
by fmw42
try this

Code: Select all

convert black_pix.png -write mpr:img \
\( mpr:img -alpha off -fill white -colorize 100% -alpha on -write mpr:img2 \) \
+swap \
\( mpr:img2 -virtual-pixel none -spread 15 \) \
-compose over -composite result.png

Re: Spread and image with opacity

Posted: 2015-12-23T17:48:40-07:00
by excel
fmw42 wrote:try this

Code: Select all

convert black_pix.png -write mpr:img \
\( mpr:img -alpha off -fill white -colorize 100% -alpha on -write mpr:img2 \) \
+swap \
\( mpr:img2 -virtual-pixel none -spread 15 \) \
-compose over -composite result.png

It's OK! Thank You!