rgb

Python — change the RGB values of the image and save as a image

雨燕双飞 提交于 2019-12-18 09:24:02
问题 I can read every pixel' RGB of the image already, but I don't know how to change the values of RGB to a half and save as a image.Thank you in advance. from PIL import * def half_pixel(jpg): im=Image.open(jpg) img=im.load() print(im.size) [xs,ys]=im.size #width*height # Examine every pixel in im for x in range(0,xs): for y in range(0,ys): #get the RGB color of the pixel [r,g,b]=img[x,y] 回答1: You can do everything you are wanting to do within PIL. If you are wanting to reduce the value of every

Replacing RGB values in numpy array by integer is extremely slow

我们两清 提交于 2019-12-18 07:04:13
问题 I want to replace the rgb values of a numpy array to single integer representations. My code works but it's too slow, I am iterating over every element right now. Can I speed this up? I am new to numpy. from skimage import io # dictionary of color codes for my rgb values _color_codes = { (255, 200, 100): 1, (223, 219, 212): 2, ... } # get the corresponding color code for the rgb vector supplied def replace_rgb_val(rgb_v): rgb_triple = (rgb_v[0], rgb_v[1], rgb_v[2]) if rgb_triple in _color

Should I use HSV/HSB or RGB and why?

时间秒杀一切 提交于 2019-12-18 06:55:34
问题 I have to detect leukocytes cells in an image that contains another blood cells, but the differences can be distinguished through the color of cells, leukocytes have more dense purple color, can be seen in the image below. What color methode I've to use RGB/HSV ? and why ?! sample image: 回答1: Usually when making decisions like this I just quickly plot the different channels and color spaces and see what I find. It is always better to start with a high quality image than to start with a low

C# Color constant R,G,B values

强颜欢笑 提交于 2019-12-18 03:39:40
问题 Where can I find a list of all the C# Color constants and the associated R,G,B (Red, Green, Blue) values? e.g. Color.White == (255,255,255) Color.Black == (0,0,0) etc... 回答1: Run this program: using System; using System.Drawing; using System.Reflection; public class Test { static void Main() { var props = typeof(Color).GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (PropertyInfo prop in props) { Color color = (Color) prop.GetValue(null, null); Console.WriteLine("Color.{0} =

Why we always divide RGB values by 255?

元气小坏坏 提交于 2019-12-17 22:50:31
问题 Why we always divide our RGB values by 255? I know that the range is from [0-1]. But why only with 255? Can anyone please explain me the concepts of RGB values? 回答1: RGB (Red, Green, Blue) are 8 bit each. The range for each individual colour is 0-255 (as 2^8 = 256 possibilities). The combination range is 256*256*256. By dividing by 255, the 0-255 range can be described with a 0.0-1.0 range where 0.0 means 0 (0x00) and 1.0 means 255 (0xFF). 回答2: This is a bit of a generic question since it can

RGB to HSL conversion

拈花ヽ惹草 提交于 2019-12-17 22:24:37
问题 I'm creating a Color Picker tool and for the HSL slider, I need to be able to convert RGB to HSL. When I searched SO for a way to do the conversion, I found this question HSL to RGB color conversion. While it provides a function to do conversion from RGB to HSL, I see no explanation to what's really going on in the calculation. To understand it better, I've read the HSL and HSV on Wikipedia. Later, I've rewritten the function from the "HSL to RGB color conversion" using the calculations from

How to create a bmp file from byte[] in C#

夙愿已清 提交于 2019-12-17 22:16:58
问题 I have a byte[] array received in TCP Client.The array contains a 24-bit RGB Bitmap file.How to create that bitmap file with given Width ,Height and data? In C++ I use this int WriteBitmapFile(const char *filename, int width, int height, unsigned char *imageData) { FILE *filePtr; // file pointer BITMAPFILEHEADER bitmapFileHeader; // bitmap file header BITMAPINFOHEADER bitmapInfoHeader; // bitmap info header DWORD imageIdx; // used for swapping RGB->BGR unsigned char tempRGB; // used for

What is the efficient way to calculate human eye contrast difference for RGB values?

旧城冷巷雨未停 提交于 2019-12-17 20:27:39
问题 In order to check if two colors in grayscale will be too close to be distinguished by the human eye. I want to be able to generate a warning to the user if 'dangerous' colors are picked. Hence based on the result we can decide if for people with bad eye sight we should change one of the two colors to white or black to enhance the readable contrast. For example the Hex colours #9d5fb0 (purple) and #318261 (green) will turn into almost the same grey tone. Seen in HSB the B value is just 1%

how could i compare colors in java?

守給你的承諾、 提交于 2019-12-17 19:43:22
问题 im trying to make a random color generator but i dont want similar colors to show up in the arrayList public class RandomColorGen { public static Color RandColor() { Random rand = new Random(); float r = rand.nextFloat(); float g = rand.nextFloat(); float b = rand.nextFloat(); Color c = new Color(r, g, b, 1); return c; } public static ArrayList<Color> ColorList(int numOfColors) { ArrayList<Color> colorList = new ArrayList<Color>(); for (int i = 0; i < numOfColors; i++) { Color c = RandColor()

RGB to HSL and back, calculation problems

蓝咒 提交于 2019-12-17 19:22:17
问题 I'm trying to convert RGB to HSL and I also want to convert from HSL to RGB, I have written a class for it but if I do RGB->HSL->RGB to try if it works I get a different value. Example case: if you create a HSLColor object by doing HSLColor MyTestConversion = HSLColor.FromRGB(Colors.Green); and then do Color ExpectedGreenHere = MyTestConversion.ToRGB() you get a different color than Colors.Green while it was the original input so something goes wrong.. This is the code i'm using: public class