Detect only red pixels in Java - java

I need to detect all the red pixels in an image using Java. What 's the best way to do this?
Only supposing a pixel is red when the Red RGB-value is > 200 isn't good enough (see this table).
So is there a better way to do this? Or is there some red-color-rgb algorithm?

Take a look at YCrCb color space.
Simple algorithm: convert your RGB image to YCrCb, extract red channel and make a threshold.

Convert RGB to HSL, and threshold the hue (H) component.

As you suggested, you probably want to do some comparison in HSB space. You'll probably want to define an appropriate rage for all three values based on what your expectations are.
You can use Color.RGBtoHSB to get the values from a given color.
http://docs.oracle.com/javase/7/docs/api/java/awt/Color.html#RGBtoHSB%28int%2C%20int%2C%20int%2C%20float%5B%5D%29

Related

Color Combination

I have a grey image containing at least 20 different shades of gray. I would like to apply a certain color without changing it with the exception of the grey affecting the colors brightness slightly. I don't want a very drastic modification to color, only a hint. How would I go about doing this?
I'm using java, however I am more interested in the concept behind doing this.
How would I get the hsv values of a color in Java?
Don't know about HSV, but you could probably use HSL instead. Check out HSL Color for a class that does the conversion.

Convert grayscale image to RGB

I'm not totally sure this is in the right place, so let me know...
Just so I'm being totally transparent, this is part of a coursework for my University course. To that end, please don't post an answer but please DO give me hints & nudges in the right direction. I've been working on it for a few days without much success.
I've been tasked with converting a grayscale image into an RGB image. It's been suggested that we must segment the image and add colours to each segment with an algorithm. It'a also noted that we could develop algorithms for both the RGB & HSI colourspace to improve the visualisation.
My first thought was that we could segment the image using some threshold technique (on the grayscale intensity values) and then add colours to segments, but I'm not sure if this is right.
I'm programming in Java and have use of the OpenCV library.
Any thought / ideas / hints / suggestions appreciated :)
A very nice presentation describing different colorization algorithms
http://www.cs.unc.edu/~lazebnik/research/fall08/lec06_colorization.pdf
The basic idea is to match texture/luminance in source and target images and then transfer the color information. The better match you have, better would be your solution. However, matching intensity values in Lab space may be misleading as many pixels in the source image can have similar luminance values around them. To overcome this problem, segmenting the source image using texture information can prove helpful and then you can transfer color values of matching textures instead of luminance values.

Java color detection

I am implementing algorithm in java which select a portion of image as marker.
My problem is
1) After selecting the marker area, how do i get the specific mean value of marker color in RGB as the number of pixels with a small difference in color.
2) How can i find marker value, meaning the threshold value for the color, based on the previous marker selection.
Please provide an algorithm and if posssible, an implementation in java.
Thanks in advance.
I'm not sure what you tried, and where you're stuck, but here goes:
To get a mean color your best bet is to try to find the median value for the three channels (R, G and B) separately and use that as the mean. Due to specific qualities of the RGB color space, the mean is very vulnerable to outliers, the median less so.
I assume you want to select all colors that are similar to your marker color. To do that you could select all pixels where the color is less small euclidean distance to your median RGB color selected above.
If this does not work for you you could look into alternative colorspaces. But I think the above should be enough.

Generate color combination from one color

I need to generate a color combination (monochromatic, triad, analogous, split, etc) from one color in Java. Just like they do in kuler, only I want to present it in a JSP page). How can I get the RGB value of the colors in the color combination? Is there a formula or API to do this?
I don't know what all those terms mean, but you might find that using HSL Color values may make it easier to find related colors.

How to replace color of an image?

I want to replace color of an image. For example turn all blue colors to red without any distortion on shape. When i try this i can swap the colors by iterating every pixel, however the shape of the swapped area turns into a flat shape.
example1 input : http://www.tutorialwiz.com/tutorials/changing_color/images/original.jpg
example1 output: http://www.tutorialwiz.com/tutorials/changing_color/images/3.jpg
example2: input output together : http://www.digital-photography-school.com/wp-content/uploads/2009/07/before-after.jpg
The usual way to do this is to use an RGBImageFilter. See the docs for FilteredImageSource for how to use such a filter.
The problem with the issue that you are asking is that a strict color replacement will modify the shape of the image. What you need to do is get a little information on what the shape is. I.e. Find boundaries and shading along the boundaries. My suggestion to you is:
Use edge detection to separate out blobs
Find a blob that fits your demands: i.e. Has a tolerant likelihood for [color]ish.
Identify blobs and filters applied
Recolor the blob and reshade.
IMO: That is the only way you're going to get the result you're looking for.
Some notes: Finding a blob may require some testing to determine how much tolerance you have for blobs and shapes. [Connected Regions].
Another thing: The shading and relative coloring will require you to have a devience for the color you want.
I'm not fully understand the question.
But from the example given, i see that the process of changing blue into red was fail. instead of becoming red, it becomes gray. does color gray is what you mean by flat?
If that so, it looks like color channel error.
to change blue to red, we have to change (0,255,0) to (255,0,0).
I'm not sure if it is the problem, maybe code snippet could help for evaluation. to make sure what is the real problem.

Categories

Resources