Multiply image anti-aliasing problem

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?".
nagarwal
Posts: 13
Joined: 2014-11-24T04:16:09-07:00
Authentication code: 6789

Multiply image anti-aliasing problem

Post by nagarwal »

Please have a look at this question http://stackoverflow.com/questions/2709 ... i-aliasing

Need help urgent.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Multiply image anti-aliasing problem

Post by fmw42 »

try the following (unix syntax):

Code: Select all

convert c5VyQ.png -morphology open octagon:3 \
-fuzz 10% -transparent white \
-fill "rgba(103,68,56,5)" +opaque none \
result.png



If you want to anti-alias the boundary, then try this

Code: Select all

convert c5VyQ.png -morphology open octagon:3 \
-fuzz 10% -transparent white \
-background "rgba(103,68,56,5)" -alpha background \
-fill "rgba(103,68,56,5)" +opaque none \
\( -clone 0 -alpha extract -blur 0x2 -level 50x100% \) \
-alpha off -compose copy_opacity -composite \
result2.png
nagarwal
Posts: 13
Joined: 2014-11-24T04:16:09-07:00
Authentication code: 6789

Re: Multiply image anti-aliasing problem

Post by nagarwal »

This is not the desired result. The flow required is as shown in the image, can you please have a look at it? and suggest right approach.

Image

orignal alpha image of the mortar I have is:

Image


Original brick image I have is.

Image

My imagemagick version is Version: ImageMagick 6.5.4-7 2014-02-10 Q16.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Multiply image anti-aliasing problem

Post by fmw42 »

Please provide all the components as separate image at the same scale. This includes the material image, the gray brick image and if you have a mask, then provide that. If the mask is created from the material image, then let us know that.

It looks line you want to take the material image, extract one row, then make a mask for the border, then put the gray brick image in the border, then recolor the gray brick image. Is that correct? If not, then please describe in more detail what you want. It is hard to know from just your diagrams.

The material image and the gray brick pattern seem to be the key image and you did not provide either previously and still not the material image for filling the inside areas.

If you provide one question that does not explain your real issue and then we reply and you change the problem, then that is very confusing.
nagarwal
Posts: 13
Joined: 2014-11-24T04:16:09-07:00
Authentication code: 6789

Re: Multiply image anti-aliasing problem

Post by nagarwal »

It looks line you want to take the material image, extract one row, then make a mask for the border, then put the gray brick image in the border, then recolor the gray brick image. Is that correct?

Yes, this is correct and that is all I have as Input.

I multiply different RGBA values into that grey area of the image for example (103,68,56,5).

The material image is

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Multiply image anti-aliasing problem

Post by fmw42 »

How can anyone do what you suggest by your diagrams without the red brick pattern? I am very confused. What should the final image look like? What about the border image and also the interior red brick image.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Multiply image anti-aliasing problem

Post by snibgo »

Maybe it works like this. I take the top third of 4Biet.png as a mask for bricks/mortar, and the middle third as texture for mortar. Windows BAT script:

Code: Select all

convert ^
  4Biet.png ^
  -crop 1x3@ +repage ^
  b.png

convert ^
  ( b-1.png -fill rgb(100%%,75%%,30%%) -colorize 50 +write bf.png ) ^
  ( pK1xB.jpg -fill rgb(100%%,40%%,30%%) -colorize 50 +write bb.png ) ^
  b-0.png ^
  -composite ^
  -gravity center -crop 1000x+0+0 +repage ^
  bricks.png
I have ignored the bottom third of 4Biet.png, and cropped the output.
Image
EDIT: "+write bf.png" and "+write bb.png" are just to show what is happening, and to help you adjust the two colours to your taste.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Multiply image anti-aliasing problem

Post by fmw42 »

I also want to point out that there is no such color as "rgba(103,68,56,5)". Alpha values are specified in the range 0 to 1. So I am not sure whether you meant alpha=0.5 or were trying to get alpha as 5/255 = 0.02

Furthermore, you did not say why my two sets of code did not satisfy the example from the link you mentioned. Without some good feedback we do not know what you are trying to do and can only guess as user snibgo tried to do.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Multiply image anti-aliasing problem

Post by fmw42 »

Here is an alternate attempt to guess what you want.

unix syntax

I left the -write show: in so you can see each step

Code: Select all

convert c5VyQ.png pK1xB.jpg \
\( -clone 0 +level-colors "black,#B6977A" -write show: \) \
\( -clone 0 -morphology open octagon:3 \
-fuzz 10% -transparent white -channel rgba \
-fill "rgba(255,255,255,1)" +opaque none -fill "rgba(0,0,0,1)" -opaque none -write show: \
-blur 0x2 -level 0x50% -write show: \) \
-delete 0 -compose over -composite result.jpg
Image

