Jump to content

Stop blended pixels on resize, but without poor quality of Nearest Neighbor algorithm


Recommended Posts

Hello,

 

I am working on a geographical map image that will ultimately be interpreted by a computer program. Thus, it is crucial that the final resized image has exactly the same colors as the original. I cannot have any blended/antialiased pixels anywhere on the resized image.

 

I read up on a similar thread from many years ago, and it pointed to TR's color reducer plugin: https://forums.getpaint.net/topic/29424-trs-color-reducer-and-palette-maker-2014-08-01/ However, I couldn't figure out how to use this plugin to accomplish what I need.

 

The only resizing algorithm that seems to avoid blending pixels is the Nearest Neighbor, but if I resize the image 200% for example, each 1 pixel on the original image turns into a 2x2 homogenous square on the resized image. Although it retains the exact colors of the original, I need the quality to be comparable to the Best Quality or Bicubic algorithms.

 

Here is a sample of part of my map image.

 

Original:

image.png.b7340a5749655b6748f5c7b260fbc388.png

 

Resized using Bicubic:

The issue here is that the algorithm blends pixels at the borders of different colors, so this image has a much larger palette than my original. I can't have this, since the computer can only process the colors in the original.

image.png.bb8d13eb04902a7e9209abbb9b09c612.png

 

Resized with Nearest Neighbor:

This preserved the color palette of the original, but it turned each pixel from the original into a 2x2 square of homogenous pixels. This greatly reduces the sharpness and quality of the resized image.

image.png.a7d512ab3bf3d208330b99a8d439f62b.png

 

In summary, I need to be able to resize the image with the quality of the Bicubic algorithm, but avoid blending pixels like the nearest neighbor algorithm.

 

I can't do anything manually, since my map is over 40000x20000 pixels, and it would take years to go over every blended edge with a tool.

If someone knows how to do this using a plugin without any kind of manual input, that would be great.

 

Thank you for your help!

Link to comment
Share on other sites

8 minutes ago, Orchface said:

TR's color reducer plugin: https://forums.getpaint.net/topic/29424-trs-color-reducer-and-palette-maker-2014-08-01/ However, I couldn't figure out how to use this plugin to accomplish what I need.

 

There's an alternative that I like much better called Selective Palette.

 

10 minutes ago, Orchface said:

If someone knows how to do this using a plugin without any kind of manual input, that would be great.

 

It's not clear what you mean by manual input, but you could try Hawkynt's 2D-ImageFilter Library.

  • Like 1

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

13 minutes ago, Orchface said:

I need to be able to resize the image with the quality of the Bicubic algorithm, but avoid blending pixels like the nearest neighbor algorithm.

 

You want your cake and eat it too...

 

The "quality" of bicubic is BECAUSE of the pixel blending.  Without pixel blending you get Nearest Neighbor.

 

You can't have it both ways.

 

That said, you might be able to do something with Floyd-Steinberg Dithering... resize with Bicubic then Dither your image.  If you need a custom palette added to the plugin, I might be able to help with that.

  • Like 1
Link to comment
Share on other sites

22 minutes ago, BoltBait said:

 

You want your cake and eat it too...

 

The "quality" of bicubic is BECAUSE of the pixel blending.  Without pixel blending you get Nearest Neighbor.

 

You can't have it both ways.

 

  

23 minutes ago, toe_head2001 said:

 

It's not clear what you mean by manual input, but you could try Hawkynt's 2D-ImageFilter Library.

 

Here is a photo that I manually edited after resizing to produce the intended effect (there was no way to do this in a single step during resize):

 

Original (two colors only):

image.png.77d8ada64f51fdc7057f5a6574d83485.png

 

Resized 200% with bicubic, and then manually recolored to remove blended pixels (still two colors only):

image.png.5fcaace61e56760706b6f15e25f5207c.png

 

Notice that in the second image, the smooth rasterization is present, yet all pixels are 100% black or white. No gray/blended pixels to be found.

And the diagonal edges from the first image were transformed into single-pixel lines in the resized image, rather than just turning each pixel into a 2x2 square like Nearest Neighbor.

 

Here is an illustration of a 200% resize using smooth rasterization without any blended pixels:

image.png.7aeda7a3b94c7e0f4edd61d98bdeeff1.png

 

This is what I mean by preserving quality but doing away with blended colors. Sorry if I was unclear.

Edited by Orchface
Link to comment
Share on other sites

51 minutes ago, Orchface said:

Sorry if I was unclear.

 

image.png

 

In your example, you changed two pixels from white to black.  In my example, I changed two pixels from black to white.

 

If the background is transparent instead of white, this MIGHT be possible.  But, then what happens if the two original pixels are different color... what color would you make the new pixels?  You see, this thing you're asking for is VERY complicated.

Link to comment
Share on other sites

29 minutes ago, BoltBait said:

 

image.png

 

In your example, you changed two pixels from white to black.  In my example, I changed two pixels from black to white.

 

If the background is transparent instead of white, this MIGHT be possible.  But, then what happens if the two original pixels are different color... what color would you make the new pixels?  You see, this thing you're asking for is VERY complicated.

Good point.

 

By this point, I think it is safe to say that there is no pre-existing algorithm which can accomplish this.

 

The colors would be determined by a simple difference comparator. I'm not altering the brightness or adding any filters to this image, so Euclidian color distance should work fine for finding a numerical representation of similarity between two colors.

 

The algorithm would go as follows:

1. get a set of all colors on the original image palette

2. resize the image using bicubic

3. get a set of all pixels whose colors do not match one of those on the original palette

4. for each pixel, go through the set of colors from the original palette, find the color with the least difference from this pixel's color, and set this pixel's color to that color.

 

Obviously the TC on this algorithm is horrible, but you get the idea.

 

Here's a portion of the half-circle from earlier with two arbitrary colors, resized with bicubic.

image.thumb.png.872b8a393128d6b33499fa9810e6012f.png

 

Now here is what is might look like afterward:

The blended pixels whose color was closer to #FFD800 were turned to #FFD800 and the pixels whose color was closer to #0094FF were changed to #0094FF.

image.thumb.png.3cba857911e1226402d891629ddf0778.png

 

This could be done for three or more colors as well.

Edited by Orchface
Link to comment
Share on other sites

2 minutes ago, welshblue said:

Just a thought. 

On the map question - surely the problem starts from a poorly cut out British Isles and is then compounded when resizing ?

 

More care = better result ?

 

map-1.png

 

map-2.png

 

The reason it looks weird is because I am using a Robinson projection. Trust me, the original image is exactly how it should be. I am making a topographic relief map that will be processed by a program; that's why I need the colors and scaling to be precise.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...