如何创建灰度直方图? [英] How to create grayscale histogram?

查看:107
本文介绍了如何创建灰度直方图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里找到了一个代码。但它是RGB。如果我只想要灰度图怎么办?



  Dim  myHistogram 作为 ()=   255 ){} 
对于 i < span class =code-keyword> As 整数 = 0 To picture.Size.Width - 1
j 作为 整数 = 0 picture.Size.Height - 1
Dim c As System.Drawing.Color = picture.GetPixel(i,j)

Dim Temp 作为 = 0
' Temp + = cR
' Temp + = cG
' Temp + = cB



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

下一步
下一步

< br $>






什么是对的?这一个?

 Temp =( 0  3  * cR)+( 0  3  * cR)+( 0  11  * cB)

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





或者这个?

; Temp + =( 0  3  * cR)
Temp + =( 0 3 * cR)
Temp + =( 0 11 * cB)

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

解决方案

引用:

什么是对的?



根据你的代码逻辑,两者都做同样的事情并获得相同的输出。您最好先阅读此主题并首先理解该主题,然后尝试实施。阅读

https://en.wikipedia.org/wiki/Grayscale [ ^ ]

并且写了很多代码项目文章关于这个主题还有

灰度图像点操作 [ ^ ]

简单的直方图显示控件 [ ^ ]

不使用指针将RGB转换为灰度 [<啊ref =http://www.codeproject.com/Tips/314506/Convert-RGB-to-Gray-Scale-without-using-Pointers\"target =_ blanktitle =New Window> ^ ]


I found a code here. but it is in RGB. What if I want grayscale only?

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?

Temp = (0.3 * c.R) + (0.3 * c.R) + (0.11 * c.B)
             
               Temp = CInt(Temp) / 3
               myHistogram(Temp) += 1



or this one?

;Temp += (0.3 * c.R)
             Temp += (0.3 * c.R)
            Temp += (0.11 * c.B)

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

解决方案

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[^]


这篇关于如何创建灰度直方图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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