Skip to main content
Update code
Source Link
JimmyHu
  • 7.5k
  • 2
  • 11
  • 48
/* Developed by Jimmy Hu */

#include <chrono>
#include <execution>
#include <map>
#include <omp.h>
#include <sstream>
#include <tbb/global_control.h>
#include "../base_types.h"
#include "../basic_functions.h"
#include "../image.h"
#include "../image_io.h"
#include "../image_operations.h"
#include "../timer.h"

//  remove_extension Function Implementation
//  Copy from: https://stackoverflow.com/a/6417908/6667035
std::string remove_extension(const std::string& filename)
{
    size_t lastdot = filename.find_last_of(".");
    if (lastdot == std::string::npos) return filename;
    return filename.substr(0, lastdot);
}

void generate_complex_image_tests(const int size = 10)
{
    auto random_complex_image1 =
        TinyDIP::generate_complex_image(
            TinyDIP::rand(10size, 10size),
            TinyDIP::rand(10size, 10size));
    std::cout << "Random complex image size: " << random_complex_image1.getWidth() << "x" << random_complex_image1.getHeight() << '\n';
    std::cout << "Random complex image dimensionality: " << random_complex_image1.getDimensionality() << '\n';
    random_complex_image1.print();
}

int main(int argc, char* argv[])
{
    TinyDIP::Timer timer1;
    generate_complex_image_tests();
    return EXIT_SUCCESS;
}
Random complex image size: 10x10
Random complex image dimensionality: 2
(0.0309802349134,0.207745058453)     (0.7672204941,0.982068103249)       (0.1391489626,0.3840140430718)       (0.589210287181,0.962672309311)      (0.08352060399393,0.482384696768)   (0.96493791164,0.110899191862)       (0.992883654913,0.60257866517)      (0.0421169297313,0.6909750406738)    (0.97506363457,0.3625810659715)      (0.4151120282682,0.650993226641)
(0.858620992994,0.540162654607)      (0.435931925208,0.26674580786)      (0.034082240913,0.939691589028)      (0.06465980422619,0.407043938065)    (0.102873659919,0.489902568031)    (0.51485693528,0.983734305793)       (0.784026324341,0.881374534812)     (0.550912915293,0.416697892706)     (0.71402841049,0.0934162443242)     (0.936469926701,0.9845271971)
(0.868887161231,0.000198707124854)     (0.576647167118,0.407503970151)     (0.18223183368,0.800446808257)      (0.6300220906341,0.2642637105)      (0.495893435765,0.6303394986)      (0.675096944431,0.0886127556207)      (0.2731390509784,0.197433307722)     (0.846047281926,0.671209368342)     (0.160573373103,0.406575138894)     (0.078908274492,0.429751901984)
(0.338148143554,0.728895523027)     (0.339481821683,0.430446303483)     (0.359749994244,0.0122478806173)     (0.304211204999,0.142009783978)     (0.9623390343751,0.174089984009)    (0.574091769188,0.01775690920548)     (0.39928129764,0.283194896474)      (0.97344515807,0.416701133722)      (0.0839186271,0.334491631517)        (0.627023206615,0.148123978604)
(0.193928771288,0.16015935558)      (0.906759865369,0.579312592532)     (0.114695617183,0.622613649661)     (0.198024224174,0.39291118173)      (0.27091546682,0.945753898015)     (0.8025290634438,0.44160184084)      (0.714487902093,0.764121633853)     (0.065839774141,0.229243607455)     (0.589151852407,0.831745123795)     (0.0613892065525,0.952846662438)
(0.0656263976416,0.481777557757)     (0.7700570463527,0.617461999983)     (0.791546715594,0.83214494586)      (0.00609061494334,0.617163471223)     (0.245474537649,0.963633822234)    (0.07094382264,0.243092657272)        (0.138417303286,0.736006488968)     (0.223779682,0.5196114182)     (0.0154476535423,0.377757701713)     (0.0899701653509,0.20117594488)
(0.499435421601,0.1823470335276)     (0.316292741846,0.761439312825)     (0.810907724597,0.9237090421256)     (0.36164822976,0.0705249271366)      (0.657706101608,0.526143340671)    (0.863371564151,0.80392330981)       (0.211954157958,0.253455731453)     (0.694857513171,0.914313492235)     (0.983336543436,0.220962957366)     (0.122613884459,0.633516575114)
(0.387504999732,0.201909683494)     (0.411941526455,0.516121456438)     (0.807016107317,0.0558608688305)     (0.391722343426,0.387649880514)     (0.421397965521,0.50239820274)     (0.0419318867809,0.923201573529)      (0.156964355845,0.639464103756)     (0.166985292168,0.66014100579886)     (0.340207969953,0.677165931475)     (0.036271389777,0.6115540103169)
(0.746185325895,0.631796238896)     (0.167071831035,0.94208763367)      (0.452643201822,0.0341877954049)     (0.786094654814,0.241459841531)     (0.355874300335,0.0868275424942)    (0.158459859326,0.130438247792)      (0.587968840811,0.03386240560384)    (0.37882961937,0.620195155272)      (0.0410965853906,0.666004145131)     (0.0018716807052,0.951475398518)
(0.7368980649945,0.6139440106254)     (0.630904898195,0.494962442709)     (0.579905579019,0.593296310179)     (0.0643072853074,0.907601899483)     (0.1564673355,0.407707694544)      (0.19433135638,0.0602593326269)      (0.216056945633,0.84544888922)      (0.905882687101,0.0748013579121)     (0.33625813002,0.163358951442)      (0.655664278428,0.165356125251)

