Parcourir la source

Rearange scripts folder

Jérôme BUISINE il y a 3 ans
Parent
commit
c9f384d67d

+ 2 - 2
README.md

@@ -29,11 +29,11 @@ make
 
 Convert the `.rawls` image format into `.ppm` 
 ```
-./main/rawls_reader --image ../path/to/image.rawls --outfile image.ppm
+./main/rawls_convert --image ../path/to/image.rawls --outfile image.ppm
 ```
 
 
 Merge `.rawls` images samples
 ```
-./main/rawls_merge --folder ../path/to/images --samples 100 --random 0 --outfile image.png
+./main/rawls_merge_mean --folder ../path/to/images --samples 100 --random 0 --outfile image.png
 ```

+ 23 - 3
main/rawls_merge_mean_incr.cpp

@@ -9,6 +9,11 @@
 #include <filesystem>
 #include <regex>
 
+#include <bits/stdc++.h> 
+#include <iostream> 
+#include <sys/stat.h> 
+#include <sys/types.h> 
+
 void writeProgress(float progress, bool moveUp = false){
     int barWidth = 200;
 
@@ -86,6 +91,9 @@ int main(int argc, char *argv[]){
         }
     }
 
+    // create output directory
+    mkdir(outputFolder.c_str(), 0755);
+
     std::vector<std::string> imagesPath;
 
     for (const auto & entry : std::filesystem::directory_iterator(folderName)){
@@ -95,6 +103,11 @@ int main(int argc, char *argv[]){
         }
     }
 
