
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-04-28 Fabien Freling <fabien.freling@lrde.epita.fr> Convert Matlab images to Milena images. * fabien/igr/mat2mln/mat2mln.cc: Convert matlab ascii format to mln format. * fabien/igr/mat2mln/raw2mlndata.cc: Deprecated. * fabien/igr/seg_fixed.cc: Update. --- TODO | 59 -------------------------------------------- igr/mat2mln/mat2mln.cc | 60 +++++++++++++++++++++++++++++++++++++++++++++ igr/mat2mln/raw2mlndata.cc | 9 +++++- igr/seg_fixed.cc | 42 +++++++++++++++---------------- 4 files changed, 89 insertions(+), 81 deletions(-) Index: trunk/milena/sandbox/fabien/igr/seg_fixed.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/seg_fixed.cc (revision 3718) +++ trunk/milena/sandbox/fabien/igr/seg_fixed.cc (revision 3719) @@ -13,6 +13,7 @@ #include <mln/accu/sum.hh> #include <mln/data/fill.hh> +#include <mln/debug/quiet.hh> #include <mln/convert/from_to.hh> #include <mln/level/compute.hh> #include <mln/util/array.hh> @@ -27,20 +28,20 @@ point2d get_edge_location(point2d p, point2d n) { - point2d res(p); + point2d res; - res.to_vec()[0] *= 2; - res.to_vec()[1] *= 2; + res[0] = p[0] * 2; + res[1] = p[1] * 2; - if (n.to_vec()[0] > p.to_vec()[0]) - ++(res.to_vec()[0]); - if (n.to_vec()[0] < p.to_vec()[0]) - --(res.to_vec()[0]); - - if (n.to_vec()[1] > p.to_vec()[1]) - ++(res.to_vec()[1]); - if (n.to_vec()[1] < p.to_vec()[1]) - --(res.to_vec()[1]); + if (n[0] > p[0]) + ++(res[0]); + if (n[0] < p[0]) + --(res[0]); + + if (n[1] > p[1]) + ++(res[1]); + if (n[1] < p[1]) + --(res[1]); return res; } @@ -55,12 +56,13 @@ { float res = 0.f; + if (!ima_sum.bbox().has(n)) + return res; + for (unsigned i = 0; i < ima_arr(p).nelements(); ++i) res += std::min(ima_arr(p)[i], ima_arr(n)[i]); res /= std::max(ima_sum(p), ima_sum(n)); - std::cout << "dist = " << res << std::endl; - return res; } @@ -83,23 +85,22 @@ image2d<float> dist_on_edges(image2d<util::array<I> > ima_arr) { - image2d<float> edges(2 * ima_arr.nrows(), 2 * ima_arr.ncols()); + box2d b = ima_arr.bbox(); + image2d<float> edges(make::box2d(2 * b.pmin()[0], 2 * b.pmin()[1], + 2 * b.pmax()[0], 2 * b.pmax()[1])); data::fill(edges, -1.f); image2d<float> ima_sum; initialize(ima_sum, ima_arr); compute_sum_arrays(ima_sum, ima_arr); - std::cout << "can i has a loop?" << std::endl; mln_piter(image2d<util::array<I> >) p(ima_arr.domain()); + mln_niter(neighb2d) n(c4(), p); for_all(p) { - std::cout << "for_all(p)" << std::endl; - mln_niter(neighb2d) n(c4(), p); for_all(n) { - std::cout << "for_all(n)" << std::endl; point2d location = get_edge_location(p, n); - std::cout << "location = " << p << " && edge = " << edges(location) << std::endl; + //std::cout << "p: " << p << " | n: " << n << " | e: " << location << std::endl; if (edges(location) == -1.f) edges(location) = compute_dist(ima_arr, ima_sum, p, n); } @@ -135,7 +136,6 @@ ima_arr(p).append(tmp_slice(p)); } - std::cout << "ho hai _o/" << std::endl; image2d<float> edges = dist_on_edges(ima_arr); return 0; Index: trunk/milena/sandbox/fabien/igr/mat2mln/raw2mlndata.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/mat2mln/raw2mlndata.cc (revision 3718) +++ trunk/milena/sandbox/fabien/igr/mat2mln/raw2mlndata.cc (revision 3719) @@ -27,6 +27,7 @@ unsigned int size = 0; unsigned int offset = 0; + // Top level miMATRIX. offset += 4; input.seekg(offset); @@ -64,11 +65,13 @@ delete name; offset += 8 - size % 8; + std::cout << "----" << std::endl; // FIXME: Decode data. offset = 128; + // Data miMATRIX. offset += 4; input.seekg(offset); @@ -103,10 +106,11 @@ input.seekg(offset); input.read((char*) &nslis, sizeof (unsigned int)); offset += sizeof (unsigned int); + offset += sizeof (unsigned int); // Padding. std::cout << "ncols: " << ncols << "; nrows: " << nrows << "; nslis: " << nslis << std::endl; // Data buffer. - typedef int V; + typedef double V; int data_size = ncols * nrows * nslis; V* data_buffer = new V[data_size]; input.seekg(offset); @@ -119,7 +123,8 @@ // Debug. image2d<V> ima_debug; ima_debug = duplicate(slice(ima, 50)); - io::pgm::save(level::stretch(value::int_u8(), ima_debug), "debug.pgm"); + //io::pgm::save(level::stretch(value::int_u8(), ima_debug), "debug.pgm"); + io::pgm::save(ima_debug, "debug.pgm"); return 0; } Index: trunk/milena/sandbox/fabien/igr/mat2mln/mat2mln.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/mat2mln/mat2mln.cc (revision 0) +++ trunk/milena/sandbox/fabien/igr/mat2mln/mat2mln.cc (revision 3719) @@ -0,0 +1,60 @@ +#include <iostream> +#include <fstream> + +#include <mln/core/image/image3d.hh> +#include <mln/io/dump/save.hh> + +#include <mln/core/image/image2d.hh> +#include <mln/debug/slices_2d.hh> +#include <mln/value/int_u8.hh> +#include <mln/io/pgm/save.hh> +#include <mln/level/stretch.hh> + +using namespace mln; +using value::int_u8; + +#define MAX_SLI 750 +#define MAX_ROW 375 +#define MAX_COL 80 + + + +int main(int argc, char* argv[]) +{ + if (argc != 3) + { + std::cout << "Usage: " << argv[0] << " cube.in dump.out" << std::endl; + return 1; + } + + image3d<unsigned int> ima(MAX_SLI, MAX_ROW, MAX_COL); + + std::ifstream file_in(argv[1]); + unsigned int val; + unsigned int col = 0; + unsigned int row = 0; + unsigned int sli = 0; + + while (file_in >> val) + { + ima.at_(sli, row, col) = val; + ++row; + if (row % MAX_ROW == 0) + { + row = 0; + ++sli; + if (sli % MAX_SLI == 0) + { + sli = 0; + ++col; + } + } + } + + io::dump::save(ima, argv[2]); + + image2d<int_u8> ima_flat = debug::slices_2d(level::stretch(int_u8(), ima), 1.f, 0); + io::pgm::save(ima_flat, "debug.pgm"); + + return 0; +} Index: trunk/milena/sandbox/fabien/TODO =================================================================== --- trunk/milena/sandbox/fabien/TODO (revision 3718) +++ trunk/milena/sandbox/fabien/TODO (revision 3719) @@ -7,62 +7,5 @@ ||----w | || || -[X] Create binaries -[X] Create scripts shell -[X] Generate color images for regions -[X] Generate histograms (normal, bg, obj, p_bg, p_obj) -[ ] Test processing chain on US -[X] Create README file for special images -[X] Implement watershed -[X] Create tool for dicom mask -[X] Check conversion for mask (everything except int_u12(0)) -[ ] Extract ROI (projection or fill holes) -[ ] Create routine for region colors -[X] Create dicom2dump (2d, 3d, int_u8, int_u12) -[ ] After threshold, take biggest object and then erode, dilate -[ ] Fix n_max -[ ] Create routine for binary images (keep n big bg & m big objects) -[X] US: projection of internal gradient -[X] Create 3D US morpho with 2D stack -[ ] Create macro for_all_slice -[X] Batch process watershed with 2D, 3D and any combination of parameters -[X] Cut into small tools -[X] Test 3D workflow on 2D images -[X] Create colorized colors for graph -[X] Diff with % -[X] Find biggest dark regions (threshold value or median accu - median / 2 - ) - [X] Learn regions value - [X] Threshold - [X] 3D - [X] Print nb bg regions // nb fg objets -[ ] Profile for performance -[X] ImageMagick support -[ ] Integrate external libraries (GDCM, IM) -[X] Send result images to lrde account -[X] Translate Matlab code -[X] Subsample binary images -[X] Fast projected histogram -[ ] Triple histogram -[X] Create plot for each kind of point with each method -[ ] Fix mean slices values -[X] Compatibility Windows -[X] Fix spatial smooth -[X] Crop volume 52 -[X] Plot all labels (3, 4 labels for tumeur) -[X] Prepare data for IGR - [X] crop->norm->tmax - [X] crop->norm->space_smooth->tmax - - (comparo normalisé) - 1)brut - 2)time_smooth - 3)space_smooth - 4)current_label_smooth (lambda faible, pas de ligne watershed) - - [X] plot label - [X] gif animés labels - - [X] fausses couleurs watershed - [X] images moyennes +[ ] Create values between pixels [ ] Watershed between pixels -[ ] Mat2Mln