Colour bleeding when using -layers merge

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
jules43
Posts: 11
Joined: 2015-09-01T06:14:31-07:00
Authentication code: 1151

Colour bleeding when using -layers merge

Post by jules43 »

I have a script (see below) that uses -distort SRT to rearrange and slightly scale two rectangles and then merge the two new rectangles back into one.

If I save out the cut out rectangles they appear exactly as I would expect. However, when I merge them together into one image, there is a slight colour bleed between the two rectangles, which I need to prevent some how.

The bleed appears to be a blur across the shared edge between the two images.

Can anyone tell me why the bleed is happening and suggest how to avoid it?

Thanks

Jules

Code: Select all

convert^
 -virtual-pixel horizontal-tile-edge^
 Test3072x1536.jpg^
 ^( -clone 0^
  -set option:distort:viewport "3072x1024+0+256"^
  -distort SRT "1536,768 0.9996744792,0.9990234375 0  1536,768"^
 ^)^
 ^( -clone 0^
  -set option:distort:viewport "1536x256+0+0"^
  -distort SRT "1536,128 0.4996744792,0.99609375 0  768,128"^
 ^)^
 -delete 0^
 -layers merge^
 +repage^
 TestOut.jpg
The source image I am testing this on is 3072x1536 pixels. I've shared my before and after images on dropbox at these links.

https://www.dropbox.com/s/wi23o4978nuy4 ... 2x1536.jpg
https://www.dropbox.com/s/hbrc2909g5956sc/TestOut.jpg

An example pixel that is showing the bleeding is 1240,256 which is tinted slighty orange and should be the colour of the pixel below.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Colour bleeding when using -layers merge

Post by snibgo »

With your output, and my output from your command, I see no bleeding at 1240,256 or anywhere along the join.

I am looking with Gimp, at 400% magification.
snibgo's IM pages: im.snibgo.com
jules43
Posts: 11
Joined: 2015-09-01T06:14:31-07:00
Authentication code: 1151

Re: Colour bleeding when using -layers merge

Post by jules43 »

Thank-you for coming back so quickly.

I just loaded TestOut.jpg into Paint.Net and then zoomed in on the area around 1240,256 and then took a screen shot, so you can see the individual pixels blown up. Here's the picture added to dropbox.

https://www.dropbox.com/s/6zbqb5aw4r8ec ... omedIn.png

Notice the bottom "half" is a fairly consistent brown colour and the top "half" is basically orange. The line of pixels between the two is the brown colour with a hint of orange. If I save out the bottom cut-out rectangle, the pixels in this line aren't this colour, they are the same brown as the rest.

This is a very small effect 256 pixels from the top of the image and 1240 pixels from the left side of the TestOut.

...

And in attempting to illustrate this more I've figured out what is going on. I've added a corrected version of the image here:

https://www.dropbox.com/s/u79xq1utebeh3 ... rected.png

When I first created it (as a jpg), it showed the exact same artefact when I re-opened it. However, when I saved it as an PNG it was correct (see link). If you compare the png and the original TestOut, I hope you'll see the line of pixels that changes where I indicated.

So, the problem is actually a JPEG compression artefact, causing subtle bleeding in the image. I shall switch to using a PNG for my output and see if that fixes it. I'm not quite sure why you didn't see the same problem in Gimp.

Thanks again for your help,

Jules
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Colour bleeding when using -layers merge

Post by snibgo »

That's a very small effect. I was looking for something more significant.

Why are you using JPEG? JPEG is lossy, which means it changes pixels. And it is only 8-bit/channel, so you lose precision. JPEG should never be part of an image-processing chain, especially not if you are looking at such minor effects.
snibgo's IM pages: im.snibgo.com
jules43
Posts: 11
Joined: 2015-09-01T06:14:31-07:00
Authentication code: 1151

Re: Colour bleeding when using -layers merge

Post by jules43 »

Good advice, I've learnt my lesson. I'm testing code my game renderer and hadn't expected this to be visible. Valuable lesson though as I now know my renderer is sensitive to this kind of compression artefact.

Thanks
Post Reply