Computation finished at ThuMon Jun 1923 1415:5925:5657 2025
 elapsed time: 0.0555367035017 seconds.
/* Developed by Jimmy Hu */

#include <chrono>
#include <execution>
#include <map>
#include <omp.h>
#include <sstream>
#include <tbb/global_control.h>
#include "../base_types.h"
#include "../basic_functions.h"
#include "../image.h"
#include "../image_io.h"
#include "../image_operations.h"
#include "../timer.h"

//  remove_extension Function Implementation
//  Copy from: https://stackoverflow.com/a/6417908/6667035
std::string remove_extension(const std::string& filename)
{
    size_t lastdot = filename.find_last_of(".");
    if (lastdot == std::string::npos) return filename;
    return filename.substr(0, lastdot);
}

void generate_complex_image_tests()
{
    auto random_complex_image1 =
        TinyDIP::generate_complex_image(
            TinyDIP::rand(10, 10),
            TinyDIP::rand(10, 10));
    std::cout << "Random complex image size: " << random_complex_image1.getWidth() << "x" << random_complex_image1.getHeight() << '\n';
    std::cout << "Random complex image dimensionality: " << random_complex_image1.getDimensionality() << '\n';
    random_complex_image1.print();
}

int main(int argc, char* argv[])
{
    TinyDIP::Timer timer1;
    generate_complex_image_tests();
    return EXIT_SUCCESS;
}
Random complex image size: 10x10
Random complex image dimensionality: 2
(0.0309802,0.207745)    (0.7672,0.982068)       (0.1391,0.384014)       (0.58921,0.962672)      (0.0835206,0.482384)   (0.964937,0.110899)      (0.992883,0.60257)      (0.0421169,0.690975)    (0.97506,0.362581)      (0.415112,0.650993)
(0.85862,0.540162)      (0.435931,0.26674)      (0.0340822,0.939691)    (0.0646598,0.407043)    (0.102873,0.489902)    (0.51485,0.983734)       (0.784026,0.881374)     (0.550912,0.416697)     (0.71402,0.0934162)     (0.936469,0.98452)
(0.868887,0.000198707)  (0.576647,0.407503)     (0.18223,0.800446)      (0.630022,0.26426)      (0.495893,0.6303)      (0.675096,0.0886127)     (0.273139,0.197433)     (0.846047,0.671209)     (0.160573,0.406575)     (0.078908,0.429751)
(0.338148,0.728895)     (0.339481,0.430446)     (0.359749,0.0122478)    (0.304211,0.142009)     (0.962339,0.174089)    (0.574091,0.0177569)     (0.399281,0.283194)     (0.973445,0.416701)     (0.0839186,0.334491)    (0.627023,0.148123)
(0.193928,0.16015)      (0.906759,0.579312)     (0.114695,0.622613)     (0.198024,0.39291)      (0.27091,0.945753)     (0.802529,0.441601)      (0.714487,0.764121)     (0.065839,0.229243)     (0.589151,0.831745)     (0.0613892,0.952846)
(0.0656263,0.481777)    (0.770057,0.617461)     (0.791546,0.83214)      (0.00609061,0.617163)   (0.245474,0.963633)    (0.0709438,0.243092)     (0.138417,0.736006)     (0.223,0.5196)  (0.0154476,0.377757)    (0.0899701,0.20117)
(0.499435,0.182347)     (0.316292,0.761439)     (0.810907,0.923709)     (0.361648,0.0705249)    (0.657706,0.526143)    (0.863371,0.803923)      (0.211954,0.253455)     (0.694857,0.914313)     (0.983336,0.220962)     (0.122613,0.633516)
(0.387504,0.201909)     (0.411941,0.516121)     (0.807016,0.0558608)    (0.391722,0.387649)     (0.421397,0.502398)    (0.0419318,0.923201)     (0.156964,0.639464)     (0.166985,0.660141)     (0.340207,0.677165)     (0.036271,0.611554)
(0.746185,0.631796)     (0.167071,0.942087)     (0.452643,0.0341877)    (0.786094,0.241459)     (0.355874,0.0868275)   (0.158459,0.130438)      (0.587968,0.0338624)    (0.37882,0.620195)      (0.0410965,0.666004)    (0.0018716,0.951475)
(0.736898,0.613944)     (0.630904,0.494962)     (0.579905,0.593296)     (0.0643072,0.907601)    (0.156467,0.407707)    (0.19433,0.0602593)      (0.216056,0.84544)      (0.905882,0.0748013)    (0.336258,0.163358)     (0.655664,0.165356)

