Forked from Vogeslu/Bildverarbeitung-Umwandlungsbeispele.cpp
Created
October 20, 2021 07:37
-
-
Save Molham321/825824c828232b401a6ee1804fc43fe3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "CImage.h" | |
#include "CColor.h" | |
using namespace bvme; | |
void grayscaleImage(CImage image) { | |
CColor tempPoint; | |
int combinedColors; | |
for (int x = 0; x < image.getHeight(); x++) | |
for (int y = 0; y < image.getWidth(); y++) { | |
tempPoint = image.getPointValue(x, y); | |
combinedColors = (tempPoint.getRed() + tempPoint.getGreen() + tempPoint.getBlue()) / 3; | |
tempPoint.setRed(combinedColors); | |
tempPoint.setGreen(combinedColors); | |
tempPoint.setBlue(combinedColors); | |
image.setPointValue(x, y, tempPoint); | |
} | |
} | |
void binaryImage(CImage image, bool inversed) { | |
CColor tempPoint; | |
int combinedColors; | |
for (int x = 0; x < image.getHeight(); x++) | |
for (int y = 0; y < image.getWidth(); y++) { | |
tempPoint = image.getPointValue(x, y); | |
combinedColors = (tempPoint.getRed() + tempPoint.getGreen() + tempPoint.getBlue()) / 3; | |
if (combinedColors > (255 / 2)) combinedColors = inversed ? 0 : 255; | |
else combinedColors = inversed ? 255 : 0; | |
tempPoint.setRed(combinedColors); | |
tempPoint.setGreen(combinedColors); | |
tempPoint.setBlue(combinedColors); | |
image.setPointValue(x, y, tempPoint); | |
} | |
} | |
void binaryImageWithTreshold(CImage image, bool inversed, int treshold) { | |
CColor tempPoint; | |
int combinedColors; | |
for (int x = 0; x < image.getHeight(); x++) | |
for (int y = 0; y < image.getWidth(); y++) { | |
tempPoint = image.getPointValue(x, y); | |
combinedColors = (tempPoint.getRed() + tempPoint.getGreen() + tempPoint.getBlue()) / 3; | |
if (combinedColors > treshold) combinedColors = inversed ? 0 : 255; | |
else combinedColors = inversed ? 255 : 0; | |
tempPoint.setRed(combinedColors); | |
tempPoint.setGreen(combinedColors); | |
tempPoint.setBlue(combinedColors); | |
image.setPointValue(x, y, tempPoint); | |
} | |
} | |
void highlightColor(CImage image, std::string color) { | |
CColor tempPoint; | |
int combinedColors; | |
for (int x = 0; x < image.getHeight(); x++) | |
for (int y = 0; y < image.getWidth(); y++) { | |
tempPoint = image.getPointValue(x, y); | |
combinedColors = ((color != "red" ? tempPoint.getRed() : 0) + (color != "green" ? tempPoint.getGreen() : 0) + (color != "blue" ? tempPoint.getBlue() : 0)) / 2; | |
if (color != "red") tempPoint.setRed(combinedColors); | |
if (color != "green") tempPoint.setGreen(combinedColors); | |
if (color != "blue") tempPoint.setBlue(combinedColors); | |
image.setPointValue(x, y, tempPoint); | |
} | |
} | |
void excludeColor(CImage image, std::string color) { | |
CColor tempPoint; | |
int combinedColors; | |
for (int x = 0; x < image.getHeight(); x++) | |
for (int y = 0; y < image.getWidth(); y++) { | |
tempPoint = image.getPointValue(x, y); | |
combinedColors = ((color == "red" ? 0 : tempPoint.getRed()) + (color == "green" ? 0 : tempPoint.getGreen()) + (color == "blue" ? 0 : tempPoint.getBlue())) / 2; | |
if (color == "red") tempPoint.setRed(combinedColors); | |
if (color == "green") tempPoint.setGreen(combinedColors); | |
if (color == "blue") tempPoint.setBlue(combinedColors); | |
image.setPointValue(x, y, tempPoint); | |
} | |
} | |
void invertImage(CImage image) { | |
CColor tempPoint; | |
int combinedColors; | |
for (int x = 0; x < image.getHeight(); x++) | |
for (int y = 0; y < image.getWidth(); y++) { | |
tempPoint = image.getPointValue(x, y); | |
tempPoint.setRed(255 - tempPoint.getRed()); | |
tempPoint.setGreen(255 - tempPoint.getGreen()); | |
tempPoint.setBlue(255 - tempPoint.getBlue()); | |
image.setPointValue(x, y, tempPoint); | |
} | |
} | |
void lightenImage(CImage image, float value) { | |
CColor tempPoint; | |
int combinedColors; | |
int lightenValue = 255 * value; | |
for (int x = 0; x < image.getHeight(); x++) | |
for (int y = 0; y < image.getWidth(); y++) { | |
tempPoint = image.getPointValue(x, y); | |
tempPoint.setRed(tempPoint.getRed() + lightenValue); | |
tempPoint.setGreen(tempPoint.getGreen() + lightenValue); | |
tempPoint.setBlue(tempPoint.getBlue() + lightenValue); | |
if (tempPoint.getRed() > 255) tempPoint.setRed(255); | |
if (tempPoint.getGreen() > 255) tempPoint.setGreen(255); | |
if (tempPoint.getBlue() > 255) tempPoint.setBlue(255); | |
image.setPointValue(x, y, tempPoint); | |
} | |
} | |
void darkenImage(CImage image, float value) { | |
CColor tempPoint; | |
int combinedColors; | |
int lightenValue = 255 * value; | |
for (int x = 0; x < image.getHeight(); x++) | |
for (int y = 0; y < image.getWidth(); y++) { | |
tempPoint = image.getPointValue(x, y); | |
tempPoint.setRed(tempPoint.getRed() - lightenValue); | |
tempPoint.setGreen(tempPoint.getGreen() - lightenValue); | |
tempPoint.setBlue(tempPoint.getBlue() - lightenValue); | |
if (tempPoint.getRed() < 0) tempPoint.setRed(0); | |
if (tempPoint.getGreen() < 0) tempPoint.setGreen(0); | |
if (tempPoint.getBlue() < 0) tempPoint.setBlue(0); | |
image.setPointValue(x, y, tempPoint); | |
} | |
} | |
int main() | |
{ | |
{ | |
CImage imageRose("Images/rose.bmp"); | |
darkenImage(imageRose, 0.6); | |
imageRose.showImage(); | |
} | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment