0
A
回答
1
这里是一个简单的RGB到HSV转换器的伪代码。它会给UNDEFINED
一个h如果颜色是灰色的阴影,否则H为6介于0和
x = min(R, G, B);
V = max(R, G, B);
if (V == x) {
H = UNDEFINED
S = 0
}
else {
if(R == x) {
f = G - B;
i = 3;
} else if(G == x) {
f = B - R;
i = 5;
} else {
f = R - G;
i = 1;
}
H = i - f /(V - x);
S = (V - x)/V;
}
现在,您可以将您的所有像素和斌它们来构建你的HSV直方图,或者你可以将RGB直方图的每个bin转换为HSV bin。
2
冷杉使用CV :: cvtColor将RGB转换为HSV 然后用CV :: calcHist计算直方图
0
您可以使用 “JavaCV” 库直接从Java访问OpenCV函数:
http://code.google.com/p/javacv/
然后你可以使用我的代码为RGB到HSV比的OpenCV的cvConvert功能较好: http://www.shervinemami.co.cc/colorConversion.html
干杯,
Shervin Emami。
0
这里是做这样的代码:
// Assume SourceImage is a Bitmap ARGB_8888
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap refImage = BitmapFactory.decodeFile(mBaseDir + "some_reference.jpg", options);
Mat hsvRef = new Mat();
Mat hsvSource = new Mat();
Mat srcRef = new Mat(refImage.getHeight(), refImage.getWidth(), CvType.CV_8U, new Scalar(4));
Utils.bitmapToMat(refImage, srcRef);
Mat srcSource = new Mat(SourceImage.getHeight(), SourceImage.getWidth(), CvType.CV_8U, new Scalar(4));
Utils.bitmapToMat(SourceImage, srcSource);
/// Convert to HSV
Imgproc.cvtColor(srcRef, hsvRef, Imgproc.COLOR_BGR2HSV);
Imgproc.cvtColor(srcSource, hsvSource, Imgproc.COLOR_BGR2HSV);
/// Using 50 bins for hue and 60 for saturation
int hBins = 50;
int sBins = 60;
MatOfInt histSize = new MatOfInt(hBins, sBins);
// hue varies from 0 to 179, saturation from 0 to 255
MatOfFloat ranges = new MatOfFloat(0f,180f,0f,256f);
// we compute the histogram from the 0-th and 1-st channels
MatOfInt channels = new MatOfInt(0, 1);
Mat histRef = new Mat();
Mat histSource = new Mat();
ArrayList<Mat> histImages=new ArrayList<Mat>();
histImages.add(hsvRef);
Imgproc.calcHist(histImages,
channels,
new Mat(),
histRef,
histSize,
ranges,
false);
Core.normalize(histRef,
histRef,
0,
1,
Core.NORM_MINMAX,
-1,
new Mat());
histImages=new ArrayList<Mat>();
histImages.add(hsvSource);
Imgproc.calcHist(histImages,
channels,
new Mat(),
histSource,
histSize,
ranges,
false);
Core.normalize(histSource,
histSource,
0,
1,
Core.NORM_MINMAX,
-1,
new Mat());
double resp1 = Imgproc.compareHist(histRef, histSource, 0);
double resp2 = Imgproc.compareHist(histRef, histSource, 1);
double resp3 = Imgproc.compareHist(histRef, histSource, 2);
double resp4 = Imgproc.compareHist(histRef, histSource, 3);
0
首先,你必须使用CV :: cvtColor为RGB图像转换成HSV图像,然后将图像转换为HSV,您可以使用CV :: calcHist来计算HSV直方图。
相关问题
- 1. EmguCV:创建图像直方图 - 错误
- 2. 的Python/Pyside:创建图像直方图
- 3. 从3个不同的直方图创建图像直方图
- 4. 使用matlab /八度音程从rgb转换为hsv图像回rgb
- 5. 如何绘制使用RGB像素值的直方图?
- 6. 如何使用java创建RGB像素值的有效图像
- 7. 创建一个RGB复合SAR图像
- 8. 从RGB数据创建图像?
- 9. 试图用ZedGraph创建直方图
- 10. 使用缓冲图像写RGB图像
- 11. 如何在python中绘制RGB图像的3D直方图
- 12. 从RGB到HSV的OpenCV图像转换阈值痛苦
- 13. 仅在RGB或HSV图像中增加黄色饱和度(Matlab)
- 14. 将图像的颜色空间从RGB转换为HSV
- 15. RGB彩色图像直方图使用OpenCV C++对比度拉伸
- 16. 使用3通道使用opencv创建直方图图表
- 17. 创建直方图OCaml
- 18. 如何创建直方图
- 19. 图像直方图
- 20. 如何使用2d rgb数组在C++中创建图像?
- 21. PIL:创建图像颜色亮度的一维直方图?
- 22. RGB图像
- 23. WinRT中RGB值的直方图绘制
- 24. 如何创建直方图的直方图?
- 25. 使用PHP创建图像
- 26. 用OpenCV通过直方图查找HSV阈值
- 27. OpenCL的图像直方图
- 28. OpenCV - RGB到HSV并回到RGB?
- 29. 用三个灰度PNG文件创建RGB图像 - pypng
- 30. RGB图像::观众