Пример #1
0
IntensityImageStudent* RGB_Student_to_Intensity_Image(RGBImageStudent* image) {
	IntensityImageStudent* IntensityImage = new IntensityImageStudent{ image->getWidth(), image->getHeight() };

	RGB* pixel_map = image->getPixels();

	for (int i = 0; i < (image->getWidth() * image->getHeight()); i++) {
		RGB pixel = pixel_map[i];
		
		const int average = (pixel.b + pixel.g + pixel.r) / 3;
		Intensity it(average);
		IntensityImage->setPixel(i, it);
	}
	return IntensityImage;
}
IntensityImageStudent GaussianFilter::applyFilter(const IntensityImage &image)
{
	IntensityImageStudent filteredImage = IntensityImageStudent(image.getWidth() - 2 * radius, image.getHeight() - 2 * radius);
	
	for (int y = 0; y < filteredImage.getHeight(); y++){
		for (int x = 0; x < filteredImage.getWidth(); x++){
			double filteredIntensity = 0.0;
			for (unsigned int i = 0; i < gaussKernel.size(); i++){
				filteredIntensity += gaussKernel[i] * image.getPixel(x + (i % (2 * radius + 1)), y + i / (2 * radius + 1));
			}
			filteredImage.setPixel(x, y, static_cast<Intensity>(filteredIntensity));
		}
	}
	return filteredImage;
}
IntensityImage * StudentPreProcessing::stepToIntensityImage(const RGBImage &image) const {
	int height = image.getHeight();
	int width = image.getWidth();
	int size = height * width;

	IntensityImageStudent* grayImage = new IntensityImageStudent(height, width);

	for (int i = 0; i < size; i++){
		//int gray = ( std::max( std::max(image.getPixel(i).r, image.getPixel(i).g) , image.getPixel(i).b) + std::min( std::min(image.getPixel(i).r , image.getPixel(i).g) , image.getPixel(i).b) ); //Algoritme lichtheid
		int gray = ((image.getPixel(i).r + image.getPixel(i).g + image.getPixel(i).b) / 3); // Algotitme: gemiddelde
		//int gray = (0.21 * image.getPixel(i).r) + (0.72 * image.getPixel(i).g) + (0.07 * image.getPixel(i).b); //Algortime helderheid

		grayImage->setPixel(i, gray);
	}

	return grayImage;
}