The above colorizes the grout/mortar area (actually the whole first image c5VyQ.png) with #B6977A (taken from your diagram). Then it creates a mask. Then it composites the gray texture image you provided pK1xB.jpg with the colorized image using the mask, so the gray texture is in the center and colorized grout/mortar region is outside.

Here are some alternates where I tried to colorize the gray texture image with the red brick color you specified.


# use +level-colors to colorize

Code: Select all

convert c5VyQ.png \( pK1xB.jpg +level-colors "black,rgb(103,68,56)" -write show: \) \
\( -clone 0 +level-colors "black,#B6977A" -write show: \) \
\( -clone 0 -morphology open octagon:3 \
-fuzz 10% -transparent white -channel rgba \
-fill "rgba(255,255,255,1)" +opaque none -fill "rgba(0,0,0,1)" -opaque none -write show: \
-blur 0x2 -level 0x50% -write show: \) \
-delete 0 -compose over -composite result2.jpg
Image

# use -colorize 85% to colorize

Code: Select all

convert c5VyQ.png \( pK1xB.jpg -colorspace gray -fill "rgb(103,68,56)" -colorize 85% -write show: \) \
\( -clone 0 +level-colors "black,#B6977A" -write show: \) \
\( -clone 0 -morphology open octagon:3 \
-fuzz 10% -transparent white -channel rgba \
-fill "rgba(255,255,255,1)" +opaque none -fill "rgba(0,0,0,1)" -opaque none -write show: \
-blur 0x2 -level 0x50% -write show: \) \
-delete 0 -compose over -composite result3.jpg
Image

# use -colorize 90% to colorize

Code: Select all

convert c5VyQ.png \( pK1xB.jpg -colorspace gray -fill "rgb(103,68,56)" -colorize 90% -write show: \) \
\( -clone 0 +level-colors "black,#B6977A" -write show: \) \
\( -clone 0 -morphology open octagon:3 \
-fuzz 10% -transparent white -channel rgba \
-fill "rgba(255,255,255,1)" +opaque none -fill "rgba(0,0,0,1)" -opaque none -write show: \
-blur 0x2 -level 0x50% -write show: \) \
-delete 0 -compose over -composite result4.jpg
Image
nagarwal
Posts: 13
Joined: 2014-11-24T04:16:09-07:00
Authentication code: 6789

Re: Multiply image anti-aliasing problem

Post by nagarwal »

fmw42 wrote:Here is an alternate attempt to guess what you want.

unix syntax

I left the -write show: in so you can see each step

Code: Select all

convert c5VyQ.png pK1xB.jpg \
\( -clone 0 +level-colors "black,#B6977A" -write show: \) \
\( -clone 0 -morphology open octagon:3 \
-fuzz 10% -transparent white -channel rgba \
-fill "rgba(255,255,255,1)" +opaque none -fill "rgba(0,0,0,1)" -opaque none -write show: \
-blur 0x2 -level 0x50% -write show: \) \
-delete 0 -compose over -composite result.jpg
Image

The above colorizes the grout/mortar area (actually the whole first image c5VyQ.png) with #B6977A (taken from your diagram). Then it creates a mask. Then it composites the gray texture image you provided pK1xB.jpg with the colorized image using the mask, so the gray texture is in the center and colorized grout/mortar region is outside.

Here are some alternates where I tried to colorize the gray texture image with the red brick color you specified.


# use +level-colors to colorize

Code: Select all

convert c5VyQ.png \( pK1xB.jpg +level-colors "black,rgb(103,68,56)" -write show: \) \
\( -clone 0 +level-colors "black,#B6977A" -write show: \) \
\( -clone 0 -morphology open octagon:3 \
-fuzz 10% -transparent white -channel rgba \
-fill "rgba(255,255,255,1)" +opaque none -fill "rgba(0,0,0,1)" -opaque none -write show: \
-blur 0x2 -level 0x50% -write show: \) \
-delete 0 -compose over -composite result2.jpg
Image

# use -colorize 85% to colorize

Code: Select all

convert c5VyQ.png \( pK1xB.jpg -colorspace gray -fill "rgb(103,68,56)" -colorize 85% -write show: \) \
\( -clone 0 +level-colors "black,#B6977A" -write show: \) \
\( -clone 0 -morphology open octagon:3 \
-fuzz 10% -transparent white -channel rgba \
-fill "rgba(255,255,255,1)" +opaque none -fill "rgba(0,0,0,1)" -opaque none -write show: \
-blur 0x2 -level 0x50% -write show: \) \
-delete 0 -compose over -composite result3.jpg
Image

# use -colorize 90% to colorize

Code: Select all

