规范化的RGb(传递浮点数) [英] Normalized RGb(passing floating point number)

查看:321
本文介绍了规范化的RGb(传递浮点数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI
我正在尝试将图像转换为规范化的rgb,现在我的代码是。 Folowing代码在循环中等于图像尺寸



HI I am trying to convert an image into normalized rgb now my code is. Folowing code is in the loop equal to image dimensions

     Color color = grayScale.GetPixel(xCoordinate, yCoordinate);
                    sum = (color.R + color.G + color.B);
                    red = color.R;
                    green = color.G;
                    blue = color.B;

                   
                        redColor =  (double)red/ (double)(sum);
                        greenColor = (double)green / (double)(sum);
                        blueColor = (double)blue /(double)(sum);

//Color.FramArgb only accepts int and my val;ues are in double since they are normalized b/w 0-1 
                        grayScale.SetPixel(xCoordinate, yCoordinate,          Color.FromArgb(redColor, greenColor,blueColor));
                     
                    }



现在问题是我怎么能传递这个参数,因为我无法将它转换成int因为我会失去我的价值。?

无论如何,


now the problem is how can i pass this argument since i cannot convert it to int because i would loose my value.?
Thanks anyways

推荐答案

乘以255:

multiply by 255:
grayScale.SetPixel(xCoordinate, yCoordinate, Color.FromArgb((int)(255*redColor), (int)(255*greenColor),(int)(255*blueColor)));


GetPixel是WAY慢下来在这里搜索文章图像处理傻瓜。是的,你没有看错。这些文章中有一个例子,它演示了一种将图像转换为灰度的快得多的方法。
GetPixel is WAY to slow. Search the articles here for "Image processing for dummies". Yes, you read that right. There's an example in those articles that demonstrates a far faster method of converting an image to grayscale.


这篇关于规范化的RGb(传递浮点数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