+    // check number of files
+    if (maxSamples > imagesPath.size()) {
+        maxSamples = imagesPath.size();
+    }
+
     // sort or shuffle the images path
     if (!random){
         std::sort(imagesPath.begin(), imagesPath.end(), std::less<std::string>());
@@ -137,13 +150,17 @@ int main(int argc, char *argv[]){
         comments = rawls::getCommentsRAWLS(imagesPath.at(0));
     }
 
-    for (unsigned i = 0; i < maxSamples; i++){
+    for (int i = 0; i < maxSamples; i++){
 
         unsigned currentSample = i + 1;
 
         // read into folder all `.rawls` file and merge pixels values
         float* buffer = rawls::getPixelsRAWLS(imagesPath.at(i));
 
+
+        double w1 = (double)i / (double)(i + 1.);
+        double w2 = 1. / ((double)i + 1.);
+        
         for(unsigned y = 0; y < height; y++){
 
             for(unsigned x = 0; x < width; x++) {
@@ -151,7 +168,9 @@ int main(int argc, char *argv[]){
                 for(unsigned j = 0; j < nbChanels; j++){
                     
                     float value = buffer[nbChanels * width * y + nbChanels * x + j];
-                    outputBuffer[nbChanels * width * y + nbChanels * x + j] +=  value;
+                    //outputBuffer[nbChanels * width * y + nbChanels * x + j] +=  value;
+
+                    outputBuffer[nbChanels * width * y + nbChanels * x + j] = outputBuffer[nbChanels * width * y + nbChanels * x + j] * w1 + value * w2;
                 }
             }
         }
@@ -161,7 +180,7 @@ int main(int argc, char *argv[]){
 
              // mean all samples values by number of samples used
             for (int j = 0; j < height * width * nbChanels; j++){
-                outputStepBuffer[j] = outputBuffer[j] / currentSample;
+                outputStepBuffer[j] = outputBuffer[j];// / currentSample;
             }
 
             // add suffix with `5` digits
@@ -174,6 +193,7 @@ int main(int argc, char *argv[]){
             // build output path of image
             std::string outfileName = outputFolder + "/" + prefixImageName + "_" + suffix + "." + imageExtension;
             outfileName = std::regex_replace(outfileName, std::regex("\\//"), "/"); // fix path 
+            std::cout << "Saved image into " << outfileName << std::endl;
 
             // save the expected `step` image using built outpath
             saveCurrentImage(width, height, nbChanels, outputStepBuffer, outfileName, comments);

+ 0 - 216
main/rawls_merge_mean_incr_v2.cpp

@@ -1,216 +0,0 @@
-#include <iostream>
-#include <string.h>
-#include <memory>
-
-#include "lodepng.h"
-#include "rawls.h"
-
-#include <algorithm>
-#include <filesystem>
-#include <regex>
-
-#include <bits/stdc++.h> 
-#include <iostream> 
-#include <sys/stat.h> 
-#include <sys/types.h> 
-
-void writeProgress(float progress, bool moveUp = false){
-    int barWidth = 200;
-
-    if (moveUp){
-        // move up line
-        std::cout << "\e[A";
-        std::cout.flush();
-    }
-
-    std::cout << "[";
-    int pos = barWidth * progress;
-    for (int i = 0; i < barWidth; ++i) {
-        if (i < pos) std::cout << "=";
-        else if (i == pos) std::cout << ">";
-        else std::cout << " ";
-    }
-    std::cout << "] " << int(progress * 100.0) << " %\r";
-    std::cout.flush();
-}
-
-/*
- * Save current step images from current buffer
- */
-bool saveCurrentImage(int width, int height, int nbChanels, float* buffer, std::string outfileName, std::string comments){
-    
-    // create outfile 
-    if (rawls::HasExtension(outfileName, ".ppm")){
-        rawls::saveAsPPM(width, height, nbChanels, buffer, outfileName);
-    } 
-    else if (rawls::HasExtension(outfileName, ".png")){
-        rawls::saveAsPNG(width, height, nbChanels, buffer, outfileName);
-    } 
-    else if (rawls::HasExtension(outfileName, ".rawls") || rawls::HasExtension(outfileName, ".rawls_20")){
-    
-        // Here no gamma conversion is done, only mean of samples
-        rawls::saveAsRAWLS(width, height, nbChanels, comments, buffer, outfileName);
-    }
-    else{
-        std::cout << "Unexpected output extension image" << std::endl;
-        return false;
-    }
-
-    return true;
-}
-
-/*
- * Incremental merge of `rawls` images
- */
-int main(int argc, char *argv[]){
-
-    std::string folderName;
-    std::string outputFolder;
-    std::string prefixImageName;
-    std::string imageExtension;
-
-    unsigned step = 10;
-    unsigned maxSamples = 0;
-    bool random;
-
-    for (int i = 1; i < argc; ++i) {
-        if (!strcmp(argv[i], "--folder") || !strcmp(argv[i], "-folder")) {
-            folderName = argv[++i];
-        } else if (!strcmp(argv[i], "--step") || !strcmp(argv[i], "-step")) {
-            step = atoi(argv[++i]);
-        }else if (!strcmp(argv[i], "--random") || !strcmp(argv[i], "-random")) {
-            random = bool(atoi(argv[++i]));
-        }else if (!strcmp(argv[i], "--output") || !strcmp(argv[i], "-output")) {
-            outputFolder = argv[++i];
-        }else if (!strcmp(argv[i], "--prefix") || !strcmp(argv[i], "-prefix")) {
-            prefixImageName = argv[++i];
-        }else if (!strcmp(argv[i], "--max") || !strcmp(argv[i], "-max")) {
-            maxSamples = atoi(argv[++i]);
-        }else if (!strcmp(argv[i], "--extension") || !strcmp(argv[i], "-extension")) {
-            imageExtension = argv[++i];
-        }
-    }
-
-    // create output directory
-    mkdir(outputFolder.c_str(), 0755);
-
-    std::vector<std::string> imagesPath;
-
-    for (const auto & entry : std::filesystem::directory_iterator(folderName)){
-        std::string imageName = entry.path().string();
-        if (rawls::HasExtension(imageName, ".rawls") || rawls::HasExtension(imageName, ".rawls_20")){
-            imagesPath.push_back(imageName);
-        }
-    }
-
-    // check number of files
-    if (maxSamples > imagesPath.size()) {
-        maxSamples = imagesPath.size();
-    }
-
-    // sort or shuffle the images path
-    if (!random){
-        std::sort(imagesPath.begin(), imagesPath.end(), std::less<std::string>());
-    }else{
-        std::random_shuffle(imagesPath.begin(), imagesPath.end());
-    }
-
-    unsigned width, height, nbChanels;
-    float* outputStepBuffer;
-    float* outputBuffer;
-
-    if (imagesPath.size() > 0){
-
-        std::tuple<unsigned, unsigned, unsigned> dimensions = rawls::getDimensionsRAWLS(imagesPath.at(0));
-
-        width = std::get<0>(dimensions);
-        height = std::get<1>(dimensions);
-        nbChanels = std::get<2>(dimensions);
-        outputBuffer = new float[width * height * nbChanels];
-        outputStepBuffer = new float[width * height * nbChanels];
-
-        // init values of buffer
-        for (int i = 0; i < height * width * nbChanels; i++){
-            outputBuffer[i] = 0;
-            outputStepBuffer[i] = 0;
-        }
-    }
-    else
-    {
-        std::cout << "Folder is empty..." << std::endl;
-        return 1;
-    }
-
-    // just for indication
-    float progress = 0.0;
-    unsigned bufferSize = width * height * nbChanels;
-    std::string comments;
-
-    if (rawls::HasExtension(imageExtension, "rawls")){
-        comments = rawls::getCommentsRAWLS(imagesPath.at(0));
-    }
-
-    for (int i = 0; i < maxSamples; i++){
-
-        unsigned currentSample = i + 1;
-
-        // read into folder all `.rawls` file and merge pixels values
-        float* buffer = rawls::getPixelsRAWLS(imagesPath.at(i));
-
-
-        double w1 = (double)i / (double)(i + 1.);
-        double w2 = 1. / ((double)i + 1.);
-        
-        for(unsigned y = 0; y < height; y++){
-
-            for(unsigned x = 0; x < width; x++) {
-
-                for(unsigned j = 0; j < nbChanels; j++){
-                    
-                    float value = buffer[nbChanels * width * y + nbChanels * x + j];
-                    //outputBuffer[nbChanels * width * y + nbChanels * x + j] +=  value;
-
-                    outputBuffer[nbChanels * width * y + nbChanels * x + j] = outputBuffer[nbChanels * width * y + nbChanels * x + j] * w1 + value * w2;
-                }
-            }
-        }
-
-        // save a new 
-        if (currentSample % step == 0){
-
-             // mean all samples values by number of samples used
-            for (int j = 0; j < height * width * nbChanels; j++){
-                outputStepBuffer[j] = outputBuffer[j];// / currentSample;
-            }
-
-            // add suffix with `5` digits
-            std::string suffix = std::to_string(currentSample);
-            
-            while(suffix.length() < 5){
-                suffix = "0" + suffix;
-            }
-
-            // build output path of image
-            std::string outfileName = outputFolder + "/" + prefixImageName + "_" + suffix + "." + imageExtension;
-            outfileName = std::regex_replace(outfileName, std::regex("\\//"), "/"); // fix path 
-            std::cout << "Saved image into " << outfileName << std::endl;
-
-            // save the expected `step` image using built outpath
-            saveCurrentImage(width, height, nbChanels, outputStepBuffer, outfileName, comments);
-            writeProgress(progress, true);
-        }
-
-        // update and write progress information
-        progress += (1 / (float)maxSamples);
-        writeProgress(progress);
-
-        delete buffer;
-    }
-    
-    writeProgress(1.);
-    std::cout << std::endl;
-
-    // delete the outputbuffer used
-    delete outputBuffer;
-    delete outputStepBuffer;
-}

run/reconstruct_png_all.sh → run/reconstruct_png_all_incr.sh


run/convert_all_rawls.py → utils/convert_all_rawls.py


run/extract_specific_modulo.py → utils/extract_specific_modulo.py


run/extract_specific_png.py → utils/extract_specific_png.py


run/run_all_estimators.py → utils/run_all_estimators.py


run/run_all_estimators_reduced.py → utils/run_all_estimators_reduced.py