I am coding this system in Java, and I would like to split a Mat into its 3 specific color channels so that I may work on each color channel separately.
Ideally when the image is split, its channels will be stored as Mats as well. My end goal is to turn the specific color channels into a hashing code for later image processing.
I am not sure exactly how and was wondering if anyone knew of some functions that could be useful.
Any help would be greatly appreciated. If anything is unclear, let me know. I will gladly explain more.
Asked
Active
Viewed 2,723 times
-4

Michael Maugeri
- 21
- 1
- 3
-
If you want to commission coding services, then this is not the platform. If you want help with your code, then post your code. – Max Vollmer Sep 20 '18 at 15:52
-
Im sorry, i didnt mean to make it sound like im asking for code. I know its it possible to do with python and c++ but i have not seen anything about how to do it in java, and was wondering if anyone had some insights – Michael Maugeri Sep 20 '18 at 16:49
-
1If you have working code in C++ and Python, you should be able to do the same in Java. If you struggle with that, update your question with your attempt, showing both the working code in C++ or Python, and your attempt in Java. Describe where you're stuck and what isn't working as you expect it. – Max Vollmer Sep 20 '18 at 17:07
2 Answers
2
Seems the following code works:
ArrayList<Mat> dst = new ArrayList<>(3);
Core.split(src, dst); // Mat src, ArrayList<Mat> dst

MadHatter
- 301
- 3
- 12
1
There is a cv::split()
function which will split an RGB Mat (or any multi-channel Mat) into an array of single-channel Mats. After splitting you could run a hashing algorithm over the individual channels.
Links to cv::split()
documentation for OpenCV 2 and OpenCV 3.
If your processing is time-sensitive, you could think about whether it might be more efficient to process the channels in-place (ie, interleaved with each other). It depends on how you want to process the channels.

Chungzuwalla
- 1,038
- 6
- 17