I want to : 1-Read an image. 2-Convert it to HSV and take only the Hue part. 3-divide the Hue plane into 16 blocks. 4-Calculate for each block the Histogram and extract a feature based on it (maybe the dominant color). 5-Build a feature Vector. 6-Compare the vector with itself.
Till know i'm stuck at dividing the image into 16 blocks. The divide section is actually diving my image into 25 blocks rather than 16. so How can i divide my image into 16 blocks and process each one of them?
Code:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
int main()
{
cv::Mat src;
/// Load image
src = cv::imread( "path", 1 );
if( !src.data )
{
std::cout << "image not found" << std::endl;
return -1;
}
/// convert the image to HSV space
cv::Mat hsv;
cv::cvtColor( src, hsv, COLOR_BGR2HSV );
/// Separate the image in 3 places (H,S,V)
cv::vector<Mat> hsv_channels;
cv::split( src, hsv_channels );
/// Take only the hue channel
cv::Mat hue = hsv_channels[0];
/// divide into 16 blocks
int tileHeight = hue.rows/4;
int tileWidth = hue.cols/4;
for (int r = 0; r < hue.rows; r += tileHeight)
{
for (int c = 0; c < hue.cols; c += tileWidth)
{
cv::Mat tile = hue(cv::Range(r, min(r + tileHeight, hue.rows)),
cv::Range(c, min(c + tileWidth, hue.cols)));
// tile processing here
// .............
}
}
cv::waitKey(0);
return 0 ;
}