如何将图像转换为目标图像?源图像为深灰色,目标图像为黑色,灰色和白色

时间:2019-05-30 22:51:22

标签: opencv

源图像,它是来自opencv的灰度转换结果。

cvtColor(img,COLOR_BGR2GRAY);

enter image description here

如何将这张图片转换为目标: enter image description here

1 个答案:

答案 0 :(得分:0)

histogram equalization函数可用于平均分布强度值范围。

enter image description here

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace cv;
using namespace std;

/**  @function main */
int main( int argc, char** argv )
{
  Mat src, dst;

  char* source_window = "Source image";
  char* equalized_window = "Equalized Image";

  /// Load image
  src = imread( "path_to_image", CV_LOAD_IMAGE_GRAYSCALE );

  /// Convert to grayscale
  //cvtColor( src, src, CV_BGR2GRAY );

  /// Apply Histogram Equalization
  equalizeHist( src, dst );

  /// Display results
  namedWindow( source_window, CV_WINDOW_AUTOSIZE );
  namedWindow( equalized_window, CV_WINDOW_AUTOSIZE );

  imshow( source_window, src );
  imshow( equalized_window, dst );

  /// Wait until user exits the program
  waitKey(0);

  return 0;
}