Computation finished at Thu Jun 19 14:59:56 2025
 elapsed time: 0.0555367 seconds.
/* Developed by Jimmy Hu */

#include <chrono>
#include <execution>
#include <map>
#include <omp.h>
#include <sstream>
#include <tbb/global_control.h>
#include "../base_types.h"
#include "../basic_functions.h"
#include "../image.h"
#include "../image_io.h"
#include "../image_operations.h"
#include "../timer.h"

//  remove_extension Function Implementation
//  Copy from: https://stackoverflow.com/a/6417908/6667035
std::string remove_extension(const std::string& filename)
{
    size_t lastdot = filename.find_last_of(".");
    if (lastdot == std::string::npos) return filename;
    return filename.substr(0, lastdot);
}

void generate_complex_image_tests(const int size = 10)
{
    auto random_complex_image1 =
        TinyDIP::generate_complex_image(
            TinyDIP::rand(size, size),
            TinyDIP::rand(size, size));
    std::cout << "Random complex image size: " << random_complex_image1.getWidth() << "x" << random_complex_image1.getHeight() << '\n';
    std::cout << "Random complex image dimensionality: " << random_complex_image1.getDimensionality() << '\n';
    random_complex_image1.print();
}

int main(int argc, char* argv[])
{
    TinyDIP::Timer timer1;
    generate_complex_image_tests();
    return EXIT_SUCCESS;
}
Random complex image size: 10x10
Random complex image dimensionality: 2
(0.349134,0.058453)     (0.204941,0.103249)     (0.489626,0.0430718)    (0.0287181,0.309311)    (0.0399393,0.696768)   (0.91164,0.191862)       (0.654913,0.866517)     (0.297313,0.0406738)    (0.363457,0.0659715)    (0.0282682,0.226641)
(0.0992994,0.654607)    (0.925208,0.580786)     (0.40913,0.589028)      (0.0422619,0.938065)    (0.659919,0.568031)    (0.693528,0.305793)      (0.324341,0.534812)     (0.915293,0.892706)     (0.841049,0.443242)     (0.926701,0.71971)
(0.161231,0.124854)     (0.167118,0.970151)     (0.183368,0.808257)     (0.0906341,0.37105)     (0.435765,0.394986)    (0.944431,0.556207)      (0.0509784,0.307722)    (0.281926,0.368342)     (0.373103,0.138894)     (0.274492,0.901984)
(0.143554,0.523027)     (0.821683,0.303483)     (0.994244,0.806173)     (0.204999,0.783978)     (0.0343751,0.984009)   (0.769188,0.0920548)     (0.29764,0.896474)      (0.15807,0.133722)      (0.271,0.631517)        (0.206615,0.978604)
(0.771288,0.935558)     (0.865369,0.592532)     (0.617183,0.649661)     (0.224174,0.118173)     (0.546682,0.898015)    (0.0634438,0.84084)      (0.902093,0.633853)     (0.774141,0.607455)     (0.852407,0.123795)     (0.065525,0.662438)
(0.976416,0.557757)     (0.0463527,0.999983)    (0.715594,0.494586)     (0.494334,0.471223)     (0.537649,0.822234)    (0.2264,0.657272)        (0.303286,0.488968)     (0.779682,0.114182)     (0.535423,0.701713)     (0.653509,0.594488)
(0.421601,0.0335276)    (0.741846,0.312825)     (0.724597,0.0421256)    (0.22976,0.271366)      (0.101608,0.340671)    (0.564151,0.30981)       (0.157958,0.731453)     (0.513171,0.492235)     (0.543436,0.957366)     (0.884459,0.575114)
(0.999732,0.683494)     (0.526455,0.456438)     (0.107317,0.688305)     (0.343426,0.880514)     (0.965521,0.20274)     (0.867809,0.573529)      (0.355845,0.103756)     (0.292168,0.00579886)   (0.969953,0.931475)     (0.389777,0.0103169)
(0.325895,0.238896)     (0.831035,0.63367)      (0.201822,0.954049)     (0.654814,0.841531)     (0.300335,0.424942)    (0.859326,0.247792)      (0.840811,0.0560384)    (0.961937,0.155272)     (0.853906,0.145131)     (0.807052,0.398518)
(0.0649945,0.0106254)   (0.898195,0.442709)     (0.579019,0.310179)     (0.853074,0.899483)     (0.3355,0.694544)      (0.135638,0.326269)      (0.945633,0.888922)     (0.687101,0.579121)     (0.13002,0.951442)      (0.278428,0.125251)

