Skip to content

Image Processing

Grayscale

$author:   Jin-Wen (Ed) Lai           
$date:     Mar. 2018
$keywords: image, processing, rgb, colormap, grayscale

An implementation of digital image processing to convert RGB image or colormap to grayscale (rgb2gray).

Content

Requirements

  • OpenCV
    # apt-get install libopencv-dev
    # apt-get install cmake
    

Programming

  • create Grayscale.cpp

```cpp #include #include #include #include

using namespace cv;

int main( int argc, char** argv ) { Mat image; image = imread("../../lena.png");

Mat grayscale;
cvtColor( image, grayscale, CV_BGR2GRAY );
imwrite( "lena_`grayscale.png", grayscale );
return 0;

} ```

CMakeLists

  • Create CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project( Grayscale )
find_package( OpenCV REQUIRED )
add_executable( Grayscale Grayscale.cpp )
target_link_libraries( Grayscale ${OpenCV_LIBS} )

Running

  • Issue below commands
cmake .
make
  • Result
Original Grayscale

Note:

  • The canvas tag is not supported in Internet Explorer 8 and earlier versions.
  • Try to Refresh this Page (Press F5) if you cannot see the result.

Reference: