GPUImage: Reducing color depth - pixel

I would like to reduce the color depth of input video and images (for example, to 16bit) when using GPUImage on iOS, and was just curious if there is a simple way to do this using existing filters.
It looks like GPUImageColorMatrixFilter or GPUImageRGBFilter might be the right tools; is this the case? I will start experimenting now, as well. Thank you.

I don't think either of those are going to do what you want here. Ignoring dithering, you're going to want something that reduces the number of color levels in your image.
The GPUImagePosterizeFilter reduces color levels by reducing the dynamic range of the red, green, and blue channels individually using the colorLevels property. For a value of 10, that should reduce your image to a 1000-color one.
However, because this acts on each color channel individually and uniformly, this may not reduce your colorspace in the specific way that you'd want. To tune colorspace reductions like this, I've seen people use color mapping tables. If you want to go that way, I'd recommend the GPUImageLookupFilter, where you can do your reduction operation on a lookup table image and then use that to do your remapping. This might lead to a higher-quality result.

Related

Clustering of colors in a thermal image

I am working on detection of dental issues using thermography. I need to separate the all the given colours in the image into separate clusters (4-7 in number) so that the high-temperature zones (seen white in the image) are seen separately, which can be followed by thresholding if need be.
I am also attaching a sample of the images I will be working on. I am looking for a suitable program to carry out the execution in MATLAB.
I've already worked on the same, the program being attached in the previous question, which gives 3 clusters only.Since I'm a beginner, I need help in establishing more clusters.
image obtained using thermal camera on which clustering is to be carried out
the closest I could get to the sort of clustering I want to carry out. here, in this image green-blue cluster and white cluster are in the same image, which i want to have in separate clusters, hence the need of more clusters
expected result after clustering and thresholding
Rather than hoping that by chance clustering does what you need, I'd rather just use the ground truth you have...
In case you haven't noticed: there is a color index to the right. That is an easy to use, ordered (this is extremely beneficial over clustering, in particular to set thresholds) easy to detect key to interpreting these images without hoping on a random generator.
Note that you will likely also need to read off the numbers that give the color scale, in order to compare images.
You can read your image file in Matlab and then convert the data from RGB format to HSL or HSV with the function rgb2hsl() or rgb2hsv().
They are two alternative representations of the RGB color model. Then you can easily make your discrimination with the value of H which is abbreviated for hue.
For more information take a look at the following link: HLS and HSV

Algorithm to detect the change in visible luminosity in an image

I want a formula to detect/calculate the change in visible luminosity in a part of the image,provided i can calculate the RGB, HSV, HSL and CMYK color spaces.
E.g: In the above picture we will notice that the left side of the image is more bright when compared to the right side , which is beneath a shade.
I have had a little think about this, and done some experiments in Photoshop, though you could just as well use ImageMagick which is free. Here is what I came up with.
Step 1 - Convert to Lab mode and discard the a and b channels since the Lightness channel holds most of the brightness information which, ultimately, is what we are looking for.
Step 2 - Stretch the contrast of the remaining L channel (using Levels) to accentuate the variation.
Step 3 - Perform a Gaussian blur on the image to remove local, high frequency variations in the image. I think I used 10-15 pixels radius.
Step 4 - Turn on the Histogram window and take a single row marquee and watch the histogram change as different rows are selected.
Step 5 - Look out for a strongly bimodal histogram (two distimct peaks) to identify the illumination variations.
This is not a complete, general purpose solution, but may hold some pointers and cause people who know better to suggest improvememnts for you!!! Note that the method requires the image to have a some areas of high uniformity like the whiteish horizontal bar across your input image. However, nearly any algorithm is going to have a hard time telling the difference between a sheet of white paper with a shadow of uneven light across it and the same sheet of paper with a grey sheet of paper laid on top of it...
In the images below, I have superimposed the histogram top right. In the first one, you can see the histogram is not narrow and bimodal because the dotted horizontal selection marquee is across the bar-code area of the image.
In the subsequent images, you can see a strong bimodal histogram because the dotted selection marquee is across a uniform area of image.
The first problem is in "visible luminosity". It me mean one of several things. This discussion should be a good start. (Yes, it has incomplete and contradictory answers, as well.)
Formula to determine brightness of RGB color
You should make sure you operate on the linear image which does not have any gamma correction applied to it. AFAIK Photoshop does not degamma and regamma images during filtering, which may produce erroneous results. It all depends on how accurate results you want. Photoshop wants things to look good, not be precise.
In principle you should first pick a formula to convert your RGB values to some luminosity value which fits your use. Then you have a single-channel image which you'll need to filter with a Gaussian filter, sliding average, or some other suitable filter. Unfortunately, this may require special tools as photoshop/gimp/etc. type programs tend to cut corners.
But then there is one thing you would probably like to consider. If you have an even brightness gradient across an image, the eye is happy and does not perceive it. Rather large differences go unnoticed if the contrast in the image is constant across the image. Unfortunately, the definition of contrast is not very meaningful if you do not know at least something about the content of the image. (If you have scanned/photographed documents, then the contrast is clearly between ink and paper.) In your sample image the brightness changes quite abruptly, which makes the change visible.
Just to show you how strange the human vision is in determining "brightness", see the classical checker shadow illusion:
http://en.wikipedia.org/wiki/Checker_shadow_illusion
So, my impression is that talking about the conversion formulae is probably the second or third step in the process of finding suitable image processing methods. The first step would be to try to define the problem in more detail. What do you want to accomplish?

How to make a charcoal drawing filter

