How to set the same (constant) hue value for each pixel in an image using ColorMatrix?

I am trying to set a constant hue value for the whole image using ColorMatrix. My goal is to make the whole image the same color without losing the brightness of any area. I found a way to shift the hue values ​​of the image using ColorMatrix, but I could not find a way to set the same hue value for all pixels. I can do this with repeating each pixel of the image, but this approach is too slow. I'm not sure if this is possible using ColorMatrix, and I'm open to possible solutions other than the ColorMatrix approach.

Input image

Image Shade *

Desired image output **

* This can be done using the color matrix

** I can do it with iterative pixels, but not with ColorMatrix

PS: I'm trying to do this on Android, but I believe that the question is not directly related to android, as the ColorMatrix approach is common on other platforms such as Flash, C #, etc.

+7
source share
5 answers

Check the QColorMatrix , which has a ColorMatrix procedure called RotateHue . The source is in C ++, but ported to other languages ​​(I ported part of it to .NET in the past, and it worked great).

+3
source

they are not very familiar here, but I believe this link can help: http://www.graficaobscura.com/matrix/index.html is a c-code, so you need to translate C β†’ ColorMatrix, but in the last paragraph there is an operation

 Hue Rotation While Preserving Luminance 

which seems to be what you are looking for.

+2
source

I don’t think there is a way to do exactly what you ask with ColorMatrix. It looks like what you want to do is convert from RGB to HSL color space, set constant H across all pixels and convert back from HSL to RGB. These color space transformations are not linear and cannot be represented by matrices. Due to the different way these parameters parameterize the color, I also suspect that some degradation may occur, making RGB-> HSL-> RGB.

I think the closest you could achieve with ColorMatrix is ​​to use one to convert to grayscale, and the other to weight RGB values ​​(their shade). Such things are often used to create fake sepia photographs, but that’s not what you are asking for.

+2
source

I made a quick sample in Flash (this question is marked as ActionScript), not sure if this is what you are looking for:

http://megaswf.com/serve/1047061

The code:

 import com.greensock.*; import com.greensock.easing.*; import flash.events.MouseEvent; colorButton.addEventListener(MouseEvent.CLICK, onColor); resetButton.addEventListener(MouseEvent.CLICK, onReset); function onColor(e:MouseEvent):void { TweenMax.to(mc, 1, {colorMatrixFilter:{colorize:0x0099ff, amount:1}}); } function onReset(e:MouseEvent):void { TweenMax.to(mc, 1, {colorMatrixFilter:{colorize:0x0099ff, amount:0}}); } 
+2
source

here is a quick way to do this if you want to set the hue, say h (0.5, 0.2, 0.3).

 var matrix:Array = new Array(); matrix = matrix.concat([.5, .5, .5, 0, 0]); matrix = matrix.concat([.2, .2, .2, 0, 0]); matrix = matrix.concat([.3, .3, .3, 0, 0]); matrix = matrix.concat([0, 0, 0, 1, 0]); var filter:ColorMatrixFilter = new ColorMatrixFilter(matrix); image.filters = [filter]; 

I'm not sure that he respects brightness perfectly, but can satisfy your needs!

+1
source

All Articles