473,465 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

rgb to grayscale

Do anyone know an algorithm which retieves a grey value given certain
rgb value?

I'm needing this kind of function:

$grey = RGBtoGrey('#ffffff');

where $grey (function's return value) should be a real number in [0;1]
range

Googling a little bit, I found an equation which seems to be aplied by
many photo-editor software

(.3*Red) + (.59*Green) + (.11*Blue)= Luminance/brightness

I'm just wondering whether someone here has better ideas...

regards - julian

Jul 4 '06 #1
3 3065
Found some code:

$grey= 0.2125*$rgb['red']+ 0.7154*$rgb['green']+ 0.0721*$rgb['blue'];

--
http://blog.deshot.com
http://www.immersivelounge.com

julian_m wrote:
Do anyone know an algorithm which retieves a grey value given certain
rgb value?

I'm needing this kind of function:

$grey = RGBtoGrey('#ffffff');

where $grey (function's return value) should be a real number in [0;1]
range

Googling a little bit, I found an equation which seems to be aplied by
many photo-editor software

(.3*Red) + (.59*Green) + (.11*Blue)= Luminance/brightness

I'm just wondering whether someone here has better ideas...

regards - julian
Jul 4 '06 #2
C.
julian_m wrote:
Do anyone know an algorithm which retieves a grey value given certain
rgb value?

I'm needing this kind of function:

$grey = RGBtoGrey('#ffffff');
<snip>
(.3*Red) + (.59*Green) + (.11*Blue)= Luminance/brightness

I'm just wondering whether someone here has better ideas...
Although it might need some gamma correction, I would have thought that
the best starting point would be the size of the RGB vector - i.e.
grey = (255/442) * sqrt(red*red + green*green + blue*blue)

You tell us what looks better.

C.

Jul 4 '06 #3

C. wrote:
Although it might need some gamma correction, I would have thought that
the best starting point would be the size of the RGB vector - i.e.
grey = (255/442) * sqrt(red*red + green*green + blue*blue)

You tell us what looks better.
I think both formulas broduce similar results.
Anyway, judge by yourself (Be aware that you're going to open a ~1mb
htm file size, beacause I wanted to do some kind of css-art)

(I'll keep it online only a couple of days)
http://choringa.com.ar/test.htm

regards - julian

Jul 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tjh | last post by:
hi - i'm a bit new to PHP - i've been messing around with the GD2 image functions and was wondering: i see a lot of information about converting a color image to grayscale but i can't figure...
0
by: Java script Dude | last post by:
In trying to speed up my web pages, I want to avoid using multiple images (disabled, hover, nohover). I've currently got opacity working on hover and it looks great and works in IE and Moz. But I...
6
by: QuasiChameleon | last post by:
Hi, I'm trying to create a grayscale image class that reads and writes grayscale Targa format. This works well with smaller images, but corrupts larger images and creates a "Segmentation fault...
8
by: RicercatoreSbadato | last post by:
I'm using bmp.Save() and the bmp is in PixelFormat.Format8bppIndexed. But when I open the image with Gimp, it tells me that the image is RGB and not grayscale.
0
by: tlemcenvisit | last post by:
Hello I translated this code (witch convert an image to grayscale) from C#.NET to C++.NET The C#.NET code is : private void GrayScale(Bitmap b) { BitmapData bmData = b.LockBits(new...
2
by: Harry Simpson | last post by:
I'm having trouble reducing the size of a bitmap programmatically: The file size of the original is 2400k. The picture is 816x1056. 16 million colors i think. I only need grayscale render. ...
2
by: Henry Wu | last post by:
Hi I was at the search for making e.Graphics.DrawImage turn any image to Grayscale, and I found two similar solutions but different ColorMatrix values, what is the difference between the two? Is...
4
by: Brian L. Troutwine | last post by:
I've recently begun to teach myself pygame by making a bunch of small toys. My current toy is cellular automata displayer and I've gotten a bit stuck on the displaying bit. (If automata isn't the...
8
by: platinumhimani | last post by:
-How to convert any image(8,16,24,32 or 64-bit) to 8-bit grayscale -i have tried to convert a 24-bit image to grayscale using setpixel and getpixel functions, in vb.net but i am unable to save...
5
by: Speed | last post by:
Hi, I have a monochrome camera connected to my computer through the USB port. I would like to capture the images from it using C++ and save them as 8-bit grayscale Bitmaps. I am using MS Visual...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.