convert c5VyQ.png \( pK1xB.jpg -colorspace gray -fill "rgb(103,68,56)" -colorize 90% -write show: \) \
\( -clone 0 +level-colors "black,#B6977A" -write show: \) \
\( -clone 0 -morphology open octagon:3 \
-fuzz 10% -transparent white -channel rgba \
-fill "rgba(255,255,255,1)" +opaque none -fill "rgba(0,0,0,1)" -opaque none -write show: \
-blur 0x2 -level 0x50% -write show: \) \
-delete 0 -compose over -composite result4.jpg
Image

I am sorry for being not so clear in my question. The fist image very close to what I need: Image. The only problem is, it has some blur in it. below is image of the actual output.Image
this is the kind of result is needed. Also we need to make that material part transparent in the final image so that different materials can fit in the background. Thank you a lot for all the effort you have put in.

the material used in actual output is:
Image

the mortar is:
Image
Last edited by nagarwal on 2014-11-25T23:11:06-07:00, edited 1 time in total.
nagarwal
Posts: 13
Joined: 2014-11-24T04:16:09-07:00
Authentication code: 6789

Re: Multiply image anti-aliasing problem

Post by nagarwal »

snibgo wrote:Maybe it works like this. I take the top third of 4Biet.png as a mask for bricks/mortar, and the middle third as texture for mortar. Windows BAT script:

Code: Select all

convert ^
  4Biet.png ^
  -crop 1x3@ +repage ^
  b.png

convert ^
  ( b-1.png -fill rgb(100%%,75%%,30%%) -colorize 50 +write bf.png ) ^
  ( pK1xB.jpg -fill rgb(100%%,40%%,30%%) -colorize 50 +write bb.png ) ^
  b-0.png ^
  -composite ^
  -gravity center -crop 1000x+0+0 +repage ^
  bricks.png
I have ignored the bottom third of 4Biet.png, and cropped the output.
Image
EDIT: "+write bf.png" and "+write bb.png" are just to show what is happening, and to help you adjust the two colours to your taste.
this is close to the result I needed but it has some blur in it. can we make the material part transparent so that different materials can be fit in the background on the fly?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Multiply image anti-aliasing problem

Post by fmw42 »

Blur was only used to anti-alias the edges of the mask image. If you do not want it, just remove the -blur -level

Code: Select all

convert c5VyQ.png pK1xB.jpg \
\( -clone 0 +level-colors "black,#B6977A" -write show: \) \
\( -clone 0 -morphology open octagon:3 \
-fuzz 10% -transparent white -channel rgba \
-fill "rgba(255,255,255,1)" +opaque none -fill "rgba(0,0,0,1)" -opaque none -write show: \) \
-delete 0 -compose over -composite result5.jpg
Image

That is the best I can do to help. Sorry, but you keep changing the images and it is getting very confusing and frustrating. If you want to do it to a different image, this should be all you need.
nagarwal
Posts: 13
Joined: 2014-11-24T04:16:09-07:00
Authentication code: 6789

Re: Multiply image anti-aliasing problem

Post by nagarwal »

fmw42 wrote:Blur was only used to anti-alias the edges of the mask image. If you do not want it, just remove the -blur -level

Code: Select all

convert c5VyQ.png pK1xB.jpg \
\( -clone 0 +level-colors "black,#B6977A" -write show: \) \
\( -clone 0 -morphology open octagon:3 \
-fuzz 10% -transparent white -channel rgba \
-fill "rgba(255,255,255,1)" +opaque none -fill "rgba(0,0,0,1)" -opaque none -write show: \) \
-delete 0 -compose over -composite result5.jpg
Image

That is the best I can do to help. Sorry, but you keep changing the images and it is getting very confusing and frustrating. If you want to do it to a different image, this should be all you need.
I am really sorry about that, but these are just different kind of mortar and material image and luckily your solution works for all the mortars and materials. Thanks for all the help, I appreciate all your efforts. Please help with one last thing. I need to set the material part transparent in the final image .
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Multiply image anti-aliasing problem

Post by fmw42 »

How can my result and snibgo's both be what you want. They are totally different. I did not recolor the gray texture in the middle parts in the example you said you liked (my others were recolored). At the same time you say snigbo's is what you want and his is recolored.
nagarwal
Posts: 13
Joined: 2014-11-24T04:16:09-07:00
Authentication code: 6789

Re: Multiply image anti-aliasing problem

Post by nagarwal »

fmw42 wrote:How can my result and snibgo's both be what you want. They are totally different. I did not recolor the gray texture in the middle parts in the example you said you liked (my others were recolored). At the same time you say snigbo's is what you want and his is recolored.
I was looking at the resultant output and If you see the both the output and the resultant output needed Image they both appeared to be somewhat closer. Whether we color it or not if can get the output same as shown above and keep the material part transparent in the final image then we are good.
Post Reply