Add invert feature for combined channel images

This commit is contained in:
Matt McWilliams 2026-03-01 14:03:06 -05:00
parent 01e38ea94d
commit ca7d02a3a5
3 changed files with 39 additions and 4 deletions

View File

@ -24,6 +24,7 @@ class FilmoutImage {
Mat red;
Mat green;
Mat blue;
Mat inverted;
Mat combineChannel(Mat& data, Mat& empty, uint8_t i);
String getExtLower (const string& path);
void writeChannel(const string& path, Mat& channel);
@ -31,6 +32,7 @@ class FilmoutImage {
public:
void loadChannels(const string& path, bool invert);
void writeChannels(const string& red_path, const string& green_path, const string& blue_path);
void invertMode(const string& path, const string& inverted_path);
void releaseChannels();
};

View File

@ -126,3 +126,25 @@ string FilmoutImage::getExtLower (const string& path) {
}
return "";
}
void FilmoutImage::invertMode(const string& path, const string& inverted_path) {
string located_path = samples::findFile(path);
string ext = getExtLower(located_path);
if (ext == "dpx") {
//NOT WORKING
cout << "{ \"dpx\" : \"" << path << "\" }" << endl;
} else {
loaded = imread(located_path, IMREAD_COLOR);
//cout << "{ \"loaded\" : \"" << located_path << "\" }" << endl;
}
if (loaded.empty()) {
cerr << "{ \"error\" : \"" << path << " empty\" }" << endl;
} else {
inverted = Mat::zeros(Size(loaded.cols, loaded.rows), CV_8UC3);
bitwise_not(loaded, inverted);
imwrite(inverted_path, inverted);
loaded.release();
inverted.release();
}
}

View File

@ -41,7 +41,15 @@ int rgbMode (const string& path, string red, string green, string blue, bool inv
return 0;
}
int processImage (string path, int mode, string red, string green, string blue) {
int invertMode (const string& path, string inverted) {
if (inverted.compare("") == 0) {
inverted = generatePath(path, "inverted");
}
fi.invertMode(path, inverted);
return 0;
}
int processImage (string path, int mode, string red, string green, string blue, string inverted) {
if (!fs::exists(path)) {
cerr << "{ \"error\" : \"File " << path << " does not exist.\" }" << endl;
return 3;
@ -53,6 +61,8 @@ int processImage (string path, int mode, string red, string green, string blue)
return rgbMode(path, red, green, blue, false);
case 1 :
return rgbMode(path, red, green, blue, true);
case 2 :
return invertMode(path, inverted);
break;
default :
cerr << "{\"error\" : \"Nothing to process\" }" << endl;
@ -68,11 +78,11 @@ int main (int argc, char** argv) {
args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"});;
args::Positional<string> image(parser, "image", "Image to manipulate");
args::ValueFlag<int> mode(parser, "mode", "The mode flag (default: 0) 0=RGB,1=", {'m'});
args::ValueFlag<int> mode(parser, "mode", "The mode flag (default: 0) 0=RGB,1=IRGB,2=Invert", {'m'});
args::ValueFlag<string> red(parser, "red", "Path of red channel file to write", {'r'});
args::ValueFlag<string> green(parser, "green", "Path of green channel file to write", {'g'});
args::ValueFlag<string> blue(parser, "blue", "Path of blue channel file to write", {'b'});
args::ValueFlag<string> inverted(parser, "inverted", "Path of inverted image file to write", {'i'});
try
{
parser.ParseCLI(argc, argv);
@ -111,7 +121,8 @@ int main (int argc, char** argv) {
mode ? args::get(mode) : 0,
red ? args::get(red) : "",
green ? args::get(green) : "",
blue ? args::get(blue) : "");
blue ? args::get(blue) : "",
inverted ? args::get(inverted) : "");
} catch (const exception &e) {
cerr << "Caught " << e.what() << endl;
return 2;