Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include "cv.h"
20 
21 namespace mitk {
22 
24 {
25  // there is nothing to do if the image is grayscale already
26  if (image.channels() == 1) { return true; }
27 
28  cv::Mat buffer;
29 
30  cv::cvtColor(image, buffer, CV_RGB2GRAY, 1);
31 
32  // content of buffer should now be the content of image
33  buffer.copyTo(image);
34 
35  return true;
36 }
37 } // namespace mitk
bool OnFilterImage(cv::Mat &image) override
Converts given image to grayscale.
DataCollection - Class to facilitate loading/accessing structured data.