i'm interested in some kind of charcoal-filters like the photoshop Photocopy-Filter or the note-paper.
Have someone a paper or some instructions how this filter works?
In best case i want to create the following:
input:
Output:
greetings
I think it's a process akin to pan-sharpening. I could get a quite similar image in gimp by:
Converting to gray
Duplicating into two layers
Lightly blurring one layer
Edge-detecting in the other layer with a DOG filter with large radius
Compositing the two layers, playing a bit with the transparency.
What this is doing is converting the color picture into a 0-1 bitmap picture.
They typically use a threshold function which returns 1 (white) for some values and 0 (black) for some other.
One simple function would be transform the image from color to gray-scale, and then select a shade of gray above which everything is white, and below it everything is black. The actual threshold you use could be made adaptive depending on the brightness of the picture (you want a certain percentage of pixels to be white).
It can also be adaptive based on the context within the picture (i.e. a dark area may still have some white pixels to show local contrast). The trees behind the house are not all black because the filtering is sensitive to the average darkness of the region.
Also note that the area close to the light gap in the tree has a cluster of dark pixels, because of its relative darkness. The edges of the home, the bench are also highlighted. There is an edge detection element at play.
I do not know exactly what effect you gave an example of but there are a variety that are similar to it. As VSOverFlow pointed out, thresholding an image would result in something very similar to that though I do not think it is what is being used. Open cv has a function for this, its documentation can be found here. You may also want to look into Otsu's method for thresholding.
Again as VSOverFlow pointed out, there is an edge detection element at play as well. You may want to investigate the Sobel and Prewitt filters. Those are 3 simple options that will give you something similar to the image you provided. Perhaps you could threshold the result from the Prewitt filter? I have no knowledge of how Photoshop implements its filters. If none of these options are close enough to what you are looking for I would recommend looking for information on the specific implementations of those filters in photoshop.

Image-Processing Image Filters

Are there properties of digital images (e.g. dct coefficients, pixel values, YCbCr, others) that remain constant when filters like binarization, grayscale, sepia, etc, or tilting the image by a certain degree are applied. It would also be helpful if you could suggest any reading or online tutorial for basic image processing.
It sounds like you want to know what features are robust to all sorts of image operations.
The properties you listed are not invariant to the transforms you listed. You ask if the "pixel values" remain constant when you apply a filter that by definition modifies the pixel values. The only positive answer about your list would be that DCT coefficients maintain their distribution when you apply a color filter.
I'm going to make an assumption and suggest that you should read up on feature detection, where the goal is to identify salient parts of an image that remain constant after a transformation like scaling, rotation, etc. These features are useful for image stitching, object detection, query-by-image search, and lots more.
Q: Are there properties of digital images ... that remain constant ...
A: Sure: height and width ;-)
Q: ...or tilting the image by a certain degree...
A: Whoops - maybe not even height and width ;)
ANYWAY -
Your question is far, far too broad.
SUGGESTION:
Get a copy of Foley/van Damm:
http://www.amazon.com/Computer-Graphics-Principles-Practice-2nd/dp/0201848406
The properties of an image (i.e. pixels) always change when you process it. Processing simply means changing the pixel values in order to finally get something from it.
There are lots of image processing techniques such as removing noises, applying filters, re-sizing, cropping, edge detection, etc.
If you want to learn from the beginning then see tutorials of Bob Powell. It is in C# and quite easy to understand.

Get dominant colors from image discarding the background

What is the best (result, not performance) algorithm to fetch dominant colors from an image. The algorithm should discard the background of the image.
I know I can build an array of colors and how many they appear in the image, but I need a way to determine what is the background and what is the foreground, and keep only the second (foreground) in mind while read the dominant colors.
The problem is very hard especially for gradient backgrounds or backrounds with patterns (not plain)
Isolating the foreground from the background is beyond the scope of this particular answer, but...
I've found that applying a pixelation filter to an image will draw out a really good set of 'average' colours.
Before
After
I sometimes use this approach to derive a pallete of colours with a particular mood. I first find a photograph with the general tones I'm after, pixelate and then sample from the resulting image.
(Thanks to Pietro De Grandi for the image, found on unsplash.com)
The colour summarizer is a pretty sweet spot for info on this subject, not to mention their seemingly free XML Web API that will produce descriptive colour statistics for an image of your choosing, reporting back the following formatted with swatches in HTML or as XML...
what is the average color hue, saturation and value in my image?
what is the RGB colour that is most representative of the image?
what do the RGB and HSV histograms look like?
what is the image's human readable colour description (e.g. dark pure blue)?
The purpose of this utility is to generate metadata that summarizes an
image's colour characteristics for inclusion in an image database,
such as Flickr. In particular this tool is being used to generate
metadata for Flickr's Color Fields group.
In my experience though.. this tool still misses the "human-readable" / obvious "main" color, A LOT of the time. Silly machines!
I would say this problem is closer to "impossible" than "very hard". The only approach to it that I can think of would be to make the assumption that the background of an image is likely to consist of solid blocks of similar colors, while the foreground is likely to consist of smaller blocks of dissimilar colors.
If this assumption is generally true, then you could scan through the whole image and weight pixels according to how similar or dissimilar they are to neighboring pixels. In other words, if a pixel's neighbors (within some arbitrary radius, perhaps) were all similar colors, you would not incorporate that pixel into the overall estimate. If the neighbors tend to be very different colors, you would weight the pixel heavily, perhaps in proportion to the degree of difference.
This may not work perfectly, but it would definitely at least tend to exclude large swaths of similar colors.
As far as my knowledge of image processing algorithms extends , there is no certain way to get the "foreground"; it is only possible to get the borders between objects. You'll probably have to make do with an average, or your proposed array count method. In that, you'll want to give colours with higher saturation a higher "score" as they're much more prominent.

Resources