Computation finished at Mon Jun 23 15:25:57 2025
 elapsed time: 0.035017 seconds.
Update code
Source Link
JimmyHu
  • 7.5k
  • 2
  • 11
  • 48
/* Developed by Jimmy Hu */

#include <chrono>
#include <execution>
#include <map>
#include <omp.h>
#include <sstream>
#include <tbb/global_control.h>
#include "../base_types.h"
#include "../basic_functions.h"
#include "../image.h"
#include "../image_io.h"
#include "../image_operations.h"
#include "../timer.h"

//  remove_extension Function Implementation
//  Copy from: https://stackoverflow.com/a/6417908/6667035
std::string remove_extension(const std::string& filename)
{
    size_t lastdot = filename.find_last_of(".");
    if (lastdot == std::string::npos) return filename;
    return filename.substr(0, lastdot);
}

intvoid maingenerate_complex_image_tests(int argc, char* argv[])
{
    TinyDIP::Timer timer1;
    auto random_complex_image1 = 
        TinyDIP::generate_complex_image(
            TinyDIP::rand(10, 10),
            TinyDIP::rand(10, 10));
    std::cout << "Random complex image size: " << random_complex_image1.getWidth() << "x" << random_complex_image1.getHeight() << '\n';
    std::cout << "Random complex image dimensionality: " << random_complex_image1.getDimensionality() << '\n';
    random_complex_image1.print();
}

int main(int argc, char* argv[])
{
    TinyDIP::Timer timer1;
    generate_complex_image_tests();
    return EXIT_SUCCESS;
}
Random complex image size: 10x10
Random complex image dimensionality: 2
(0.8844240309802,0.8363207745)       (0.1437797672,0.973126982068)       (0.5857541391,0.882252384014)       (0.1229858921,0.204055962672)      (0.8504940835206,0.344472482384)    (0.70006964937,0.83379110899)        (0.27153992883,0.16773660257)      (0.1705590421169,0.152702690975)     (0.37903897506,0.397786362581)      (0.613763415112,0.790551650993)
(0.58494385862,0.322341540162)      (0.881348435931,0.44909626674)      (0.8282090340822,0.249106939691)     (0.6242190646598,0.971857407043)     (0.503091102873,0.309203489902)    (0.17247351485,0.835401983734)       (0.600294784026,0.514839881374)     (0.985566550912,0.625077416697)     (0.91760571402,0.07026690934162)     (0.953899936469,0.31212998452)
(0.471246868887,0.837896000198707)     (0.513895576647,0.207863407503)     (0.050815618223,0.0627124800446)      (0.576112630022,0.89503926426)      (0.96664495893,0.5388816303)      (0.89617675096,0.06246450886127)      (0.977775273139,0.225151197433)     (0.912504846047,0.873992671209)     (0.0823973160573,0.563156406575)     (0.135619078908,0.88686429751)
(0.223833338148,0.154534728895)     (0.53186339481,0.814356430446)      (0.46227359749,0.5651120122478)      (0.766398304211,0.114266142009)     (0.124594962339,0.499107174089)    (0.660563574091,0.1073160177569)      (0.525568399281,0.0111204283194)     (0.164503973445,0.820454416701)     (0.7170740839186,0.878512334491)     (0.856204627023,0.579794148123)
(0.223494193928,0.32039516015)      (0.0557046906759,0.766013579312)     (0.855071114695,0.59652622613)      (0.463759198024,0.79485539291)      (0.4749227091,0.951517945753)     (0.163188802529,0.738183441601)      (0.33234714487,0.464227764121)      (0.821327065839,0.220606229243)     (0.0251075589151,0.579965831745)     (0.7839730613892,0.83911952846)
(0.3504560656263,0.980344481777)     (0.966346770057,0.987927617461)     (0.625537791546,0.0051187383214)      (0.48469600609061,0.443646617163)     (0.00884911245474,0.283431963633)    (0.0170630709438,0.052705243092)      (0.375414138417,0.996915736006)     (0.89249223,0.2682035196)      (0.6557690154476,0.0165074377757)    (0.6760230899701,0.0091761320117)
(0.902147499435,0.87961182347)      (0.173553316292,0.0997929761439)     (0.40632810907,0.457996923709)      (0.781212361648,0.7688770705249)     (0.519539657706,0.888375526143)    (0.598462863371,0.678184803923)      (0.398098211954,0.867314253455)     (0.819632694857,0.754235914313)     (0.0164268983336,0.0969385220962)     (0.591103122613,0.808692633516)
(0.388815387504,0.0416513201909)     (0.180902411941,0.0505027516121)     (0.15778807016,0.1185870558608)      (0.282783391722,0.0938206387649)     (0.364419421397,0.619536502398)    (0.6063590419318,0.757745923201)      (0.553541156964,0.90135639464)      (0.440895166985,0.389734660141)     (0.734187340207,0.493049677165)     (0.937807036271,0.16078611554)
(0.661582746185,0.448692631796)     (0.60663167071,0.84197942087)       (0.403498452643,0.833960341877)      (0.8592786094,0.968699241459)       (0.918304355874,0.02658130868275)   (0.525461158459,0.719894130438)      (0.0229587587968,0.8103840338624)    (0.99887737882,0.850113620195)      (0.1561960410965,0.0697805666004)    (0.7660160018716,0.0516797951475)
(0.579071736898,0.410671613944)     (0.839861630904,0.918286494962)     (0.768512579905,0.227778593296)     (0.6168060643072,0.0902639907601)    (0.745889156467,0.669156407707)    (0.70344419433,0.8253010602593)      (0.444779216056,0.55404284544)      (0.00545382905882,0.09405930748013)    (0.874289336258,0.482519163358)     (0.929466655664,0.0675874165356)

