私はHSV画像を持っており、画像の特定の領域に興味があります。画像を選択して作業し、関心のあるエリアを特定しましたが、チャンネルを分割する方法は正しいとは思いません。私のチャンネルの値は実際の値に近づかない。私が見ている画像の部分はRGBスケールで白い。私はHSVで白が約(0..20)と値(230.255)の彩度を持っていることを知っていますが、プログラムによって印刷された数字はその範囲に近づいていません。私は、Sと-93のほとんどがVのために高い40の低い50を得る。私のチャネル計算は正しいのだろうか?彼らはしかし、すべての白、私のチャンネルの分離計算は正しいですか?
関心領域が中心にある左上のステッカーです:
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 – cuber
あなたのコードで何が起こっているのかを理解するには、一定の(既知の)HSV値のイメージを作成し、アルゴリズム上で試してみてください。 –