Batch Replace Color Produces Pixelated Colors

Ask for help and post your question on how to use XnView Classic.

Moderators: helmut, XnTriq, xnview

jpeni
Posts: 5
Joined: Fri Apr 11, 2008 10:16 pm
Location: Uniondale, NY, USA

Batch Replace Color Produces Pixelated Colors

Post by jpeni »

I am trying to batch convert a collection of black symbols in .PNG (32bit RGB) images.

I select Batch Processing and add the Replace Color Transformations option.
I select the original color and the replacement color and click Go.
The images process, but the replacement color is pixelated - not smooth.

Image


What am I doing wrong?

JPeni
User avatar
DOS386
Posts: 291
Joined: Sun Jun 11, 2006 2:43 pm

Re: Batch Replace Color Produces Pixelated Colors

Post by DOS386 »

jpeni wrote:I am trying to batch convert a collection of black symbols in .PNG (32bit RGB) images.

What am I doing wrong?
Please upload the original Corpus Delicti in PNG format. Let me guess that it has more than 1 black colour?
There is indeed no WinZIP under my rock.
cday
XnThusiast
Posts: 3296
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Batch Replace Color Produces Pixelated Colors

Post by cday »

DOS386's explanation is probably correct...

If the intention is to batch convert 32bit RGB images of symbols to pure black symbols, it might be logical to batch convert the images to 1-bit colour depth using Transformations > Convert > Convert to Binary.

That does assume that there is no other colour in the source images which needs to be preserved, otherwise it would be an interesting challenge... Maybe using Levels?? Or possibly simply by reducing the number of colours in the PNG??
jpeni
Posts: 5
Joined: Fri Apr 11, 2008 10:16 pm
Location: Uniondale, NY, USA

Re: Batch Replace Color Produces Pixelated Colors

Post by jpeni »

I checked the original RGB 32-bit PNG image - the color is pure black - Value: 0,0,0. The image contains only Black and White.

I converted the PNG image to Binary (No dither) with XnView and reprocessed to Replace Black (0,0,0) with Red (255, 0, 0),
but the resulting Replaced Color symbol is still Black - the Red did not appear.

JPeni
cday
XnThusiast
Posts: 3296
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Batch Replace Color Produces Pixelated Colors

Post by cday »

If the image is converted to binary it can't contain anything except black and white. I'm sorry, I didn't realise you wanted to replace the black symbol with a red symbol, although that is in fact clear in your original post.

Can you post the original image, or a representative image, either as an attachment or as a link to a file hosting service, as DOS386 suggested?

Edit:

I have done a quick test with a simple image I created and with 24-bit depth black was replaced by red successfully, but when the same image was converted to 32-bit in XnView the histogram of the resultant 'red' image had some additional colour (which showed in the image as a band rather than pixelation).

If you can post a test image it should be possible to reproduce any bug if there is one for 32-bit depth images.
jpeni
Posts: 5
Joined: Fri Apr 11, 2008 10:16 pm
Location: Uniondale, NY, USA

Re: Batch Replace Color Produces Pixelated Colors

Post by jpeni »

Image
User avatar
XnTriq
Moderator & Librarian
Posts: 6040
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Batch Replace Color Produces Pixelated Colors

Post by XnTriq »

jpeni wrote:I am trying to batch convert a collection of black symbols in .PNG (32bit RGB) images.
If your goal is to convert these symbols from black to red without loosing the smooth edges, you're better off by just increasing the value of the red channel:
  • View mode: Image » Adjust » Brightness/Contrast/Gamma/Balance... » Colour balance
  • Batch processing: Map » Colour balance
Would you like the background to be transparent?
cday
XnThusiast
Posts: 3296
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Batch Replace Color Produces Pixelated Colors

Post by cday »

a.png
The file as downloaded contains 149 unique colours, as shown by Image > Count colours used, and as predicted by DOS386.
b.png
The image obtained using Image » Adjust » Brightness/Contrast/Gamma/Balance... » Colour balance with Red=255, Green=0, Blue=0.

Excellent idea XnTrig, but the image still contains 143 unique colours. Is there a way to make a pure red image?

Edit:

The extra colours almost all occur on the edges of the symbol and suggest that the image has been anti-aliased at some point. Reducing the colour depth (using Levels with an extreme setting is one way) results in extra pixels becoming visible on the edges, which substantially degrade its appearance.

So at what point was the image anti-aliased? But as adjusting the colour balance seems to produce an acceptable image, and the anti-aliased image has a better appearance, are the extra colours a problem?

Finally, the original 'Replace colour' method does work correctly for 32-bit images with a single colour, and produces a pure red symbol when the image remains a PNG, but saving as a JPG seems to introduce additional colours and the possibility of banding or other artifacts.
You do not have the required permissions to view the files attached to this post.
User avatar
XnTriq
Moderator & Librarian
Posts: 6040
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Batch Replace Color Produces Pixelated Colors

Post by XnTriq »

cday wrote:Excellent idea XnTrig, but the image still contains 143 unique colours. Is there a way to make a pure red image?
You'll need XnViewMP for that:
  1. Create an all red image with the same dimensions as p5fo5Lp.png (200×200 pixels) and name it blank.png.
  2. Invert p5fo5Lp.png (Image » Map » Negative) and save it as mask.png.
  3. Tools » Batch convert...
    1. Input » Add files...: blank.png
    2. Actions » Add action » Image » Add mask: mask.png (Use mask as alpha)
Image + Image = Image
jpeni
Posts: 5
Joined: Fri Apr 11, 2008 10:16 pm
Location: Uniondale, NY, USA

Re: Batch Replace Color Produces Pixelated Colors

Post by jpeni »

cday and XnTriq

Thanks for your help.

JPeni