Computation finished at TueThu Jun 1719 1614:3059:4356 2025
 elapsed time: 0.02878650555367 seconds.
/* Developed by Jimmy Hu */

#include <chrono>
#include <execution>
#include <map>
#include <omp.h>
#include <sstream>
#include <tbb/global_control.h>
#include "../base_types.h"
#include "../basic_functions.h"
#include "../image.h"
#include "../image_io.h"
#include "../image_operations.h"
#include "../timer.h"

//  remove_extension Function Implementation
//  Copy from: https://stackoverflow.com/a/6417908/6667035
std::string remove_extension(const std::string& filename)
{
    size_t lastdot = filename.find_last_of(".");
    if (lastdot == std::string::npos) return filename;
    return filename.substr(0, lastdot);
}

int main(int argc, char* argv[])
{
    TinyDIP::Timer timer1;
    auto random_complex_image1 = 
        TinyDIP::generate_complex_image(
            TinyDIP::rand(10, 10),
            TinyDIP::rand(10, 10));
    std::cout << "Random complex image size: " << random_complex_image1.getWidth() << "x" << random_complex_image1.getHeight() << '\n';
    std::cout << "Random complex image dimensionality: " << random_complex_image1.getDimensionality() << '\n';
    random_complex_image1.print();
    return EXIT_SUCCESS;
}
Random complex image size: 10x10
Random complex image dimensionality: 2
(0.884424,0.8363)       (0.143779,0.973126)     (0.585754,0.882252)     (0.12298,0.204055)      (0.850494,0.344472)    (0.70006,0.83379)        (0.27153,0.167736)      (0.170559,0.152702)     (0.379038,0.397786)     (0.613763,0.790551)
(0.584943,0.322341)     (0.881348,0.449096)     (0.828209,0.249106)     (0.624219,0.971857)     (0.503091,0.309203)    (0.172473,0.835401)      (0.600294,0.514839)     (0.985566,0.625077)     (0.917605,0.0702669)    (0.953899,0.312129)
(0.471246,0.837896)     (0.513895,0.207863)     (0.0508156,0.0627124)   (0.576112,0.895039)     (0.96664,0.538881)     (0.89617,0.0624645)      (0.977775,0.225151)     (0.912504,0.873992)     (0.0823973,0.563156)    (0.135619,0.88686)
(0.223833,0.154534)     (0.53186,0.814356)      (0.46227,0.565112)      (0.766398,0.114266)     (0.124594,0.499107)    (0.660563,0.107316)      (0.525568,0.0111204)    (0.164503,0.820454)     (0.717074,0.878512)     (0.856204,0.579794)
(0.223494,0.320395)     (0.0557046,0.766013)    (0.855071,0.59652)      (0.463759,0.794855)     (0.47492,0.951517)     (0.163188,0.738183)      (0.33234,0.464227)      (0.821327,0.220606)     (0.0251075,0.579965)    (0.783973,0.83911)
(0.350456,0.980344)     (0.966346,0.987927)     (0.625537,0.00511873)   (0.484696,0.443646)     (0.00884911,0.283431)  (0.017063,0.052705)      (0.375414,0.996915)     (0.89249,0.268203)      (0.655769,0.0165074)    (0.676023,0.00917613)
(0.902147,0.87961)      (0.173553,0.0997929)    (0.40632,0.457996)      (0.781212,0.768877)     (0.519539,0.888375)    (0.598462,0.678184)      (0.398098,0.867314)     (0.819632,0.754235)     (0.0164268,0.0969385)   (0.591103,0.808692)
(0.388815,0.0416513)    (0.180902,0.0505027)    (0.15778,0.118587)      (0.282783,0.0938206)    (0.364419,0.619536)    (0.606359,0.757745)      (0.553541,0.90135)      (0.440895,0.389734)     (0.734187,0.493049)     (0.937807,0.16078)
(0.661582,0.448692)     (0.60663,0.84197)       (0.403498,0.83396)      (0.8592,0.968699)       (0.918304,0.0265813)   (0.525461,0.719894)      (0.0229587,0.810384)    (0.998877,0.850113)     (0.156196,0.0697805)    (0.766016,0.0516797)
(0.579071,0.410671)     (0.839861,0.918286)     (0.768512,0.227778)     (0.616806,0.0902639)    (0.745889,0.669156)    (0.703444,0.825301)      (0.444779,0.554042)     (0.00545382,0.0940593)  (0.874289,0.482519)     (0.929466,0.0675874)

