Given a generated histogram that I got from an image I was wondering if there was any optimized way to generate a mask. Below I have added in 3 different images: the reference to use, the histogram data of the reference, and the main image that I would like to mask. I know that I could do this by each pixel and vary the color information by a certain percentage so that I would be able to get colors with lighting changes as well.
The basic idea is to find a color, given by the histogram data and within a certain range, and if it finds anything then to make it black. If it doesn't find anything then the color will be white.
Any advice would be greatly appreciated.
Reference image:
Histogram values:
Image to mask:
What you want is to mask a color in a certain range, this is what you should try with the code i posted here :
In my example, it is used to make it transparent, if you want to make it black, just skip the cvNot() step...
Making a color completely transparent in OpenCV
Hope it helped,
Julien
PS : i've just seen that you were the one who asked the question I answered about how to make a color transparent: the problem here is exactly the same... just adapt a lil bit the answer..
1) Convert your image RGB -> HSV : cvtColor()
2) Generate your histogram : calcHist()
3) Find the maximum in your Hue histogram : minMaxLoc()
4) Select thresholds around this maximum : your function
5) Use them to select only the color you want : inRange()
6) Put this mask in black : your function (a very simple way would be to remove all the RGB components on the mask) : your function
Try to use template matching approaches instead of histogram, for example, normalized cross correlation http://www.mathworks.com/products/demos/image/cross_correlation/imreg.html.
Related
Hello I have some confusions about extracting data from images and I know lots of image processing experts are in here. I would appreciate if someone can help me realize some concepts. how we can get some information,like intensity of a the light source from images? I know we can extract RGB value, but these values are associated with the surfaces and not with the light source spectra (I am talking about white light source with different spectra not monochromatic wavelength). is there a way to extract some information of the light source from images with matlab? should we convert color images to greyscale images? if yes, can you explain how grey scale giving us intensity (or other photometric data)? I know about HDRI so feel free to refer to them
You can in each language get the red (=r), green (=g), blue (=b) and alpha bytes of each pixel of an image. The internet give you many formulas to calculate the different possible values on base of the amount of red, green and blue.
For example this link provides how to calculate the hsv value with r, g and b.
It is more or less a question HOW (language, libraries) you want to do it.
I am trying to clip a raster so that the clipped raster would have the same minimum and maximum values for the color band as the original raster.
For example if i clip the raster with this command:
create table clipped AS SELECT
ST_Clip(rast,ST_MakePolygon(ST_GeomFromText ('LINESTRING(424920
7370964,
424920 7371476,425432 7371476,425432 7370964,424920 7370964) ')) ) FROM original;
I get the following result:
So the clipped raster has band minium value as 0 and maxium value as 20. Instead of that, i want it to be exactly same as the 'original' raster: from 0 to 33.
I am new for PostGIS, but i have tried to find an answer for a while to this question but i haven't found anything. I have tried the functions like ST_Reclass but with no success. What is the proper way to do this with PostGIS?
Why is that happening?
The reason that your range changes is because your maximum value (33 in your case) is not contained within the area you clipped. This is not a bad thing, its just a fact. It's not a PostGIS thing, its just a clipping thing.
Can we find a solution?
I'm guessing that the real problem you want solved is that the two rasters look very different in QGIS. That's really easy to fix! I'll show you how with some example data.
Exmaple Data
Here's what we're starting with:
Link to image because I don't have enough rep to embed an image yet, I guess...
Double click on the "clipped" layer to open up the "Layer Properties" window and select the Style tab from the list on the left side of the window
Locate the text window for "Max" and change it to 33 to match your original raster. This picture may help. It's worth noting that you may run into a case where your Minimum is different in the clipped raster as well like it is here. You can adjust that in the same fashion.
Apply your changes and watch them work!
I have a color box array as below.
Now, I want to do numbering the array as below picture.
In order to do numbering, I just put texts on the array elements, manually.
I would like to do numbering automatically.
Can anyone give me a solution how to do numbering the array elements automatically?
Thank you in advance.
I would add 2D numerical array. Resize it to have a size of the color box, make it transparent and show there what I wanted.
Please download example code from my dropbox (LV 15): https://www.dropbox.com/s/wevy0sgqnhgvh8p/Example%20on%20color%20box.vi?dl=0
and LV11:
https://www.dropbox.com/s/zmrg66fai8cg3w6/Example%20on%20color%20box_11.vi?dl=0
I'd use a different approach.
1) Build a cluster containing both color box and a transparent number indicator
2) Put the cluster in a 2D array
Make a typedef of the cluster if you want.
In this way you can easily play with colors and numbers all around your program.
Lets say we have 2 images in YUV422 format and assume that the second image Y field of value 0x10 is being transparent and merged on to the first one with Cb and Cr overwritten.
The product of such merge results in ugly borders (divided pixel line efect) of solid shapes. Is there a way to produce a combination of values on borders, so the transition is smooth?
This problem is not specific to YUV4:2:2:, but occurs whenever binary transparency is used. The best solution is to use a four-channel image and include an alpha channel. Essentially, an alpha channel represents the "degree of opaque-ness" of each pixel. When two images with alpha-channels overlap, alpha blending produces a result that looks much better.
If you're stuck with YUV4:2:2 or can't add alpha channel, you could try smooth the transition the two images with a low-pass filter. This will hurt the definition of your edges, but might look better than doing nothing.
I'm putting in a function which will allow a user to input a color (eg: purple) and it will change the look of their profile to be purple. It's interpreted from text into a 'Color' class which stores them inside itself as RGB numbers (int for red, one for green and other for blue). What i don't know how to do is logically turn these three numbers into another 3 which will make a readable colour.
Can anyone help me on how to do this?
Joe
If I'm interpreting your question correctly, you're looking for a readable text color after someone has chosen a background theme color. This was answered in an older question:
Good text foreground color for a given background color
Obviously, there's not a name for every possible RGB combination! Presumably you want to find a nearby combination that you have specified a name for?
So really all you need is a way of defining how "close" one RGB is to another. For simplicity, I would suggest Euclidean-distance-squared, i.e. (R2-R1)^2 + (G2-G1)^2 + (B2-B1)^2. Then all you need to do is iterate through all your "named" colours, and find the one with the smallest distance.
You could look at the rgb.txt file that comes with X11.
A parser for that could provide a translation between those strings and the RGB values wouldn't be terribly hard to build and would likely do what you're looking for.
As others already say, there are 16.7 million possible combinations, all of which obviously can't have a defined name.
You're not going into detail about your use case, but if you want to make it end user friendly, how about using percentages?
80% red, 50% green, 23% blue
this is perfectly understandable for a non-technical person as well. You would limit (from 256^3 to 100^3) the number of possibilities if you use integer percentage values, but not as much as confining the user to a fixed palette of named colours.