Jump to content

Color conversion


DMGD

Recommended Posts

Hello,

 

I am taking black and white images and trying to convert them to color. The color matching is not important this is for a technical purpose not astetic..

 

Is there a way to scale the grey to color.. IE

 

If white is 0 and black is 10.. convert those values into a color scale for an image. Basically like what i have below.

 

image.png.3cf39702f304f8237f7e62296a7a16ad.png

Link to comment
Share on other sites

3 ways to do this.

  • Reverse engineer it by using color curves and working by channels. Use Color Curve+.
  • Make the gradient map yourself. Use the gradient mapping provided by @pyrochild
  • An automated solution (I do have g'mic codes that could work. I believe that something based on this definitely could work.). The solution is provided below.
mirror. x
sh[0] 0,2
f. i(#1,i/iM#1*w#1-1,0)
rm.

Copy the gradient image to clipboard, and paste this into code[local] of g'mic qt. Make sure you set to active and below.

 

The i code uses values as reference to the x coordinate of the copied gradient. iM simply means the maximum value. #1 means that it's using the gradient image as reference for color. I'm not sure how to do the codelab or c# equivalent of this automated solution, you would have to ask a person that expertise on that.

 

I had to use mirror x. because the left means 0, and the right means 1. It wouldn't be needed if you flip the gradient horizontally.

 

EDIT: By the way, the scale aren't equal, so that makes this thing a bit harder to solve. First, make the gradient of color of equal length, then do the above. It'll take time, but it's possible.

Edited by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

How many distinct colors do you want to end up with?

 

I have an unreleased plugin which looks up the source color and returns a match from a list of 255 colors. I could rewrite it for you to customize it to your needs.

 

Edit: Another easy way would be to use one of the source color channels (R, G or B ) to return a new Hue. 256 inputs = 256 outputs.

Link to comment
Share on other sites

4 hours ago, Ego Eram Reputo said:

How many distinct colors do you want to end up with?

 

I have an unreleased plugin which looks up the source color and returns a match from a list of 255 colors. I could rewrite it for you to customize it to your needs.

 

Edit: Another easy way would be to use one of the source color channels (R, G or B ) to return a new Hue. 256 inputs = 256 outputs.

 

I'm guessing it's based on finding values based on the image lightness using source and the target, then averaging values based on the found value after the search, and then return that to a vector, and then use the vector as the output.

 

Speaking of image, I have a feeling that it's related to sin and cos function and contrast function. If you disable color channel, you'd find that there's a sin,cos, contrast function applied. The better theoretical solution is to do applied mathematics to solve this. You would be able to get more accurate result, and more ranges of application not limited to 8-bit processing and might even have theoretical output that lies outside of the ranges mentioned in the original post.

Edited by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

22 minutes ago, Reptillian said:

I'm guessing it's based on finding values based on the image lightness using source and the target, then averaging values based on the found value after the search, and then return that to a vector, and then use the vector as the output.

 

Yes - you're pretty close!

 

I calculate the source color intensity which I clip to a byte (0 to 255). I use the intensity value to look up a custom list of 256 RGBA colors.  

 

I released a CSV file type plugin in order to make a 1px x 256px slice of an image into a color table. Now you know what I was making when I came up with the plugin ;)

 

If the OP wanted to use the demo image as the color table, simply resize it to 256px wide and crop it to one px high. Then save the pixel data using the plugin and import it as hard-coded data into Codelab.

 

Link to comment
Share on other sites

Thank you for the help.. basically I am after the below. I have several photos of what is pictured on the left, I would scan that, grey scale, "do something", then present the information. I also have a sheet of known pressures that directly relate to the density of the color (about 12 levels) then use that as a reference for the chart.

516lr4tbztL.jpg
 

Link to comment
Share on other sites

Give me a couple of days and I'll customize my plugin to use your color table. 

Link to comment
Share on other sites

If you just need coloration based on darkness in general (and don't need the specific gradient you put above), my plugin Color Magic works quite well for this effect with the "Black Distance" or "White Distance" settings. Adjust the "Smoothness" variable to to make the recoloring smoother or more scattered and then adjust the hue/saturation as needed. Here are some examples:

 

KhgBFom.png

 

Gta8Dp3.png

QW0hr7j.png

 

Note that the quality is only bad because I only had a 167x182 image to work with. Better-quality images will give better results. Also note how similar the second one looks to the Topaq colorization system. Probably a very similar algorithm.

 

 

Note also that converting first to grayscale isn't required -- this plugin will automatically read the dark/light data from the image regardless of its color. It actually *won't* currently work with black/white images (I should fix that!)

Edited by Xhin

xhin.png

Link to comment
Share on other sites

40 minutes ago, Xhin said:

Note also that converting first to grayscale isn't required -- this plugin will automatically read the dark/light data from the image regardless of its color. It actually *won't* currently work with black/white images (I should fix that!)

In case you're talking about first picture: In the first picture, while a filter can read light/dark of a color, it seem to utilize arbitrary gradient based on info of below which don't follow 'fill x' slope. This is where extracting gradient map comes in. In the end, you still have to manually find curves and/or gradient map using extracted info.

 

-

 

The second picture do surprisedly look similar. Some deviations exist within cyan to violet range.

Edited by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

Here is something to play with... it is in the Adjustments menu.

 

Note: your 'white' background is not uniform ;)

 

The red color doesn't return a full range of intensities. I out of time today to play with it any more. Sorry. Let me know if you want me to work on it further.

 

 

 

RecolorFromTable.zip

Link to comment
Share on other sites

9 hours ago, Ego Eram Reputo said:

Here is something to play with... it is in the Adjustments menu.

 

Note: your 'white' background is not uniform ;)

 

The red color doesn't return a full range of intensities. I out of time today to play with it any more. Sorry. Let me know if you want me to work on it further.

 

 

 

RecolorFromTable.zip 6.07 kB · 2 downloads

 

I wonder if you can modify that to use 256x1 or 1x256 colors clipboard image as table. It would go well with my recent g'mic filter which basically reverse engineer gradient map from grayscale image and color image of the same size.

Edited by Reptillian

G'MIC Filter Developer

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...