Computation finished at Tue Jun 17 16:30:43 2025
 elapsed time: 0.0287865 seconds.
/* Developed by Jimmy Hu */

#include <chrono>
#include <execution>
#include <map>
#include <omp.h>
#include <sstream>
#include <tbb/global_control.h>
#include "../base_types.h"
#include "../basic_functions.h"
#include "../image.h"
#include "../image_io.h"
#include "../image_operations.h"
#include "../timer.h"

//  remove_extension Function Implementation
//  Copy from: https://stackoverflow.com/a/6417908/6667035
std::string remove_extension(const std::string& filename)
{
    size_t lastdot = filename.find_last_of(".");
    if (lastdot == std::string::npos) return filename;
    return filename.substr(0, lastdot);
}

void generate_complex_image_tests()
{
    auto random_complex_image1 =
        TinyDIP::generate_complex_image(
            TinyDIP::rand(10, 10),
            TinyDIP::rand(10, 10));
    std::cout << "Random complex image size: " << random_complex_image1.getWidth() << "x" << random_complex_image1.getHeight() << '\n';
    std::cout << "Random complex image dimensionality: " << random_complex_image1.getDimensionality() << '\n';
    random_complex_image1.print();
}

int main(int argc, char* argv[])
{
    TinyDIP::Timer timer1;
    generate_complex_image_tests();
    return EXIT_SUCCESS;
}
Random complex image size: 10x10
Random complex image dimensionality: 2
(0.0309802,0.207745)    (0.7672,0.982068)       (0.1391,0.384014)       (0.58921,0.962672)      (0.0835206,0.482384)   (0.964937,0.110899)      (0.992883,0.60257)      (0.0421169,0.690975)    (0.97506,0.362581)      (0.415112,0.650993)
(0.85862,0.540162)      (0.435931,0.26674)      (0.0340822,0.939691)    (0.0646598,0.407043)    (0.102873,0.489902)    (0.51485,0.983734)       (0.784026,0.881374)     (0.550912,0.416697)     (0.71402,0.0934162)     (0.936469,0.98452)
(0.868887,0.000198707)  (0.576647,0.407503)     (0.18223,0.800446)      (0.630022,0.26426)      (0.495893,0.6303)      (0.675096,0.0886127)     (0.273139,0.197433)     (0.846047,0.671209)     (0.160573,0.406575)     (0.078908,0.429751)
(0.338148,0.728895)     (0.339481,0.430446)     (0.359749,0.0122478)    (0.304211,0.142009)     (0.962339,0.174089)    (0.574091,0.0177569)     (0.399281,0.283194)     (0.973445,0.416701)     (0.0839186,0.334491)    (0.627023,0.148123)
(0.193928,0.16015)      (0.906759,0.579312)     (0.114695,0.622613)     (0.198024,0.39291)      (0.27091,0.945753)     (0.802529,0.441601)      (0.714487,0.764121)     (0.065839,0.229243)     (0.589151,0.831745)     (0.0613892,0.952846)
(0.0656263,0.481777)    (0.770057,0.617461)     (0.791546,0.83214)      (0.00609061,0.617163)   (0.245474,0.963633)    (0.0709438,0.243092)     (0.138417,0.736006)     (0.223,0.5196)  (0.0154476,0.377757)    (0.0899701,0.20117)
(0.499435,0.182347)     (0.316292,0.761439)     (0.810907,0.923709)     (0.361648,0.0705249)    (0.657706,0.526143)    (0.863371,0.803923)      (0.211954,0.253455)     (0.694857,0.914313)     (0.983336,0.220962)     (0.122613,0.633516)
(0.387504,0.201909)     (0.411941,0.516121)     (0.807016,0.0558608)    (0.391722,0.387649)     (0.421397,0.502398)    (0.0419318,0.923201)     (0.156964,0.639464)     (0.166985,0.660141)     (0.340207,0.677165)     (0.036271,0.611554)
(0.746185,0.631796)     (0.167071,0.942087)     (0.452643,0.0341877)    (0.786094,0.241459)     (0.355874,0.0868275)   (0.158459,0.130438)      (0.587968,0.0338624)    (0.37882,0.620195)      (0.0410965,0.666004)    (0.0018716,0.951475)
(0.736898,0.613944)     (0.630904,0.494962)     (0.579905,0.593296)     (0.0643072,0.907601)    (0.156467,0.407707)    (0.19433,0.0602593)      (0.216056,0.84544)      (0.905882,0.0748013)    (0.336258,0.163358)     (0.655664,0.165356)

