소스 검색

Added sample code and sample image to second tutorial

Clemens-Alexander Brust 11 년 전
부모
커밋
03caa89ca1
3개의 변경된 파일74개의 추가작업 그리고 0개의 파일을 삭제
  1. 13 0
      core/tutorial/02_grayscale.md
  2. 57 0
      core/tutorial/progs/02_grayscale.cpp
  3. 4 0
      core/tutorial/sample_02.pgm

+ 13 - 0
core/tutorial/02_grayscale.md

@@ -38,3 +38,16 @@ To calculate an image's histogram, use the constructor:
 ``` c++
 ``` c++
 NICE::Histogram histogram(image, 0, 256);
 NICE::Histogram histogram(image, 0, 256);
 ```
 ```
+
+### Equalization
+The sample code uses the pattern from the beginning and the _Histogram_ class to
+optimize the source image's contrast.
+
+The transformation works by computing the cumulative histogram like this:
+
+```c++
+NICE::IntVector* cumulative_histogram = histogram.cumulative();
+```
+
+It is then scaled down to make it a homogenuos transform from [0,255] to [0,255].
+The histogram of the resulting image *should* resemble a uniform distribution.

+ 57 - 0
core/tutorial/progs/02_grayscale.cpp

@@ -8,9 +8,66 @@
  * @author Clemens-A. Brust
  * @author Clemens-A. Brust
  */
  */
 
 
+#include <iostream>
+#include <string>
+#include <core/image/ImageT.h>
+#include <core/image/Histogram.h>
+
 /*
 /*
  * Entry point
  * Entry point
  */
  */
+
 int main(int argc, char** argv) {
 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);
+
+	// Calculate cumulative histogram
+	NICE::Histogram histogram(image, 0, 256);
+	NICE::IntVector* cumulative_histogram = histogram.cumulative();
+
+	// The largest value in the cumulative histogram is the total pixel count
+	// of the source image. We need to scale this down to 255 to match to pixel
+	// format of the image.
+	double factor = 255.0/(double)(image.width()*image.height());
+
+	// Transform using our pattern
+	for(int x = 0; x < image.width(); x++) {
+		for(int y=0; y < image.height(); y++) {
+			// This is the old gray value
+			Ipp8s pixel = image.getPixelQuick(x, y);
+
+			// We use it as and index into the cumulative histogram to
+			// computer the new one. This has to be scaled appropriately
+			// using our precomputed factor.
+			double new_pixel_f =
+					((double)cumulative_histogram->get(pixel))*factor;
+
+			// The pixel format is 8-bit integer, so we have to convert
+			// the result
+			Ipp8s new_pixel = (Ipp8s)(new_pixel_f * 255.0);
+
+			// ..and save it
+			image.setPixelQuick(x, y, new_pixel);
+		}
+	}
+
+
+	// Write image to disk
+	NICE::ImageFile dest_image(output_path);
+	dest_image.writer(&image);
 	return 0;
 	return 0;
 }
 }

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 4 - 0
core/tutorial/sample_02.pgm


이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.