Click here to Skip to main content
15,884,040 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I found a code here. but it is in RGB. What if I want grayscale only?

VB
Dim myHistogram As Long() = New Long(255) {}
       For i As Integer = 0 To picture.Size.Width - 1
           For j As Integer = 0 To picture.Size.Height - 1
               Dim c As System.Drawing.Color = picture.GetPixel(i, j)

               Dim Temp As Long = 0
               'Temp += c.R
               'Temp += c.G
               'Temp += c.B
             


               Temp = CInt(Temp) / 3
               myHistogram(Temp) += 1

           Next
       Next




What is right? This one?
C#
Temp = (0.3 * c.R) + (0.3 * c.R) + (0.11 * c.B)
             
               Temp = CInt(Temp) / 3
               myHistogram(Temp) += 1


or this one?
C#
;Temp += (0.3 * c.R)
             Temp += (0.3 * c.R)
            Temp += (0.11 * c.B)

               Temp = CInt(Temp) / 3
               myHistogram(Temp) += 1
Posted
Updated 8-Sep-15 16:13pm
v2
Comments
Sergey Alexandrovich Kryukov 8-Sep-15 22:20pm    
You have only one problem: you probably think that software engineering is done by finding code. If you go away from that, your problems must be solved. Try to solve the problem from scratch.
—SA
NekoNao 8-Sep-15 23:35pm    
I tried those codes and its working . but i don't know and not sure if the data is correct. that's all i need
Patrice T 9-Sep-15 1:49am    
I suspect both are wrong.
You should explain what you want to get as a result.
Member 13341679 28-Sep-17 9:36am    
First i converted the pixel values and stored it in arrays. Then how to show histogram using those values, please help me.
Thanks.

1 solution

Quote:
What is right?

As per your code logic, both do the same and will get the same output. You better read on this topic and understand the subject first and then try to implement. read
https://en.wikipedia.org/wiki/Grayscale[^]
and there are many code project articles written on this topic as well
Point Operations on Grayscale Images[^]
A simple histogram displaying control[^]
Convert RGB to Gray Scale without using Pointers[^]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 9-Sep-15 2:12am    
5ed.
—SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900