// File: kebwi[P]Trifid/src/ImageProcs.cpp
// Function: denoiseRGBImage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void denoiseRGBImage(string filename, string manualShrinkageThresholdStr)
{
	cout << "Denoising color image..." << endl;
	
	//Open the image
	Image3ChnlReal rgbImage;
	rgbImage.readFile(filename);
	
	//Construct a steerable pyramid of the image
	SteerablePyramid steerPyr[3];
	for (int c = 0; c < 3; c++)
		steerPyr[c].DoFullWaveletAnalysis(rgbImage[c]->img(), rgbImage[c]->width(), rgbImage[c]->height(), true);
	
	if (gGenerateIntermediateImages)
	{
		for (int c = 0; c < 3; c++)
		{
			string s = rgbImage.filename();
			if (c == 0)
				s += "_R";
			else if (c == 1)
				s += "_G";
			else s += "_B";
			steerPyr[c].GeneratePGMimages(s.c_str());
		}
	}
	
	int numLevels = steerPyr[0].NumLevels();
	cout << "Steerable pyramid will be built with " << numLevels << " levels" << endl;
	if (gManualShrinkageThresholds[0].size() != numLevels + 1)
		for (int c = 0; c < 3; c++)
			gManualShrinkageThresholds[c].resize(numLevels + 1);
	cout << "Thresholds:" << endl;
	for (int c = 0; c < 3; c++)
	{
		if (c == 0)
			cout << "  Red:" << endl;
		else if (c == 1)
			cout << "  Green:" << endl;
		else cout << "  Blue:" << endl;
		
		cout << "    H:  " << setw(10) << gManualShrinkageThresholds[c][0] << endl;
		cout << "    B:  ";
		for (int i = 1; i < gManualShrinkageThresholds[c].size(); i++)
			cout << setw(10) << gManualShrinkageThresholds[c][i];
		cout << endl;
	}
	cout << endl;
	
	//Shrink the coefficients
	for (int c = 0; c < 3; c++)
		steerPyr[c].SoftThreshold(gManualShrinkageThresholds[c]);
	
	if (gGenerateIntermediateImages)
	{
		for (int c = 0; c < 3; c++)
		{
			string s = rgbImage.filename();
			if (c == 0)
				s += "_R_sk";
			else if (c == 1)
				s += "_G_sk";
			else s += "_B_sk";
			steerPyr[c].GeneratePGMimages(s.c_str());
		}
	}
	
	//Synthesize the steerable pyramid
	Image3ChnlReal rgbImageShrunk(rgbImage.width(), rgbImage.height());
	for (int c = 0; c < 3; c++)
		steerPyr[c].DoFullWaveletSynthesis(rgbImageShrunk[c]->img());
	/*
	stringstream denoiseParamSS;
	denoiseParamSS << "_";
	for (int c = 0; c < 3; c++)
	{
		if (c == 0)
			denoiseParamSS << "R";
		else if (c == 1)
			denoiseParamSS << "G";
		else denoiseParamSS << "B";
		
		denoiseParamSS << gManualShrinkageThresholds[c][0];
		for (int i = 1; i < gManualShrinkageThresholds[c].size(); i++)
			denoiseParamSS << "," << gManualShrinkageThresholds[c][i];
	}
	*/
	rgbImageShrunk.setFilename(rgbImage.filename());
	rgbImageShrunk.appendFilename("_dn");
	rgbImageShrunk.appendFilename(manualShrinkageThresholdStr);
	rgbImageShrunk.writeFile(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x420, %rsp            # imm = 0x420
movq %rdi, -0x2c8(%rbp)
movq %rsi, -0x2d0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x355f8(%rip), %rdi     # 0x59fd0
leaq 0x270e9(%rip), %rsi     # 0x4bac8
callq 0x4390
movq %rax, %rdi
movq 0x355ca(%rip), %rsi     # 0x59fb8
callq 0x43d0
leaq -0x60(%rbp), %rdi
callq 0x17000
movq -0x2c8(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x4180
jmp 0x24a0e
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x17cc0
jmp 0x24a1d
leaq -0x80(%rbp), %rdi
callq 0x46c8
leaq -0x180(%rbp), %rax
movq %rax, -0x2e8(%rbp)
movq %rax, %rcx
addq $0xf0, %rcx
movq %rcx, -0x2e0(%rbp)
movq %rax, -0x2d8(%rbp)
movq -0x2d8(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
callq 0x293b0
jmp 0x24a61
movq -0x2e0(%rbp), %rcx
movq -0x2f0(%rbp), %rax
addq $0x50, %rax
cmpq %rcx, %rax
movq %rax, -0x2d8(%rbp)
jne 0x24a4c
movl $0x0, -0x184(%rbp)
cmpl $0x3, -0x184(%rbp)
jge 0x24c20
movslq -0x184(%rbp), %rax
movl %eax, %esi
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq -0x180(%rbp,%rax), %rax
movq %rax, -0x300(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xef40
movq %rax, -0x2f8(%rbp)
jmp 0x24ac8
movq -0x2f8(%rbp), %rdi
callq 0xf2c0
movq %rax, -0x308(%rbp)
jmp 0x24add
movl -0x184(%rbp), %esi
leaq -0x60(%rbp), %rdi
callq 0xef40
movq %rax, -0x310(%rbp)
jmp 0x24af5
movq -0x310(%rbp), %rdi
callq 0xedd0
movl %eax, -0x314(%rbp)
jmp 0x24b09
movl -0x184(%rbp), %esi
leaq -0x60(%rbp), %rdi
callq 0xef40
movq %rax, -0x320(%rbp)
jmp 0x24b21
movq -0x320(%rbp), %rdi
callq 0xedf0
movl %eax, -0x324(%rbp)
jmp 0x24b35
movl -0x324(%rbp), %ecx
movl -0x314(%rbp), %edx
movq -0x308(%rbp), %rsi
movq -0x300(%rbp), %rdi
movl $0x1, %r8d
callq 0x2d2c0
jmp 0x24b5c
jmp 0x24b5e
movl -0x184(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x184(%rbp)
jmp 0x24a89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x25516
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x46c8
jmp 0x25516
movq -0x2e8(%rbp), %rcx
movq %rax, %rsi
movq -0x2f0(%rbp), %rax
movq %rsi, -0x88(%rbp)
movl %edx, -0x8c(%rbp)
cmpq %rax, %rcx
movq %rax, -0x330(%rbp)
je 0x24c04
movq -0x330(%rbp), %rdi
addq $-0x50, %rdi
movq %rdi, -0x338(%rbp)
callq 0x299e0
movq -0x2e8(%rbp), %rcx
movq -0x338(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x330(%rbp)
jne 0x24bd3
jmp 0x25516
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x254c8
leaq 0x3598a(%rip), %rax     # 0x5a5b1
testb $0x1, (%rax)
je 0x24d32
movl $0x0, -0x188(%rbp)
cmpl $0x3, -0x188(%rbp)
jge 0x24d30
leaq -0x1a8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xf090
jmp 0x24c59
cmpl $0x0, -0x188(%rbp)
jne 0x24c9c
leaq 0x26e78(%rip), %rsi     # 0x4bae1
leaq -0x1a8(%rbp), %rdi
callq 0x4360
jmp 0x24c77
jmp 0x24cd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x46c8
jmp 0x254c8
cmpl $0x1, -0x188(%rbp)
jne 0x24cbc
leaq 0x26e38(%rip), %rsi     # 0x4bae4
leaq -0x1a8(%rbp), %rdi
callq 0x4360
jmp 0x24cba
jmp 0x24cd3
leaq 0x26e24(%rip), %rsi     # 0x4bae7
leaq -0x1a8(%rbp), %rdi
callq 0x4360
jmp 0x24cd1
jmp 0x24cd3
jmp 0x24cd5
movslq -0x188(%rbp), %rax
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq -0x180(%rbp,%rax), %rax
movq %rax, -0x340(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x4160
movq -0x340(%rbp), %rdi
movq %rax, %rsi
callq 0x30350
jmp 0x24d10
leaq -0x1a8(%rbp), %rdi
callq 0x46c8
movl -0x188(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x188(%rbp)
jmp 0x24c3a
jmp 0x24d32
leaq -0x180(%rbp), %rdi
callq 0x2bac0
movl %eax, -0x344(%rbp)
jmp 0x24d46
movl -0x344(%rbp), %eax
movl %eax, -0x1ac(%rbp)
movq 0x35277(%rip), %rdi     # 0x59fd0
leaq 0x26d2a(%rip), %rsi     # 0x4ba8a
callq 0x4390
movq %rax, -0x350(%rbp)
jmp 0x24d6e
movq -0x350(%rbp), %rdi
movl -0x1ac(%rbp), %esi
callq 0x4600
movq %rax, -0x358(%rbp)
jmp 0x24d89
movq -0x358(%rbp), %rdi
leaq 0x26d19(%rip), %rsi     # 0x4bab0
callq 0x4390
movq %rax, -0x360(%rbp)
jmp 0x24da5
movq -0x360(%rbp), %rdi
movq 0x35205(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x24dba
leaq 0x3584f(%rip), %rdi     # 0x5a610
callq 0xe5c0
movl -0x1ac(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0x24e27
movl $0x0, -0x1b0(%rbp)
cmpl $0x3, -0x1b0(%rbp)
jge 0x24e25
movslq -0x1b0(%rbp), %rax
leaq (%rax,%rax,2), %rcx
leaq 0x35814(%rip), %rax     # 0x5a610
leaq (%rax,%rcx,8), %rdi
movl -0x1ac(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0xe5e0
jmp 0x24e12
jmp 0x24e14
movl -0x1b0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b0(%rbp)
jmp 0x24de1
jmp 0x24e27
movq 0x351a2(%rip), %rdi     # 0x59fd0
leaq 0x26c83(%rip), %rsi     # 0x4bab8
callq 0x4390
movq %rax, -0x368(%rbp)
jmp 0x24e43
movq -0x368(%rbp), %rdi
movq 0x35167(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x24e58
movl $0x0, -0x1b4(%rbp)
cmpl $0x3, -0x1b4(%rbp)
jge 0x250c6
cmpl $0x0, -0x1b4(%rbp)
jne 0x24eab
movq 0x35151(%rip), %rdi     # 0x59fd0
leaq 0x26c64(%rip), %rsi     # 0x4baea
callq 0x4390
movq %rax, -0x370(%rbp)
jmp 0x24e94
movq -0x370(%rbp), %rdi
movq 0x35116(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x24ea9
jmp 0x24f1c
cmpl $0x1, -0x1b4(%rbp)
jne 0x24ee7
movq 0x35115(%rip), %rdi     # 0x59fd0
leaq 0x26c2f(%rip), %rsi     # 0x4baf1
callq 0x4390
movq %rax, -0x378(%rbp)
jmp 0x24ed0
movq -0x378(%rbp), %rdi
movq 0x350da(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x24ee5
jmp 0x24f1a
movq 0x350e2(%rip), %rdi     # 0x59fd0
leaq 0x26c05(%rip), %rsi     # 0x4bafa
callq 0x4390
movq %rax, -0x380(%rbp)
jmp 0x24f03
movq -0x380(%rbp), %rdi
movq 0x350a7(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x24f18
jmp 0x24f1a
jmp 0x24f1c
movq 0x350ad(%rip), %rdi     # 0x59fd0
leaq 0x26bd8(%rip), %rsi     # 0x4bb02
callq 0x4390
movq %rax, -0x388(%rbp)
jmp 0x24f38
movl $0xa, %edi
callq 0xe410
movl %eax, -0x38c(%rbp)
jmp 0x24f4a
movq -0x388(%rbp), %rdi
movl -0x38c(%rbp), %eax
movl %eax, -0x1b8(%rbp)
movl -0x1b8(%rbp), %esi
callq 0x4430
movq %rax, -0x398(%rbp)
jmp 0x24f71
movslq -0x1b4(%rbp), %rax
leaq (%rax,%rax,2), %rcx
leaq 0x3568d(%rip), %rax     # 0x5a610
leaq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xe670
movq -0x398(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x4670
movq %rax, -0x3a0(%rbp)
jmp 0x24fa9
movq -0x3a0(%rbp), %rdi
movq 0x35001(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x24fbe
movq 0x3500b(%rip), %rdi     # 0x59fd0
leaq 0x26b3f(%rip), %rsi     # 0x4bb0b
callq 0x4390
jmp 0x24fd3
movl $0x1, -0x1bc(%rbp)
movslq -0x1bc(%rbp), %rax
movq %rax, -0x3a8(%rbp)
movslq -0x1b4(%rbp), %rax
leaq 0x35617(%rip), %rdi     # 0x5a610
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0xe5c0
movq %rax, %rcx
movq -0x3a8(%rbp), %rax
cmpq %rcx, %rax
jae 0x2509b
movl $0xa, %edi
callq 0xe410
movl %eax, -0x3ac(%rbp)
jmp 0x2502a
movl -0x3ac(%rbp), %eax
movl %eax, -0x1c0(%rbp)
movl -0x1c0(%rbp), %esi
movq 0x34f8d(%rip), %rdi     # 0x59fd0
callq 0x4430
movq %rax, -0x3b8(%rbp)
jmp 0x25051
movslq -0x1b4(%rbp), %rax
leaq (%rax,%rax,2), %rcx
leaq 0x355ad(%rip), %rax     # 0x5a610
leaq (%rax,%rcx,8), %rdi
movslq -0x1bc(%rbp), %rsi
callq 0xe670
movq -0x3b8(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x4670
jmp 0x25085
jmp 0x25087
movl -0x1bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1bc(%rbp)
jmp 0x24fdd
movq 0x34f2e(%rip), %rdi     # 0x59fd0
movq 0x34f0f(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x250b0
jmp 0x250b2
movl -0x1b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b4(%rbp)
jmp 0x24e62
movq 0x34f03(%rip), %rdi     # 0x59fd0
movq 0x34ee4(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x250db
movl $0x0, -0x1c4(%rbp)
cmpl $0x3, -0x1c4(%rbp)
jge 0x25182
movslq -0x1c4(%rbp), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
leaq -0x180(%rbp,%rcx), %rcx
movq %rcx, -0x3c0(%rbp)
leaq (%rax,%rax,2), %rcx
leaq 0x354f5(%rip), %rax     # 0x5a610
leaq (%rax,%rcx,8), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x1d890
jmp 0x2512d
movq -0x3c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x2ec80
jmp 0x25142
leaq -0x1e0(%rbp), %rdi
callq 0xe260
movl -0x1c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c4(%rbp)
jmp 0x250e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0xe260
jmp 0x254c8
leaq 0x35428(%rip), %rax     # 0x5a5b1
testb $0x1, (%rax)
je 0x25294
movl $0x0, -0x1e4(%rbp)
cmpl $0x3, -0x1e4(%rbp)
jge 0x25292
leaq -0x208(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xf090
jmp 0x251bb
cmpl $0x0, -0x1e4(%rbp)
jne 0x251fe
leaq 0x26949(%rip), %rsi     # 0x4bb14
leaq -0x208(%rbp), %rdi
callq 0x4360
jmp 0x251d9
jmp 0x25237
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x46c8
jmp 0x254c8
cmpl $0x1, -0x1e4(%rbp)
jne 0x2521e
leaq 0x2690c(%rip), %rsi     # 0x4bb1a
leaq -0x208(%rbp), %rdi
callq 0x4360
jmp 0x2521c
jmp 0x25235
leaq 0x268fb(%rip), %rsi     # 0x4bb20
leaq -0x208(%rbp), %rdi
callq 0x4360
jmp 0x25233
jmp 0x25235
jmp 0x25237
movslq -0x1e4(%rbp), %rax
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq -0x180(%rbp,%rax), %rax
movq %rax, -0x3c8(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x4160
movq -0x3c8(%rbp), %rdi
movq %rax, %rsi
callq 0x30350
jmp 0x25272
leaq -0x208(%rbp), %rdi
callq 0x46c8
movl -0x1e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e4(%rbp)
jmp 0x2519c
jmp 0x25294
leaq -0x60(%rbp), %rdi
callq 0xedd0
movl %eax, -0x3cc(%rbp)
jmp 0x252a5
leaq -0x60(%rbp), %rdi
callq 0xedf0
movl %eax, -0x3d0(%rbp)
jmp 0x252b6
movl -0x3d0(%rbp), %edx
movl -0x3cc(%rbp), %esi
leaq -0x258(%rbp), %rdi
callq 0x17410
jmp 0x252d0
movl $0x0, -0x25c(%rbp)
cmpl $0x3, -0x25c(%rbp)
jge 0x25370
movslq -0x25c(%rbp), %rax
movl %eax, %esi
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq -0x180(%rbp,%rax), %rax
movq %rax, -0x3e0(%rbp)
leaq -0x258(%rbp), %rdi
callq 0xef40
movq %rax, -0x3d8(%rbp)
jmp 0x2531c
movq -0x3d8(%rbp), %rdi
callq 0xf2c0
movq %rax, -0x3e8(%rbp)
jmp 0x25331
movq -0x3e8(%rbp), %rsi
movq -0x3e0(%rbp), %rdi
callq 0x2e250
jmp 0x25346
jmp 0x25348
movl -0x25c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x25c(%rbp)
jmp 0x252da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x254bc
leaq -0x280(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xf090
jmp 0x25382
leaq -0x258(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x154b0
jmp 0x25397
leaq -0x280(%rbp), %rdi
callq 0x46c8
leaq 0x2671a(%rip), %rsi     # 0x4bac4
leaq -0x258(%rbp), %rdi
callq 0xf220
jmp 0x253b8
movq -0x2d0(%rbp), %rsi
leaq -0x2a0(%rbp), %rdi
callq 0x4180
jmp 0x253cd
leaq -0x258(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x154f0
jmp 0x253e2
leaq -0x2a0(%rbp), %rdi
callq 0x46c8
leaq -0x2c0(%rbp), %rdi
leaq -0x258(%rbp), %rsi
movl $0x1, %edx
callq 0x18430
jmp 0x25408
leaq -0x2c0(%rbp), %rdi
callq 0x46c8
leaq -0x258(%rbp), %rdi
callq 0x175b0
leaq -0x180(%rbp), %rax
movq %rax, -0x3f8(%rbp)
addq $0xf0, %rax
movq %rax, -0x3f0(%rbp)
movq -0x3f0(%rbp), %rdi
addq $-0x50, %rdi
movq %rdi, -0x400(%rbp)
callq 0x299e0
movq -0x3f8(%rbp), %rcx
movq -0x400(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x3f0(%rbp)
jne 0x2543b
leaq -0x60(%rbp), %rdi
callq 0x175b0
addq $0x420, %rsp            # imm = 0x420
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x46c8
jmp 0x254bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x46c8
leaq -0x258(%rbp), %rdi
callq 0x175b0
leaq -0x180(%rbp), %rax
movq %rax, -0x410(%rbp)
addq $0xf0, %rax
movq %rax, -0x408(%rbp)
movq -0x408(%rbp), %rdi
addq $-0x50, %rdi
movq %rdi, -0x418(%rbp)
callq 0x299e0
movq -0x410(%rbp), %rcx
movq -0x418(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x408(%rbp)
jne 0x254e3
jmp 0x25516
leaq -0x60(%rbp), %rdi
callq 0x175b0
movq -0x88(%rbp), %rdi
callq 0x4620
nopl (%rax,%rax)