IntensityImage * StudentPreProcessing::stepToIntensityImage(const RGBImage &image) const {
	auto newImage = ImageFactory::newIntensityImage(image.getWidth(), image.getHeight());
	IntensityImageStudent * studentIntensity = dynamic_cast<IntensityImageStudent *>(newImage);
	studentIntensity->convertToIntensityImage(image);

	return studentIntensity;
}
IntensityImageStudent::IntensityImageStudent(const IntensityImageStudent &other) : IntensityImage(other.getWidth(), other.getHeight()), pixelMap(nullptr) {
	const int SIZE = other.getSize();
	if (SIZE > 0) {
		pixelMap = new Intensity[SIZE];
		for (int i = 0; i < SIZE; i++) {
			pixelMap[i] = other.getPixel(i);
		}
	}
}
void IntensityImageStudent::set(const IntensityImageStudent &other) {
	IntensityImage::set(other.getWidth(), other.getHeight());
	delete[] pixel_storage;
	this->pixel_storage = new Intensity[getWidth() * getHeight()];
	int max = getHeight() * getWidth();
	for (int i = 0; i < max; ++i) {
		pixel_storage[i] = other.pixel_storage[i];
	}
}
void IntensityImageStudent::set(const IntensityImageStudent &other) {
	const int	SIZE = other.getSize();
	IntensityImage::set(other.getWidth(), other.getHeight());

	if (SIZE > 0) {
		delete[] pixelMap;
		pixelMap = new Intensity[SIZE];
		for (int i = 0; i < SIZE; i++) {
			pixelMap[i] = other.getPixel(i);
		}
	}
}
Ejemplo n.º 5
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;
}
IntensityImageStudent::IntensityImageStudent(const IntensityImageStudent &other) : IntensityImage(other.getWidth(), other.getHeight()) {
    init_intensity_image();
    for (int y = 0; y < height; y++){
        for (int x = 0; x < width; x++){
            intensity_image[x][y] = other.getPixel(x, y);
        }
    }
}
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;
}
void IntensityImageStudent::set(const IntensityImageStudent &other) {
    Intensity** t_intensity_array = intensity_image;
    int old_height = height;
    width = other.width;
    height = other.height;

    init_intensity_image();
    for (int y = 0; y < height; y++){
        for (int x = 0; x < width; x++){
            intensity_image[x][y] = other.getPixel(x, y);
        }
    }
    delete_intensity_array(t_intensity_array, old_height);
}
IntensityImageStudent::IntensityImageStudent(const IntensityImageStudent &other) : IntensityImage(other.getWidth(), other.getHeight()), pixel_storage(new Intensity[other.getWidth() * other.getHeight()]) {
	int max = other.getHeight() * other.getWidth();
	for (int i = 0; i < max; ++i) {
		pixel_storage[i] = other.pixel_storage[i];
	}
}