9

I would like to reduce the number of hues in my flat image from the full range to only four, but I would like to preserve the value/brightness (and if possible, saturation as well). I want four hues because I think it will look cool.

I tried using a hue-adjustment layer, but when I used it, it only shifted the range during conversion, so that one range was converted into another range with many colors. I want to shift a specified range to be converted to the same hue while preserving value/brightness (and maybe even saturation, if it can be done).

I am using Photoshop CS5

These are the four HSB/HSV hue values I want to use:

  1. 333
  2. 58
  3. 193
  4. 242

This is how I would like to convert the hues:

Target HSV Values

Note: I have modified this question since first posting it. Initially, I erroneously asked that responders reduce the image to four RGB values, while simultaneously maintaining the tints/values in the source image. This, however, is an impossible task, as RGB values contain tints/brightness AND hues; in RGB tint and hue are inextricably linked.

Thankfully @Wolff was able to understand what I meant, despite my poor phrasing, and along with @Danielillo, @Ryan, and @Emilie, he helped me to understand that what I was really asking for was to target four hues, not four RGB values. He then identified the four hues present in my RGB values (in HSB/HSV). Those HSB/HSV values are the now the ones I am asking responders to target in the image conversion (not RGB).

Also, as noted by @Wolff, in the first version of my post, I didn’t specify how to convert the full HSB spectrum (I didn’t have magenta-like ranges). The updated question also includes that previously omitted range.

For those who want to understand the root of the confusion (rightfully expressed by some users who provided alternate answers), these were the original 4 RGB values I posted:

enter image description here

Clarification update: Please know that my intention is only for screen, not print. I built a site, based on those four hues, and I thought it would be slick if the images all had the colors warped to match them. At the same time, within each of the four collapsed colors' ranges, I wanted to keep as much of the dynamics which are encoded by original value/brightness as possible. I hope this helps. Points will not be awarded by me, the original poster, for print answers, but any explanation for a print solution will likely be appreciated by the community. @Emilie, who placed the bounty on the question, can reward whomever she desires.

Thanks to @Emilie for placing the bounty on this! I really was bummed that no one seemed able to answer it before.

  • just a guess, but a combination of a black & white adjustment layer and a gradient map? – Vincent Jul 28 '16 at 12:51
  • @Vincent won't work I don't believe. In fact I don't think any answer will work. Its a flawed concept. – Ryan Nov 1 '16 at 12:36
  • Okay.. then you don't need spot channels specifically. You can just mask layers and apply a color overly....It will respect tints if you send the blend mode to "Hue" or "color". – Scott Mar 7 '17 at 7:36
  • The colourisation is easy (I’d use gradient maps). Automatically selecting the hue ranges and creating the masks is that harder part. I haven't thought of a solution for that yet. – Marc Edwards Mar 8 '17 at 11:47
  • 1
    @Emilie, It made my day to see all the engagement your bounty prompted! Plus I get to see the results (which I could only imagine before)! Even the "incorrect" responses are interesting. Thanks again!! – CoderScissorhands Aug 26 at 18:15
6
+50

As others have pointed out, the logic of this question is a bit flawed, but very interesting nonetheless.

My answer is mostly based on RGB/HSB math and I admit that there are many questionable aspects when it comes to percieved color, color profiles etc., but I'll give it a shot anyway.


I'm taking the liberty to redefine the question a little bit to be able to answer it.

First of all, the spectrum you are showing us is going from red to blue. The magenta is missing - what to do with the colors in that part of the spectrum?

So I'm extending your spectrum to include magenta in both ends.

Another problem we have is your list of four hues as you call it. They are not just hues, they are colors with individual saturation and brightness values. This doesn't make too much sense if we are to compare them with the spectrum, so we have to "reduce them to hues" by changing both the saturation and the brightness to 100.


We'll use the HSB/HSL Filter (must be dowloaded from Adobe's site) in Photoshop to get the hue of an image as an alpha mask. Then we'll use Gradient Map to map the hue values to the wanted values and then we'll convert the image back to RGB using HSB/HSL Filter again.

The math is a bit funky because the range of hue is 0-360 (and it wraps), the range of alpha is 0-255 and the range of gradient stops is 0-100.

First I'll make a table to get an idea of what's going on. We might not need all the numbers.

(The values are rounded and the hues not exactly how you've defined them, because I've extended the spectrum. They could of course have been placed differently.)

Let's take a colorful image and add the spectrum as a reference. (Image by Mike Goad from Pixabay).

Using HSB/HSL Filter gives us the following hue channel:

I copy the hue channel to a new grayscale document (the color profile must be Gray Gamma 2.2) in order to be able to use Gradient Map on it. I set up the Gradient Map as follows:

Setting up the gradient stops requires a bit of fiddling (it's quite annoying to work with). I'm getting the values from the table I made before. There are 8 stops in total, some of them must overlap to get hard transitions:

The resulting hue channel looks like this:

I finally copy this hue channel back into the initial HSB image, replacing the old hue channel and convert the image back to RGB using HSB/HSL Filter.

I believe this does as requested, but I'm not sure if it looks as cool as you hoped. The transitions are very abrupt, but they could of course be softened by changing the gradient map.


Edit: Javascript approach

Here is a JSFiddle with a Javascript version of the same concept. Drop an image on the resulting page and it gets converted to the four hues. Change the "hueRanges" to customize the result. The main part of the code is annotated.

The result differs slightly from the Photoshop method, but it's very close:

Since I don't know the math behind Photoshop's filters I can't tell why there is this difference.

  • Let us continue this discussion in chat. – Wolff Aug 25 at 21:16
  • Stop posting in comments. The chatroom was created, any comments after it was created have now been lost. Use the chatroom. – Ryan Aug 26 at 18:52
2

This is a flawed concept to reproduce because its entirely abritrary where one color ends and another begins. You also talk about preserving tint which makes it even more confusing.

That said for your result you might try:

  1. Convert to LAB
  2. Duplicate the layer and posterize it with 4
  3. Create 4 Solid Color adjustment layers with each of your 4 colors. Change each one to the Color blend mode.
  4. Use Blend-If Options to reduce those 4 colors to the contrains you're after.

Here's the results:

enter image description here

  • I don't think you are "preserving the tints" as my answer does (in a way), but it looks pretty cool! – Wolff Aug 26 at 19:52
  • @Wolff tints in LAB are completely separated into the L channel. My answer doesn't edit that channel at all so it should preserve tints/shades (lighting) – Ryan Aug 26 at 19:53
  • Ah, I see. Nice. – Wolff Aug 26 at 19:54
  • I've asked this question following your answer because I couldn't really find anything to back up that LAB separated white/black more properly than HSB. So I've attributed the bounty to Wolff's answer but just for the record, my mind is not really made up between the two! – curious Aug 30 at 14:34
2

The question is lately edited from an ambiquous state to a better shape. It demands now explicitly predefinable hue quantization and remapping. The accepted answer gives it for Photoshop.

The next is for freeware users.

Paint.NET has a plugin filter which does hue and saturation range mappings directly. This task needs applying the filter four times to map total 360 degrees to four discrete hues. The result is the same as in the accepted answer. The filter is "Conditional Hue/Saturation". It's a part of Evan's Effect Package.

The filter isn't fully polished. I couldn't input exactly predefined hue values. Range settings must be done with far too small sliders, no exact numerical input fields exist. Here's a test with the same image which was used in Wolff's answer:

enter image description here

  • Oh, nice to see that you get the same result. I mean it seems that this is how it looks if you do what the OP asks for. Will we ever need this result? I'm not so sure. But it's a puzzle solved. – Wolff Aug 31 at 8:11
  • @Wolff if the mapping is done by setting the values visually, the method surely would have some value as creative tool. The filter for Paint.NET fulfills that task. – user287001 Aug 31 at 8:38
  • Thanks! While I did want a Photoshop-based solution, it is nice to have an open-source option. Cool that you found this! – CoderScissorhands Aug 31 at 19:26
1

1. Convert the RGB image to HSB

Use Filter > Other > HSB/HSL and select Input mode: RGB and Row order: HSB. This will make the image look very strange but it allows us to manipulate the hue separately from the saturation and brightness using the image channels.

2. Reduce the number of hues

The Red channel will now contain the hues for all pixels in the image. You want to quantize these into your four selected hues. This is the hardest part. One way to do this would be to copy the content in the red channel to a new image and set image mode to Indexed color and create a custom palette with your hues mapped to the corresponding black and white values. Then paste this image back into the red channel.

3. Convert back to RGB

When you have reduced the number of hues you apply the HSB/HSL filter again but with reversed input/row order setting to complete the procedure.

  • I don't have hsb/hsl as an option in my "other" menu. Is that part of CS5? – CoderScissorhands Oct 4 '17 at 19:23
  • I found it here: supportdownloads.adobe.com/detail.jsp?ftpID=4688, it is an "additional plugin" (you need to put the file called "Optional MultiPlugin.8BF" in your install's photoshop's install plugin folder. – CoderScissorhands Oct 4 '17 at 20:02
  • I made it to the middle of step two, and have the red channel in a new image, with the image mode set to indexed color. Now, would you mind telling me how to create a custom pallet with my hues mapped to the corresponding black and white values? If you can walk walk me through that and it works I can give you credit for answering the question. :) – CoderScissorhands Oct 4 '17 at 20:11
0

The question does not clarify the purpose of the image, this answer is for an image intended for printing (EPS DCS)

In this case, converting an image to only four inks without having the color black, assumes the shadows of that image will be the darkest color, blue.

  • Starting from a CMYK image where there are 4 color available channels and go to menu Image > Mode and choose Multichannel
  • Edit each channel color clicking the color thumbnail and insert the RGB numbers
  • Replace the Black channel for the Blue color

enter image description here

enter image description here

Add after the comments and chat

To me the question has a concept problem what makes difficult to find an optimal result. I guess the OP is asking about a RGB image but thinking in a CMYK mix process. That's why I use a CMYK image while @Wolff answers using a RGB image.

  • The red is easy to change to the new RGB color
  • The problem comes with yellow, since in a RGB image yellow is the mix of green and red, so this makes impossible to separate red and yellow as two different colors. In the spectral bar the greens and yellows should be a yellow RGB, this means getting rid off the RGB image. It must be converted to a print flat colors image (or another image mode) to get it.
  • The same problem with cyan, a mix of green and blue

enter image description here

  • 2
    Bounty hunter :) Your answer doesn't really address all the technical issues of the question. And the resulting image can't be intended for printing since you can't use four RGB colors as printing inks. I'll see if I can come up with a more (pseudo) technically correct answer. – Wolff Aug 25 at 14:50
  • I know, actually the question has several unclear issues to me, that's why I put my printing version. You can't use four RGB colors as printing inks, that's right, but you can use RGB color in a multichannel doc. – Danielillo Aug 25 at 14:56
  • Yes, but what to do with the file afterwards? It's still just "for screen". You'll have to convert to RGB and then back to CMYK in order to able to print it. The question is flawed. See my latest post on The Ink Spot. (I'm working on another solution right now) – Wolff Aug 25 at 15:01
  • You'll have to convert to RGB and then back to CMYK in order to able to print it, that's wrong, a .dcs file is a ready to print in silkscreen of flat inks. I go back to the beginning of my answer: the question does not clarify the purpose of the image. – Danielillo Aug 25 at 15:03
  • 2
    As far as I can tell, the way @Wolff manipulated photo of the fruit stand looks more like the intended result I had hoped for (compared to your version of it). I want something akin to posterization, but with tints preserved as much as possible. Your version of the fruit stand has oranges and reds that I definitely want to exclude. I'll wait a bit before rewarding the bounty, but so far, he seems to have understood my question, as I intended it, better. – CoderScissorhands Aug 26 at 16:23
-1

It's not converting many colors to 4, but achieving 4 colors with the same tint? Open the first color in your color picker. Left and right changes hue. Up makes tints, down makes shades. Go straight up from your color a specified distance. I don't know how to specify the distance, by eye and hand is how I do it. If your original color is halfway up the the chart, pick a point directly above it that is 25% to the top ( or however much tint you want). Note the hex value of this new color. Do the same for the next three colors, trying for the same amount up from the original color.

Alternately, gather your 4 saturated colors together and draw a white rectangle over them and apply transparancy/difference and opacity 80% to the rectangle. You might have to try the other transparencies and opacity especially to get the right tints, or apply only opacity to the rectangle, adding white to your colors evenly to achieve the same tintedness.

  • Oh, woops, this is for Illustrator. If background is white then opacity will apply tint to your colors in PS. – Webster Jan 6 '17 at 3:34
  • I want to basically to collapse all hues to four, and preserve tints. Does that make sense? I want the final result to have the full range of tints available in the original image. However, I want to replace the hues...reducing them from full spectrum to four, and have those values depend on where in the hue range it falls. – CoderScissorhands Jan 6 '17 at 16:34
-2

There are a few ways I can think of, though none of them are super accurate and convenient in every case.

  • Option one is to use the sampler/color picker tool. Select it, and then set 'sample size' at the top to a large value that would cover about 1/4th of the image. By doing this, the sampler will take an average tint over a larger area, as opposed to a single pixel. If your image is too large, scale it down first.
  • Option two is to scale down the image to just a few pixels large. For example, if you'd use the image you provided, and you want 4 colors, scale the image down to 4 pixels high. This way, Photoshop finds the average colors for you when scaling. Note: With the second option, it may help to set image interpolation (can be found in Photoshop's settings) to 'nearest neighbour'.

Alternatively, you can use Adobe Illustrator, should you have it.

Import the image you use, and look for 'image tracing'. Set image tracing to the best setting that suits your needs. In CS6 at least, there are presets for 3 or 6 colors, but if you open the image tracing panel you can set another desired amount of colors.

  • Since he wants to convert his entire image(as in each pixel), scaling it down is probably not what he wanted though. – SitiSchu Jul 5 '17 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.