Click here to Skip to main content
15,889,462 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Convert RGB to Gray Scale Without Using Pointers

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
13 Jan 2012CPOL 10.1K   1
This is an alternative to "Convert RGB to Gray Scale Without Using Pointers".

I'm afraid there are better ways of doing this, based on the power of the framework; in this case, ColorMatrix is the tool to use. See example here[^]. (Warning: Make sure to use correct matrix elements, corresponding to the coefficients mentioned in the tip/trick).

:)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Belgium Belgium
I am an engineer with a background in electronics, software and mathematics.

I develop technical software, both for embedded systems and for desktop equipment. This includes operating systems, communication software, local networks, image processing, machine control, automation, etc.

I have been using all kinds of microcontrollers and microprocessors (Intel 4004/8080/8051/80386/Pentium, Motorola 680x/680x0/ColdFire/PowerPC, Microchip PIC, Altera NIOS, and many more), lots of programming languages (all relevant assemblers, Fortran, Basic, C, Java, C#, and many more), and different operating systems (both proprietary and commercial).

For desktop applications and general development tools I have been using both UNIX systems and Mac/MacOS for many years, but I have switched to x86-based PCs with Windows, Visual Studio and the .NET Framework several years ago.

I specialize in:
- cross-platform development (making software that runs on diverse hardware/OS combinations)
- instruction set simulation
- improving software performance, i.e. making sure the software runs the job at hand in as short a time as possible on the given hardware. This entails algorithm selection, implementation design, accurate measurements, code optimisation, and sometimes implementing virtual machines, applying SIMD technology (such as MMX/SSE), and more.

Comments and Discussions

 
GeneralI have accepted your alternative. But the essence of the top... Pin
Grasshopper.iics13-Jan-12 18:32
Grasshopper.iics13-Jan-12 18:32 
I have accepted your alternative. But the essence of the topic is "Simple Conversion". Using pointers with unsafe is more efficient than color matrix. But the mentioned code here ( in main tip) is much simpler and the same loop can be used to produce binary image, edge detection, any other transform. Smile | :)

Also the gray scale value can be obtained just by taking the average of R,G,B and replace it in all three channels.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.