I would like to load 2 jpg images with Gimp Python. Then the pictures should be compared pixel by pixel. If the pixel in picture 2 has a certain rgb value, the pixel in picture 1 should be colored. Before that, a user input should be made in which the start value can be entered.
I'm unsure if gimp python can do it all?
Primarily I search the commands:
- Load a picture
- User input
- Load pixel RGB value
- Change pixel RGB value
- Save image
Many thanks in advance
I first tried c ++, but handling pictures is not that easy. My teacher advised me to gimp. Schematic it should look like this:
#include <iostream>
using namespace std;
int main()
{
unsigned long long int startPixelBreite;
unsigned long long int startPixelHoehe;
int prozent;
//EDIT: Load pic 1
//EDIT: load pic 2
//startpixel bestimmen durch usereingabe
cout << "Startpixel Höhe" << endl;
cin >> startPixelBreite;
cout << "Startpixel Höhe" << endl;
cin >> startPixelHoehe;
//breite + Höhe von bild 1 auslesen
endpixelBreite = startPixelBreite + bildBreite1
endpixelHoehe = startPixelHoehe + bildHoehe1
//ANFANG: Schleife für pixelzeile
aktuellerPixelX = 0;
//ANFANG schleife für pixel pixelreihe
//pixelfarbebild1 einlesen
/*
pixelfarbebild1[0] = //rot
pixelfarbebild1[1] = //grün
pixelfarbebild1[2] = //blau
*/
//pixelfarbebild2 einlesen
/*
pixelfarbebild2[0] = //rot
pixelfarbebild2[1] = //grün
pixelfarbebild2[2] = //blau
*/
if (aktuellerPixelX > startPixelBreite & aktuellerPixelX< endpixelBreite)
{
if pixelfarbe[0] = 102 & pixelfarbe[1] = 102 & pixelfabre [2] = 102 //grau
{
prozent = 60
neuerpixel[0] = (pixelfarbebild1[0]*prozent-100*pixelfarbebild1[0]+100*pixelfarbebild2[0])/prozent //rot
neuerpixel[1] = (pixelfarbebild1[1]*prozent-100*pixelfarbebild1[1]+100*pixelfarbebild2[1])/prozent //grün
neuerpixel[2] = (pixelfarbebild1[2]*prozent-100*pixelfarbebild1[2]+100*pixelfarbebild2[2])/prozent //blau
}
else if pixelfarbe[0] = 237 & pixelfarbe[1] = 136 & pixelfabre [2] = 196 //pink
{
prozent = 70
neuerpixel[0] = (pixelfarbebild1[0]*prozent-100*pixelfarbebild1[0]+100*pixelfarbebild2[0])/prozent //rot
neuerpixel[1] = (pixelfarbebild1[1]*prozent-100*pixelfarbebild1[1]+100*pixelfarbebild2[1])/prozent //grün
neuerpixel[2] = (pixelfarbebild1[2]*prozent-100*pixelfarbebild1[2]+100*pixelfarbebild2[2])/prozent //blau
}
else if pixelfarbe[0] = 175 & pixelfarbe[1] = 167 & pixelfabre [2] = 172 //hellgrau
{
prozent = 67
neuerpixel[0] = (pixelfarbebild1[0]*prozent-100*pixelfarbebild1[0]+100*pixelfarbebild2[0])/prozent //rot
neuerpixel[1] = (pixelfarbebild1[1]*prozent-100*pixelfarbebild1[1]+100*pixelfarbebild2[1])/prozent //grün
neuerpixel[2] = (pixelfarbebild1[2]*prozent-100*pixelfarbebild1[2]+100*pixelfarbebild2[2])/prozent //blau
}
else
{
neuerpixel[0] = pixelfarbebild2[0] //rot
neuerpixel[1] = pixelfarbebild2[1] //grün
neuerpixel[2] = pixelfarbebild2[2] //blau
}
//pixel in bild schreiben
}
else{
neuerpixel[0] = pixelfarbebild2[0] //rot
neuerpixel[1] = pixelfarbebild2[1] //grün
neuerpixel[2] = pixelfarbebild2[2] //blau
}
aktuellerPixelX++;
//ENDE schleife für pixel pixelreihe
//ENDE: Schleife für pixelzeile
//ausgabe
}
In matlab / octave this is very straightforward. No need for gimp, and integrates well with C++ if you absolutely must have c++ code integration. E.g., say you want to change Image2 pixels to R: 50, G: 60, B:70, whenever Image1 has pixels R:10, G: 20, B:30. Then:
You can read and compare images similarly in python using scipy.imread, numpy, etc if you prefer python over matlab. No need for gimp.
PS. As you may have realised from my sarcastic code comments, please consider writing code exclusively in English when asking an international audience such as SO. It's very frustrating and tiresome to read such 'mixed' code and therefore it comes across as rude and inconsiderate; (and this holds true even for someone like me personally, despite the fact that I happen to speak a reasonable amount of German and English is not my native language.). Not to mention that you risk needlessly limiting your audience to only German speakers by doing so!