浏览代码

Added tutorial 03 - colors

Clemens-Alexander Brust 11 年之前
父节点
当前提交
9332a12feb
共有 2 个文件被更改,包括 96 次插入1 次删除
  1. 67 1
      core/tutorial/03_color.md
  2. 29 0
      core/tutorial/progs/03_color.cpp

+ 67 - 1
core/tutorial/03_color.md

@@ -1 +1,67 @@
-# Tutorial 03 - Color Image Operations
+# Tutorial 03 - Color Image Operations
+
+## Architecture
+As mentioned in tutorial 01, color images in memory are represented by instances of
+_ColorImageT<>_
+
+## File input/output
+Because _ImageT<>_ and _ColorImageT<>_ are both subclasses of 
+_GrayColorImageCommonImplementationT<>_, you can use the __reader__ and __writer__ methods
+as explained in tutorial 01.
+
+Note that using a file format that doesn't match the number of channels used by your image
+results in undefined behavior.
+
+## Read/write operations
+For pixel access, the __setPixelQuick__ methods accepts either a matching instance of
+_ColorT<>_ (_Color_ for 8-bit images) or three pixel values:
+
+```c++
+// Using Color
+color_image.setPixelQuick(4, 3, NICE::Color(0, 255, 0));
+
+// Using separate parameters
+color_image.setPixelQuick(4, 3, 0, 255, 0);
+```
+
+To read a pixel, use __getPixelQuick__ with the additional _channel_ parameter:
+
+```c++
+r = color_image.getPixelQuick(4, 3, 0);
+g = color_image.getPixelQuick(4, 3, 1);
+b = color_image.getPixelQuick(4, 3, 2);
+```
+
+## Conversion between color spaces
+NICE can convert between the three-channel color spaces YUV, HSV and RGB.
+The following methods are available:
+
+- __rgbToHSV__
+- __hsvToRGB__
+- __rgbToYUV__
+- __yuvToRGB__
+
+These methods allocate a new _ColorImageT<>_ (you can specify your own if you want to) and
+return a pointer to it:
+
+```c++
+// Use the return value
+NICE::ColorImage my_rgb_image = NICE::hsvToRGB(my_hsv_image);
+
+// Specify your own!
+NICE::ColorImage my_yuv_image(my_hsv_image.width(), my_hsv_image.height());
+NICE::rgbToYUV(my_rgb_image, my_yuv_image);
+``
+
+### Pseudocolors
+While not strictly a conversion, you can enhance a gray image with pseudocolors using the
+built-in function _imageToPseudoColor_. This is a very helpful visualization technique
+if your gray values represent something other than intensity (e.g depth or temperature):
+
+```c++
+// Allocate color image of appropriate dimensions
+NICE::ColorImage color_image(image.width(), image.height());
+
+// Convert to pseudocolor image
+NICE::imageToPseudoColor(image, color_image);
+``

+ 29 - 0
core/tutorial/progs/03_color.cpp

@@ -7,10 +7,39 @@
  * @date 09.03.2014
  * @author Clemens-A. Brust
  */
+ 
+ #include <iostream>
+ #include <core/image/ImageT.h>
+ #include <core/image/ColorImageT.h>
+ #include <core/image/ImageFile.h>
+ #include <core/image/Convert.h>
 
 /*
  * Entry point
  */
 int main(int argc, char** argv) {
+	// Check if enough parameters were supplied
+	if (argc < 3) {
+		std::cout << "USAGE: " << argv[0] << " <input image> <output image>\n";
+		return -1;
+	}
+
+	// These are our file names
+	std::string input_path(argv[1]);
+	std::string output_path(argv[2]);
+
+	// Read file header and display header information
+	NICE::ImageFile source_file(input_path);
+
+	// Read image into memory
+	NICE::Image image;
+	source_file.reader(&image);
+
+	NICE::ColorImage pseudo_image(image.width(), image.height());
+	imageToPseudoColor(image, pseudo_image);
+
+	// Write image to disk
+	NICE::ImageFile dest_image(output_path);
+	dest_image.writer(&pseudo_image);
 	return 0;
 }