Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Block process an image?

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 ;


}

Block process an image?

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 now 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 ;


}

Block process an image?

I want to : 1-Read :

  1. Read an image. 2-Convert image.
  2. Convert it to HSV and take only the Hue part. 3-divide part.
  3. Divide the Hue plane into 16 blocks. 4-Calculate blocks.
  4. Calculate for each block the Histogram and extract a feature based on it (maybe the dominant color). 5-Build colour).
  5. Build a feature Vector. 6-Compare Vector.
  6. Compare the vector with itself.

Till Untill now i'm stuck at dividing the image into 16 blocks. blocks. The divide section is actually diving my image into 25 blocks rather than 16. so How 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 ;


}