11 #include <cartobase/object/object.h>
12 #include <cartobase/stream/directory.h>
13 #include <cartobase/stream/fileutil.h>
14 #include <aims/io/channelR.h>
22 template<
class T>
bool
23 detectSlices(aims::Process & p,
const std::string &, aims::Finder &)
40 carto::VolumeRef<int16_t> vol;
44 aims::ChannelReader<carto::VolumeRef<int16_t> > reader(proc.
fileIn);
45 reader.read(vol, proc.
c);
46 std::cout <<
"Original image loaded" << std::endl;
49 std::vector<Component> components = detector.
analyze(vol, proc.
n, proc.
res,
112 aims::Writer<carto::Object> w(proc.
fileOut);
113 const std::string format(
"JSON");
114 return w.write(bounds,
false, &format);
117 template<
class T>
bool
123 carto::VolumeRef<T> vol;
125 std::vector<Component> components;
138 carto::VolumeRef<int16_t> volgrey;
144 aims::ChannelReader<carto::VolumeRef<int16_t> > reader(proc.
fileInP);
145 reader.read(volgrey, proc.
c);
146 std::cout <<
"Pre-processed image loaded" << std::endl;
150 aims::ChannelReader<carto::VolumeRef<int16_t> > reader(proc.
fileIn);
151 reader.read(volgrey, proc.
c);
152 std::cout <<
"Original image loaded" << std::endl;
162 components = detector.
analyze(volgrey, proc.
n, proc.
res,
168 std::vector<int32_t> columnsizes;
171 columnsizes.push_back(1);
180 std::cout <<
"Last sort processed (according to slice taking) ..."
183 std::cout << std::endl;
185 std::cout << std::endl;
188 aims::Reader<carto::VolumeRef<T> > fileIn(proc.
fileIn);
191 T bg = background<T>(components, vol);
192 std::cout <<
"Background : " << toString(bg) << std::endl;
198 std::string outname = (proc.
outName.empty() ? FileUtil::removeExtension(
212 std::cout <<
"Volume written to output directory. Terminated."
224 std::cout <<
"Volume written to output file. Terminated." << std::endl;
236 void rescale(carto::VolumeRef<T> &in, RescalerInfo & info)
238 if (std::isnan(info.vmin)) {
239 if (! info.usevtypelimits) {
240 info.vmin = (double) in.min();
244 if (std::isnan(info.vmax)) {
245 if (! info.usevtypelimits) {
246 info.vmax = (double) in.max();
250 DefaultedRescalerInfo<T, T> defaultedinfo(info);
258 for (t = 0; t < dt; ++t)
260 for (z = 0; z < dz; ++z)
262 for (y = 0; y < dy; ++y)
264 for (x = 0; x < dx; ++x)
265 in(x, y, z, t) = defaultedinfo.getScaledValue(
276 std::vector<Component> &cpnt,
277 carto::VolumeRef<T> &data,
278 std::string outputfile,
283 const std::string *wf = 0;
287 Object options = Object::value(Dictionary());
298 throw dimension_x_error();
309 throw dimension_y_error();
312 carto::VolumeRef<T> recons_volume(dx, dy, cpnt.size());
313 std::vector<float> vs(4, 1.);
318 recons_volume.header().setProperty(
"voxel_size", vs);
323 std::cout <<
"Reconstructing volume ..." << std::endl << std::endl;
324 for (l = 0; l < int32_t(cpnt.size()); ++l)
326 Point2d shift, size_component;
328 size_component[0] = cpnt[l].bounding_hz + 2 *
BORDER_LOCAL;
329 size_component[1] = cpnt[l].bounding_vt + 2 *
BORDER_LOCAL;
331 shift[0] = (dx - size_component[0]) / 2;
332 shift[1] = (dy - size_component[1]) / 2;
334 for (y = 0; y < size_component[1] ; ++y)
335 for (x = 0; x < size_component[0] ; ++x)
338 && ((x + cpnt[l].abscissa_x -
BORDER_LOCAL) < data.getSizeX())
340 && ((y + cpnt[l].ordinate_y -
BORDER_LOCAL) < data.getSizeY()))
342 recons_volume(x + shift[0],
344 cpnt[l].label_f - 1) = data(
351 std::cout <<
"Stacking process achieved." << std::endl;
356 aims::Writer<carto::VolumeRef<T> > volumeWriter(outputfile, options);
357 return volumeWriter.write(recons_volume,
false, wf);
364 std::vector<Component> &cpnt,
365 carto::VolumeRef<T> &data,
366 std::string outputdir,
367 std::string outputname,
373 Directory dir = Directory(outputdir);
376 std::string dirname = dir.dirname();
377 std::string extension = FileUtil::extension(outputname);
378 std::string wf = (format.empty() && extension.empty() ?
"GIS" : format);
380 Object options = Object::value(Dictionary());
381 options->setProperty(
"exact_format",
true);
391 throw dimension_x_error();
402 throw dimension_y_error();
405 carto::VolumeRef<T> slice(dx, dy);
406 std::vector<float> vs(4, 1.);
411 slice.header().setProperty(
"voxel_size", vs);
413 std::cout <<
"Writing volume slices ..." << std::endl << std::endl;
415 for (l=0; l<int32_t(cpnt.size()); ++l)
420 Point2d shift, size_component;
422 size_component[0] = cpnt[l].bounding_hz + 2 *
BORDER_LOCAL;
423 size_component[1] = cpnt[l].bounding_vt + 2 *
BORDER_LOCAL;
425 shift[0] = (dx - size_component[0]) / 2;
426 shift[1] = (dy - size_component[1]) / 2;
428 for (y = 0; y < size_component[1] ; ++y)
429 for (x = 0; x < size_component[0] ; ++x)
432 && ((x + cpnt[l].abscissa_x -
BORDER_LOCAL) < data.getSizeX())
434 && ((y + cpnt[l].ordinate_y -
BORDER_LOCAL) < data.getSizeY()))
437 y + shift[1]) = data(x + cpnt[l].abscissa_x
439 y + cpnt[l].ordinate_y
444 std::stringstream ss;
445 ss << outputdir << FileUtil::separator()
446 << FileUtil::removeExtension(FileUtil::basename(outputname));
447 ss <<
"_" << setfill(
'0') << setw(4) << slicemin + cpnt[l].label_f - 1;
449 if (! extension.empty())
450 ss <<
"." << extension;
455 aims::Writer<carto::VolumeRef<T> > sliceWriter(ss.str(), options);
456 if (! sliceWriter.write(slice,
false, &wf))
carto::Object boundingBoxes(const carto::VolumeRef< int16_t > &vol, const std::vector< Component > &components)
std::vector< Component > analyze(carto::VolumeRef< int16_t > &vol, const int32_t slices_number=6, const int32_t scan_resolution=0, const int32_t threshold_lowerbound=0, const int32_t threshold_upperbound=0)
std::vector< int32_t > dimensionsizes
std::vector< int32_t > dimensionorders
std::vector< Component > sortComponent(std::vector< Component > &cpnt, std::vector< int32_t > dimensionsizes)
std::vector< Component > changeComponentsIndex(std::vector< Component > &components, std::vector< int32_t > dimensionsizes, std::vector< int32_t > dimensionorders, int32_t offset=1, int32_t step=1)
void writeComponents(std::vector< Component > &comp)
int32_t extractMaxima(std::vector< int32_t > vctr)
T background(std::vector< Component > &cpnt, carto::VolumeRef< T > &vol)
std::vector< int32_t > extractVectorFromComponent(std::vector< Component > cpnt, ContinuityParameterTested param)
void rescale(carto::VolumeRef< T > &in, RescalerInfo &info)
bool detectSlices(aims::Process &p, const std::string &, aims::Finder &)
bool writeNumberedSlices(int32_t dx, int32_t dy, int32_t res, float z, T background, std::vector< Component > &cpnt, carto::VolumeRef< T > &data, std::string outputdir, std::string outputname, std::string format, uint8_t slicemin)
bool writeStackedSlices(int32_t dx, int32_t dy, int32_t res, float z, T background, std::vector< Component > &cpnt, carto::VolumeRef< T > &data, std::string outputfile, std::string format)
bool individStackSlices(aims::Process &p, const std::string &, aims::Finder &)