Skip to content

Commit

Permalink
add debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
zEttOn86 committed May 23, 2019
1 parent a6aee11 commit 3c59c89
Show file tree
Hide file tree
Showing 15 changed files with 947 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apply_em_algorithm/em_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace em_algorithm
if (weight(s, l) > eps0Weight) {
weight_sum += weight(s, l);
for (int f = 0; f < num_features; f++) {
ave(f, 0) += static_cast<double>(feat_samples.at(f*num_samples + s)) + weight(s, l);
ave(f, 0) += static_cast<double>(feat_samples.at(f*num_samples + s)) * weight(s, l);
}
}
} /* Sample loop */
Expand Down
10 changes: 10 additions & 0 deletions atlas-guided-em-algorithm.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "apply_em_algorithm", "apply
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "apply_maximum_a_posteriori", "apply_maximum_a_posteriori\apply_maximum_a_posteriori.vcxproj", "{B87B8835-EB4D-4CE3-A36A-499A1095E78B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "generate_debug_img", "generate_debug_img\generate_debug_img.vcxproj", "{FBDCD7E6-C441-4321-90F0-B3FAA21DA420}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -61,6 +63,14 @@ Global
{B87B8835-EB4D-4CE3-A36A-499A1095E78B}.Release|x64.Build.0 = Release|x64
{B87B8835-EB4D-4CE3-A36A-499A1095E78B}.Release|x86.ActiveCfg = Release|Win32
{B87B8835-EB4D-4CE3-A36A-499A1095E78B}.Release|x86.Build.0 = Release|Win32
{FBDCD7E6-C441-4321-90F0-B3FAA21DA420}.Debug|x64.ActiveCfg = Debug|x64
{FBDCD7E6-C441-4321-90F0-B3FAA21DA420}.Debug|x64.Build.0 = Debug|x64
{FBDCD7E6-C441-4321-90F0-B3FAA21DA420}.Debug|x86.ActiveCfg = Debug|Win32
{FBDCD7E6-C441-4321-90F0-B3FAA21DA420}.Debug|x86.Build.0 = Debug|Win32
{FBDCD7E6-C441-4321-90F0-B3FAA21DA420}.Release|x64.ActiveCfg = Release|x64
{FBDCD7E6-C441-4321-90F0-B3FAA21DA420}.Release|x64.Build.0 = Release|x64
{FBDCD7E6-C441-4321-90F0-B3FAA21DA420}.Release|x86.ActiveCfg = Release|Win32
{FBDCD7E6-C441-4321-90F0-B3FAA21DA420}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
13 changes: 13 additions & 0 deletions generate_debug_img/expdev.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <math.h>

float expdev(long *idum)
{
float ran1(long *idum);
float dum;

do
dum = ran1(idum);
while (dum == 0.0);
//printf("%f\t%f\n", dum, -log(dum));
return -log(dum);
}
26 changes: 26 additions & 0 deletions generate_debug_img/gasdev.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <math.h>

float gasdev(long *idum)
{
float ran1(long *idum);
static int iset = 0;
static float gset;
float fac, rsq, v1, v2;

if (*idum < 0) iset = 0;
if (iset == 0) {
do {
v1 = 2.0*ran1(idum) - 1.0;
v2 = 2.0*ran1(idum) - 1.0;
rsq = v1*v1 + v2*v2;
} while (rsq >= 1.0 || rsq == 0.0);
fac = sqrt(-2.0*log(rsq) / rsq);
gset = v1*fac;
iset = 1;
return v2*fac;
}
else {
iset = 0;
return gset;
}
}
219 changes: 219 additions & 0 deletions generate_debug_img/generate_debug_img.vcxproj

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions generate_debug_img/generate_debug_img.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="ソース ファイル">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="ヘッダー ファイル">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="リソース ファイル">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="random.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="nrutil.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
</ItemGroup>
</Project>
75 changes: 75 additions & 0 deletions generate_debug_img/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include<iostream>
#include "ItkImageIO.h"
#include "dataIO.h"
#include "random.h"

#define X_SIZE 170
#define Y_SIZE 170
#define Z_SIZE 1

#define MIXTURE_RATIO 0.8
#define MEAN1 7.0
#define VAR1 5.0
#define MEAN2 -4.0
#define VAR2 3.0

typedef double feat_t;
typedef unsigned char mask_t;
typedef unsigned char label_t;

int main(int argc, char **argv) {

if (argc != 2) {
std::cerr << "Usage:" << std::endl;
std::cerr << argv[0] << " <output directory> "
<< std::endl;
return EXIT_FAILURE;
}
std::string output_dir = std::string(argv[1]) + "/";

long idum = -1;

int xe = X_SIZE;
int ye = Y_SIZE;
int ze = Z_SIZE;
int se = xe*ye*ze;
std::vector<feat_t> img(se, 0);
std::vector<label_t> label_img(se, 0);


// class 1
int x1 = (int)(xe*MIXTURE_RATIO + 0.5);
for (int y = 0; y < ye; y++) {
for (int x = 0; x < x1; x++) {
img.at(xe*y + x) = normal(&idum, sqrt(VAR1)) + MEAN1;
label_img.at(xe*y + x) = 0;

}
}

// class 2
for (int y = 0; y < ye; y++) {
for (int x = x1; x < xe; x++) {
img.at(xe*y + x) = normal(&idum, sqrt(VAR2)) + MEAN2;
label_img.at(xe*y + x) = 1;
}
}

// Save image
std::string result_dir = output_dir+"org";
make_dir(result_dir);
save_vector(result_dir + "/debug.mhd", img, xe, ye, ze, 1., 1., 1.);

result_dir = output_dir + "label";
make_dir(result_dir);
save_vector(result_dir + "/debug.mhd", label_img, xe, ye, ze, 1., 1., 1.);


// For mask
std::vector<mask_t> mask(se, 1);
result_dir = output_dir + "mask";
make_dir(result_dir);
save_vector(result_dir + "/debug.mhd", mask, xe, ye, ze, 1., 1., 1.);

return EXIT_SUCCESS;
}
Loading

0 comments on commit 3c59c89

Please sign in to comment.