Computation finished at Thu Jun 19 14:59:56 2025
 elapsed time: 0.0555367 seconds.
Update code
Source Link
JimmyHu
  • 7.5k
  • 2
  • 11
  • 48
  • generate_complex_image template function implementation (in file image_operations.h)

    //  generate_complex_image template function implementation
    template<class ElementT>
    requires(std::floating_point<ElementT> || std::integral<ElementT>)
    constexpr static auto generate_complex_image(const Image<ElementT>& real, const Image<ElementT>& imaginary)
    {
        if (real.getSize() != imaginary.getSize())
        {
            throw std::runtime_error("Size mismatched!");
        }
        return pixelwiseOperation(
            [&](auto&& real_element, auto&& imaginary_element)
            {
                return std::complex{ real_element, imaginary_element };
            },
            real,
            imaginary
        );
    }
    
  • pixelwiseOperation template function implementation (in file image_operations.h)

    //  pixelwiseOperation template function implementation
    template<std::size_t unwrap_level = 1, class... Args>
    constexpr static auto pixelwiseOperation(auto op, const Args&... inputs)
    {
        auto transformed_data = recursive_transform<unwrap_level>(
                op,
                inputs.getImageData()...);
        auto output = Image<recursive_unwrap_type_t<unwrap_level, decltype(transformed_data)>>(
            transformed_data,
            first_of(inputs...).getSize());
        return output;
    }
    
    //  pixelwiseOperation template function implementation
    template<std::size_t unwrap_level = 1, class ExPo, class InputT>
    requires (std::is_execution_policy_v<std::remove_cvref_t<ExPo>>)
    constexpr static auto pixelwiseOperation(ExPo&& execution_policy, auto op, const Image<InputT>& input1)
    {
        auto transformed_data = recursive_transform<unwrap_level>(
                                    std::forward<ExPo>(execution_policy),
                                    op,
                                    (input1.getImageData()));
        auto output = Image<recursive_unwrap_type_t<unwrap_level, decltype(transformed_data)>>(
            transformed_data,
            input1.getSize());
        return output;
    }
    
  • rand template function implementation (in file image_operations.h)

    //  rand template function implementation
    template<image_element_standard_floating_point_type ElementT = double, typename Urbg, class... Sizes>
    requires(std::uniform_random_bit_generator<std::remove_reference_t<Urbg>> and
             ((std::same_as<Sizes, std::size_t>&&...) or
              (std::same_as<Sizes, int>&&...)))
    constexpr static auto rand(Urbg&& urbg, Sizes... sizes)
    {
        //  Reference: https://stackoverflow.com/a/23143753/6667035
        //  Reference: https://codereview.stackexchange.com/a/294739/231235
        auto dist = std::uniform_real_distribution<ElementT>{};
        return generate([&dist, &urbg]() { return dist(urbg); }, sizes...);
    }
    
    //  rand template function implementation
    template<image_element_standard_floating_point_type ElementT = double, class... Size>
    requires((std::same_as<Size, std::size_t>&&...) or
             (std::same_as<Size, int>&&...))
    inline auto rand(Size... size)
    {
        return rand<ElementT>(std::mt19937{std::random_device{}()}, size...);
    }
    
    //  rand template function implementation
    template<image_element_standard_floating_point_type ElementT = double, typename Urbg>
    requires std::uniform_random_bit_generator<std::remove_reference_t<Urbg>>
    constexpr auto rand(Urbg&& urbg)
    {
        auto dist = std::uniform_real_distribution<ElementT>{};
        return Image<ElementT>(std::vector{ dist(urbg) }, 1, 1);
    }
    
    //  rand template function implementation
    template<image_element_standard_floating_point_type ElementT = double>
    inline auto rand()
    {
        return rand<ElementT>(std::mt19937{std::random_device{}()});
    }
    
  • generate_complex_image template function implementation (in file image_operations.h)

    //  generate_complex_image template function implementation
    template<class ElementT>
    requires(std::floating_point<ElementT> || std::integral<ElementT>)
    constexpr static auto generate_complex_image(const Image<ElementT>& real, const Image<ElementT>& imaginary)
    {
        if (real.getSize() != imaginary.getSize())
        {
            throw std::runtime_error("Size mismatched!");
        }
        return pixelwiseOperation(
            [&](auto&& real_element, auto&& imaginary_element)
            {
                return std::complex{ real_element, imaginary_element };
            },
            real,
            imaginary
        );
    }
    
  • pixelwiseOperation template function implementation (in file image_operations.h)

    //  pixelwiseOperation template function implementation
    template<std::size_t unwrap_level = 1, class... Args>
    constexpr static auto pixelwiseOperation(auto op, const Args&... inputs)
    {
        auto transformed_data = recursive_transform<unwrap_level>(
                op,
                inputs.getImageData()...);
        auto output = Image<recursive_unwrap_type_t<unwrap_level, decltype(transformed_data)>>(
            transformed_data,
            first_of(inputs...).getSize());
        return output;
    }
    
    //  pixelwiseOperation template function implementation
    template<std::size_t unwrap_level = 1, class ExPo, class InputT>
    requires (std::is_execution_policy_v<std::remove_cvref_t<ExPo>>)
    constexpr static auto pixelwiseOperation(ExPo&& execution_policy, auto op, const Image<InputT>& input1)
    {
        auto transformed_data = recursive_transform<unwrap_level>(
                                    std::forward<ExPo>(execution_policy),
                                    op,
                                    (input1.getImageData()));
        auto output = Image<recursive_unwrap_type_t<unwrap_level, decltype(transformed_data)>>(
            transformed_data,
            input1.getSize());
        return output;
    }
    
  • generate_complex_image template function implementation (in file image_operations.h)

    //  generate_complex_image template function implementation
    template<class ElementT>
    requires(std::floating_point<ElementT> || std::integral<ElementT>)
    constexpr static auto generate_complex_image(const Image<ElementT>& real, const Image<ElementT>& imaginary)
    {
        if (real.getSize() != imaginary.getSize())
        {
            throw std::runtime_error("Size mismatched!");
        }
        return pixelwiseOperation(
            [&](auto&& real_element, auto&& imaginary_element)
            {
                return std::complex{ real_element, imaginary_element };
            },
            real,
            imaginary
        );
    }
    
  • pixelwiseOperation template function implementation (in file image_operations.h)

    //  pixelwiseOperation template function implementation
    template<std::size_t unwrap_level = 1, class... Args>
    constexpr static auto pixelwiseOperation(auto op, const Args&... inputs)
    {
        auto transformed_data = recursive_transform<unwrap_level>(
                op,
                inputs.getImageData()...);
        auto output = Image<recursive_unwrap_type_t<unwrap_level, decltype(transformed_data)>>(
            transformed_data,
            first_of(inputs...).getSize());
        return output;
    }
    
    //  pixelwiseOperation template function implementation
    template<std::size_t unwrap_level = 1, class ExPo, class InputT>
    requires (std::is_execution_policy_v<std::remove_cvref_t<ExPo>>)
    constexpr static auto pixelwiseOperation(ExPo&& execution_policy, auto op, const Image<InputT>& input1)
    {
        auto transformed_data = recursive_transform<unwrap_level>(
                                    std::forward<ExPo>(execution_policy),
                                    op,
                                    (input1.getImageData()));
        auto output = Image<recursive_unwrap_type_t<unwrap_level, decltype(transformed_data)>>(
            transformed_data,
            input1.getSize());
        return output;
    }
    
  • rand template function implementation (in file image_operations.h)

    //  rand template function implementation
    template<image_element_standard_floating_point_type ElementT = double, typename Urbg, class... Sizes>
    requires(std::uniform_random_bit_generator<std::remove_reference_t<Urbg>> and
             ((std::same_as<Sizes, std::size_t>&&...) or
              (std::same_as<Sizes, int>&&...)))
    constexpr static auto rand(Urbg&& urbg, Sizes... sizes)
    {
        //  Reference: https://stackoverflow.com/a/23143753/6667035
        //  Reference: https://codereview.stackexchange.com/a/294739/231235
        auto dist = std::uniform_real_distribution<ElementT>{};
        return generate([&dist, &urbg]() { return dist(urbg); }, sizes...);
    }
    
    //  rand template function implementation
    template<image_element_standard_floating_point_type ElementT = double, class... Size>
    requires((std::same_as<Size, std::size_t>&&...) or
             (std::same_as<Size, int>&&...))
    inline auto rand(Size... size)
    {
        return rand<ElementT>(std::mt19937{std::random_device{}()}, size...);
    }
    
    //  rand template function implementation
    template<image_element_standard_floating_point_type ElementT = double, typename Urbg>
    requires std::uniform_random_bit_generator<std::remove_reference_t<Urbg>>
    constexpr auto rand(Urbg&& urbg)
    {
        auto dist = std::uniform_real_distribution<ElementT>{};
        return Image<ElementT>(std::vector{ dist(urbg) }, 1, 1);
    }
    
    //  rand template function implementation
    template<image_element_standard_floating_point_type ElementT = double>
    inline auto rand()
    {
        return rand<ElementT>(std::mt19937{std::random_device{}()});
    }
    
Source Link
JimmyHu
  • 7.5k
  • 2
  • 11
  • 48
Loading