【发布时间】:2017-02-23 20:11:23
【问题描述】:
我有一张 HSV 图像,我对图像的某个区域感兴趣。我已经开始选择图像并确定我感兴趣的区域,但我认为我分离频道的方式不正确。我的通道值不接近它们的实际值。我正在查看的图像部分是 RGB 比例的白色。我知道在 HSV 中,白色的饱和度约为 (0..20) 和值 (230..255),但程序打印出的数字并未接近该范围。我得到 S 的高 40 低 50 和 -93 主要是 V。我的通道计算是否正确?
public void splitChannels() {
Mat firstImage = Imgcodecs.imread("firstImage.jpg");
int width = 20;
int height = 20;
Rect roi = new Rect(120, 160, width, height);
Mat smallImg = new Mat(firstImage, roi);
int channels = smallImg.channels();
System.out.println("small pixels:" + smallImg.total());
System.out.println("channels:" + smallImg.channels());
int totalBytes = (int)(smallImg.total() * smallImg.channels());
byte buff[] = new byte[totalBytes];
smallImg.get(0, 0, buff);
for (int i=0; i< height; i++) {
// stride is the number of bytes in a row of smallImg
int stride = channels * width;
for (int j=0; j<stride; j+=channels) {
//I don't know if these channels calculations are correct.
int h = buff[(i * stride) + j];
int s = buff[(i * stride) + j + 1];
int v = buff[(i * stride) + j + 2];
// Do something with the hsv.
System.out.println("s: "+ s + " v: " + v);
}
}
}
这是我的图片:
感兴趣的区域是中心的左上角贴纸,不过它们都是白色的。
它为此程序打印出来的 HSV 是:
h: 99 s: 78 v: 57
h: 97 s: 76 v: 55
h: 101 s: 77 v: 57
h: 101 s: 77 v: 57
h: 103 s: 79 v: 59
h: 103 s: 79 v: 59
h: 103 s: 79 v: 59
h: 102 s: 78 v: 58
h: 100 s: 76 v: 58
h: 99 s: 75 v: 57
h: 98 s: 74 v: 56
h: 98 s: 74 v: 56
h: 98 s: 74 v: 54
h: 99 s: 75 v: 55
【问题讨论】:
-
可以分享图片吗?
-
更新我的问题我会添加他们@RossPresser
-
了解代码中发生的情况的一个好方法是创建一个恒定(已知)HSV 值的图像,并在您的算法上进行尝试。
-
好的,我刚刚尝试了一张白色图像,值在
h: 122 s: 63 v: 67@DaveS 左右 -
据我所知,这并不接近白色图像的正确 HSV 值。白色应该在该范围内有一个
Saturation(0..20) and Value(230..255)。 @DaveS这就是为什么我想知道我的计算是否错误地获得了这些值。