Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkConvertGrayscaleOpenCVImageFilter.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include <opencv2/imgproc.hpp>
16 
17 namespace mitk {
18 
20 {
21  // there is nothing to do if the image is grayscale already
22  if (image.channels() == 1) { return true; }
23 
24  cv::Mat buffer;
25 
26  cv::cvtColor(image, buffer, CV_RGB2GRAY, 1);
27 
28  // content of buffer should now be the content of image
29  buffer.copyTo(image);
30 
31  return true;
32 }
33 } // namespace mitk
bool OnFilterImage(cv::Mat &image) override
Converts given image to grayscale.
DataCollection - Class to facilitate loading/accessing structured data.
mitk::Image::Pointer image