URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-04-24 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Add binary tools for parsing of .mat files.
* fabien/igr/mat2mln/mat2raw.cc: Uncompress .mat data.
* fabien/igr/mat2mln/raw2mlndata.cc: Convert uncompressed .mat data
to Milena dump format.
* fabien/igr/seg_fixed.cc: Creation of edges between pixels.
---
TODO | 4 +
igr/mat2mln/mat2raw.cc | 52 ++++++++++++++++++++
igr/mat2mln/raw2mlndata.cc | 113 +++++++++++++++++++++++++++++++++++++++++++++
igr/seg_fixed.cc | 25 ++++++---
4 files changed, 184 insertions(+), 10 deletions(-)
Index: trunk/milena/sandbox/fabien/igr/seg_fixed.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/seg_fixed.cc (revision 3703)
+++ trunk/milena/sandbox/fabien/igr/seg_fixed.cc (revision 3704)
@@ -59,6 +59,8 @@
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;
}
@@ -87,15 +89,21 @@
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);
- if (edges(location) != -1)
+ std::cout << "location = " << p << " &&
edge = " << edges(location) << std::endl;
+ if (edges(location) == -1.f)
edges(location) = compute_dist(ima_arr, ima_sum, p, n);
}
+ }
return edges;
}
@@ -112,23 +120,22 @@
int main(int argc, char* argv[])
{
- typedef int_u12 I;
-
if (argc != 2)
return usage(argv[0]);
- image3d<I> input;
- io::dump::save(input, argv[1]);
- image2d<util::array<I> > ima_arr;
+ image3d<int_u12> input;
+ io::dump::load(input, argv[1]);
+ image2d<util::array<int_u12> > ima_arr;
initialize(ima_arr, slice(input, 0));
for (unsigned int i = 0; i < input.nslices(); ++i)
{
- image2d<I> tmp_slice = duplicate(slice(input, i));
- mln_piter_(image2d<I>) p(tmp_slice.domain());
+ image2d<int_u12> tmp_slice = duplicate(slice(input, i));
+ mln_piter_(image2d<int_u12>) p(tmp_slice.domain());
for_all(p)
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 0)
+++ trunk/milena/sandbox/fabien/igr/mat2mln/raw2mlndata.cc (revision 3704)
@@ -0,0 +1,113 @@
+#include <iostream>
+#include <fstream>
+
+#include <mln/core/image/image3d.hh>
+#include <mln/io/dump/save.hh>
+
+using namespace mln;
+
+
+int main(int argc, char* argv[])
+{
+ if (argc != 3)
+ {
+ std::cout << "Usage: " << argv[0] << " input.raw
output.raw" << std::endl;
+ return 1;
+ }
+
+ std::ifstream input(argv[1]);
+
+ unsigned int size = 0;
+ unsigned int offset = 0;
+
+ // Top level miMATRIX.
+ offset += 4;
+ input.seekg(offset);
+ input.read((char*) &size, sizeof (unsigned int));
+ offset += sizeof (unsigned int);
+ std::cout << "Size: " << size << std::endl;
+
+ // Array flags.
+ offset += 4;
+ input.seekg(offset);
+ input.read((char*) &size, sizeof (unsigned int));
+ offset += sizeof (unsigned int);
+ std::cout << "Flags size: " << size << std::endl;
+
+ // Dimensions array.
+ offset += size;
+ offset += 4;
+ input.seekg(offset);
+ input.read((char*) &size, sizeof (unsigned int));
+ offset += sizeof (unsigned int);
+ std::cout << "Dimensions size: " << size << std::endl;
+
+ // Array name.
+ offset += size;
+ offset += 4;
+ input.seekg(offset);
+ input.read((char*) &size, sizeof (unsigned int));
+ offset += sizeof (unsigned int);
+ std::cout << "Name size: " << size << std::endl;
+ char* name = new char[size + 1];
+ input.seekg(offset);
+ input.read((char*) name, size);
+ name[size + 1] = '\0';
+ std::cout << "Array name: " << name << std::endl;
+ delete name;
+ offset += 8 - size % 8;
+
+ std::cout << "----" << std::endl;
+ // FIXME: Decode data.
+
+ offset = 128;
+
+ // Data miMATRIX.
+ offset += 4;
+ input.seekg(offset);
+ input.read((char*) &size, sizeof (unsigned int));
+ offset += sizeof (unsigned int);
+ std::cout << "Data size: " << size << std::endl;
+
+ // Array flags.
+ offset += 4;
+ input.seekg(offset);
+ input.read((char*) &size, sizeof (unsigned int));
+ offset += sizeof (unsigned int);
+ std::cout << "Flags size: " << size << std::endl;
+
+ // Dimensions array.
+ offset += size;
+ offset += 4;
+ input.seekg(offset);
+ input.read((char*) &size, sizeof (unsigned int));
+ offset += sizeof (unsigned int);
+ std::cout << "Dimensions size: " << size << std::endl;
+ std::cout << "Number of dimensions: " << size / 4 <<
std::endl;
+ int ncols = 0;
+ int nrows = 0;
+ int nslis = 0;
+ input.seekg(offset);
+ input.read((char*) &ncols, sizeof (unsigned int));
+ offset += sizeof (unsigned int);
+ input.seekg(offset);
+ input.read((char*) &nrows, sizeof (unsigned int));
+ offset += sizeof (unsigned int);
+ input.seekg(offset);
+ input.read((char*) &nslis, sizeof (unsigned int));
+ offset += sizeof (unsigned int);
+ std::cout << "ncols: " << ncols << "; nrows: "
<< nrows << "; nslis: " << nslis << std::endl;
+
+ // Data buffer.
+ typedef double V;
+ int data_size = ncols * nrows * nslis;
+ V* data_buffer = new V[data_size];
+ input.seekg(offset);
+ input.read((char*) data_buffer, data_size);
+
+ image3d<V> ima(nslis, nrows, ncols);
+ memcpy(ima.buffer(), data_buffer, data_size);
+ io::dump::save(ima, argv[2]);
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/mat2mln/mat2raw.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/mat2mln/mat2raw.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/mat2mln/mat2raw.cc (revision 3704)
@@ -0,0 +1,52 @@
+#include <iostream>
+#include <fstream>
+
+#include <zlib.h>
+
+int main(int argc, char* argv[])
+{
+ if (argc != 3)
+ {
+ std::cout << "Usage: " << argv[0] << " input.mat
output.raw" << std::endl;
+ return 1;
+ }
+
+ std::ifstream input(argv[1]);
+
+ // Fetch data.
+ unsigned int size;
+ input.seekg(132);
+ input.read((char*) &size, sizeof(unsigned int));
+ std::cout << "Size: " << size << std::endl;
+ unsigned char* data_buffer = new unsigned char[size];
+ input.read((char*) data_buffer, size);
+ input.close();
+
+ // Decompress.
+ unsigned long dest_size = 2 * size;
+ unsigned char* dest_buffer = new unsigned char[dest_size];
+ int dezip_result = uncompress(dest_buffer, &dest_size, data_buffer, size);
+
+ switch (dezip_result)
+ {
+ case Z_OK:
+ std::cout << "Z_OK" << std::endl;
+ std::cout << "Dest size: " << dest_size << std::endl;
+ break;
+ case Z_MEM_ERROR:
+ std::cout << "Z_MEM_ERROR" << std::endl;
+ break;
+ case Z_BUF_ERROR:
+ std::cout << "Z_BUF_ERROR" << std::endl;
+ break;
+ case Z_DATA_ERROR:
+ std::cout << "Z_DATA_ERROR" << std::endl;
+ break;
+ }
+
+ // Write buffer to disk.
+ std::ofstream save_file(argv[2]);
+ save_file.write((char*) dest_buffer, dest_size);
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/TODO
===================================================================
--- trunk/milena/sandbox/fabien/TODO (revision 3703)
+++ trunk/milena/sandbox/fabien/TODO (revision 3704)
@@ -49,7 +49,7 @@
[X] Fix spatial smooth
[X] Crop volume 52
[X] Plot all labels (3, 4 labels for tumeur)
-[ ] Prepare data for IGR
+[X] Prepare data for IGR
[X] crop->norm->tmax
[X] crop->norm->space_smooth->tmax
@@ -64,3 +64,5 @@
[X] fausses couleurs watershed
[X] images moyennes
+[ ] Watershed between pixels
+[ ] Mat2Mln