diff --git a/SliceModel.h b/SliceModel.h index 73ca76286..9698c2e8a 100644 --- a/SliceModel.h +++ b/SliceModel.h @@ -1,7 +1,7 @@ #ifndef SliceModelH #define SliceModelH #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "libs/gzip_interface.hpp" // --------------------------------------------------------------------------- @@ -11,12 +11,12 @@ class SliceModel { std::shared_ptr handle; int view_id; bool is_diffusion_space = true; - image::matrix<4,4,float> T,invT; // T: image->diffusion iT: diffusion->image - image::geometry<3>geometry; - image::vector<3,float>voxel_size; + tipl::matrix<4,4,float> T,invT; // T: image->diffusion iT: diffusion->image + tipl::geometry<3>geometry; + tipl::vector<3,float>voxel_size; public: // for directx - image::vector<3,int> slice_pos; + tipl::vector<3,int> slice_pos; bool slice_visible[3]; public: SliceModel(std::shared_ptr new_handle,int view_id_); @@ -28,11 +28,11 @@ class SliceModel { std::pair get_contrast_color(void) const; void set_contrast_range(float min_v,float max_v); void set_contrast_color(unsigned int min_c,unsigned int max_c); - void get_slice(image::color_image& image, - unsigned char,const image::value_to_color& v2c, + void get_slice(tipl::color_image& image, + unsigned char,const tipl::value_to_color& v2c, const SliceModel* overlay, - const image::value_to_color& overlay_v2c) const; - image::const_pointer_image get_source(void) const; + const tipl::value_to_color& overlay_v2c) const; + tipl::const_pointer_image get_source(void) const; public: template @@ -41,8 +41,8 @@ class SliceModel { { if(!is_diffusion_space) { - image::vector<3,float> v; - image::slice2space(cur_dim, x, y, slice_pos[cur_dim], v[0],v[1],v[2]); + tipl::vector<3,float> v; + tipl::slice2space(cur_dim, x, y, slice_pos[cur_dim], v[0],v[1],v[2]); v.to(T); v.round(); px = v[0]; @@ -50,13 +50,13 @@ class SliceModel { pz = v[2]; } else - image::slice2space(cur_dim, x, y, slice_pos[cur_dim], px, py, pz); + tipl::slice2space(cur_dim, x, y, slice_pos[cur_dim], px, py, pz); } void toOtherSlice(const SliceModel* other_slice, unsigned char cur_dim,float x,float y, - image::vector<3,float>& v) const + tipl::vector<3,float>& v) const { - image::slice2space(cur_dim, x, y, slice_pos[cur_dim], v[0],v[1],v[2]); + tipl::slice2space(cur_dim, x, y, slice_pos[cur_dim], v[0],v[1],v[2]); if(!is_diffusion_space) v.to(T); if(!other_slice->is_diffusion_space) @@ -66,16 +66,16 @@ class SliceModel { bool to3DSpace(unsigned char cur_dim,value_type x, value_type y, value_type& px, value_type& py, value_type& pz) const { - image::slice2space(cur_dim, x, y, slice_pos[cur_dim], px, py, pz); + tipl::slice2space(cur_dim, x, y, slice_pos[cur_dim], px, py, pz); return geometry.is_valid(px, py, pz); } public: - void get_texture(unsigned char dim,image::color_image& cur_rendering_image, - const image::value_to_color& v2c, + void get_texture(unsigned char dim,tipl::color_image& cur_rendering_image, + const tipl::value_to_color& v2c, const SliceModel* overlay, - const image::value_to_color& overlay_v2c) + const tipl::value_to_color& overlay_v2c) { get_slice(cur_rendering_image,dim,v2c,overlay,overlay_v2c); for(unsigned int index = 0;index < cur_rendering_image.size();++index) @@ -116,24 +116,24 @@ class SliceModel { } return has_updated; } - void get_slice_positions(unsigned int dim,std::vector >& points) + void get_slice_positions(unsigned int dim,std::vector >& points) { points.resize(4); - image::get_slice_positions(dim, slice_pos[dim], geometry,points); + tipl::get_slice_positions(dim, slice_pos[dim], geometry,points); if(!is_diffusion_space) for(unsigned int index = 0;index < points.size();++index) points[index].to(T); } - void get_mosaic(image::color_image& image, + void get_mosaic(tipl::color_image& image, unsigned int mosaic_size, - const image::value_to_color& v2c, + const tipl::value_to_color& v2c, unsigned int skip, const SliceModel* overlay, - const image::value_to_color& overlay_v2c); - void apply_overlay(image::color_image& show_image, + const tipl::value_to_color& overlay_v2c); + void apply_overlay(tipl::color_image& show_image, unsigned char dim, const SliceModel* other_slice, - const image::value_to_color& overlay_v2c) const; + const tipl::value_to_color& overlay_v2c) const; }; class CustomSliceModel : public SliceModel { @@ -142,9 +142,9 @@ class CustomSliceModel : public SliceModel { public: std::auto_ptr > thread; - image::const_pointer_image from; - image::vector<3> from_vs; - image::affine_transform arg_min; + tipl::const_pointer_image from; + tipl::vector<3> from_vs; + tipl::affine_transform arg_min; bool terminated; bool ended; CustomSliceModel(std::shared_ptr new_handle); @@ -154,11 +154,11 @@ class CustomSliceModel : public SliceModel { } void terminate(void); - void argmin(image::reg::reg_type reg_type); + void argmin(tipl::reg::reg_type reg_type); void update(void); public: - image::basic_image source_images; + tipl::image source_images; public: bool initialize(const std::vector& files,bool correct_intensity); diff --git a/cmd/ana.cpp b/cmd/ana.cpp index 2ab06e6d9..82997fd58 100644 --- a/cmd/ana.cpp +++ b/cmd/ana.cpp @@ -4,7 +4,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "tracking/region/Regions.h" #include "libs/tracking/tract_model.hpp" #include "libs/tracking/tracking_thread.hpp" @@ -126,19 +126,19 @@ void export_track_info(const std::string& file_name, { file_name_stat += ".bmp"; std::cout << "export subvoxel TDI to " << file_name_stat << std::endl; - image::basic_image tdi; - image::matrix<4,4,float> tr; + tipl::image tdi; + tipl::matrix<4,4,float> tr; tr.identity(); if(cmd == "tdi_color") tdi.resize(handle->dim); else { - tdi.resize(image::geometry<3>(handle->dim[0]*4,handle->dim[1]*4,handle->dim[2]*4)); + tdi.resize(tipl::geometry<3>(handle->dim[0]*4,handle->dim[1]*4,handle->dim[2]*4)); tr[0] = tr[5] = tr[10] = 4.0f; } tract_model.get_density_map(tdi,tr,false); - image::basic_image mosaic; - image::mosaic(tdi,mosaic,std::sqrt(tdi.depth())); + tipl::image mosaic; + tipl::mosaic(tdi,mosaic,std::sqrt(tdi.depth())); QImage qimage((unsigned char*)&*mosaic.begin(), mosaic.width(),mosaic.height(),QImage::Format_RGB32); qimage.save(file_name_stat.c_str()); diff --git a/cmd/atl.cpp b/cmd/atl.cpp index 9975cb41a..234a98cbf 100644 --- a/cmd/atl.cpp +++ b/cmd/atl.cpp @@ -2,7 +2,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "mapping/fa_template.hpp" #include "libs/gzip_interface.hpp" #include "mapping/atlas.hpp" @@ -64,10 +64,10 @@ bool atl_load_atlas(std::string atlas_name) return true; } -void atl_save_mapping(const std::string& file_name,const image::geometry<3>& geo, - const image::basic_image,3>& mapping, +void atl_save_mapping(const std::string& file_name,const tipl::geometry<3>& geo, + const tipl::image,3>& mapping, const std::vector& trans, - const image::vector<3>& vs, + const tipl::vector<3>& vs, bool multiple) { for(unsigned int i = 0;i < atlas_list.size();++i) @@ -82,17 +82,17 @@ void atl_save_mapping(const std::string& file_name,const image::geometry<3>& geo output += atlas_list[i].get_list()[j]; output += ".nii.gz"; - image::basic_image roi(geo); + tipl::image roi(geo); for(unsigned int k = 0;k < mapping.size();++k) if (atlas_list[i].is_labeled_as(mapping[k], j)) roi[k] = 1; if(multiple) { - image::io::nifti out; + tipl::io::nifti out; out.set_voxel_size(vs); if(!trans.empty()) out.set_LPS_transformation(trans.begin(),roi.geometry()); - image::flip_xy(roi); + tipl::flip_xy(roi); out << roi; out.save_to_file(output.c_str()); std::cout << "save " << output << std::endl; diff --git a/cmd/cnn.cpp b/cmd/cnn.cpp index 2432a16b3..fb95418fb 100644 --- a/cmd/cnn.cpp +++ b/cmd/cnn.cpp @@ -1,13 +1,13 @@ #include #include #include "program_option.hpp" -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "gzip_interface.hpp" int cnn(void) { std::string train_file_name = po.get("train"); - image::ml::network_data nn_data,nn_test; + tipl::ml::network_data nn_data,nn_test; if(!nn_data.load_from_file(train_file_name.c_str())) { std::cout << "Cannot load training data at " << train_file_name << std::endl; @@ -23,7 +23,7 @@ int cnn(void) } } std::string network = po.get("network"); - image::ml::network nn; + tipl::ml::network nn; if(!(nn << network)) { diff --git a/cmd/exp.cpp b/cmd/exp.cpp index ce482bf06..c19bca9cd 100644 --- a/cmd/exp.cpp +++ b/cmd/exp.cpp @@ -2,7 +2,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "tracking/region/Regions.h" #include "libs/tracking/tract_model.hpp" #include "libs/dsi/image_model.hpp" @@ -66,7 +66,7 @@ int exp(void) if(mat_reader.read("trans",row,col,trans)) std::cout << "Transformation matrix found." << std::endl; - image::geometry<3> geo(dim_buf[0],dim_buf[1],dim_buf[2]); + tipl::geometry<3> geo(dim_buf[0],dim_buf[1],dim_buf[2]); std::string export_option = po.get("export"); std::replace(export_option.begin(),export_option.end(),',',' '); std::istringstream in(export_option); @@ -88,10 +88,10 @@ int exp(void) continue; } - image::basic_image fibers; + tipl::image fibers; if(cmd[3] == 's') // all directions { - fibers.resize(image::geometry<4>(geo[0],geo[1],geo[2],dir.num_fiber*3)); + fibers.resize(tipl::geometry<4>(geo[0],geo[1],geo[2],dir.num_fiber*3)); for(unsigned int i = 0,ptr = 0;i < dir.num_fiber;++i) for(unsigned int j = 0;j < 3;++j) for(unsigned int index = 0;index < geo.size();++index,++ptr) @@ -106,7 +106,7 @@ int exp(void) std::cout << "Invalid fiber index. The maximum fiber per voxel is " << (int) dir.num_fiber << std::endl; continue; } - fibers.resize(image::geometry<4>(geo[0],geo[1],geo[2],3)); + fibers.resize(tipl::geometry<4>(geo[0],geo[1],geo[2],3)); for(unsigned int j = 0,ptr = 0;j < 3;++j) for(unsigned int index = 0;index < geo.size();++index,++ptr) if(dir.get_fa(index,dir_index)) @@ -115,7 +115,7 @@ int exp(void) gz_nifti nifti_header; if(trans) //QSDR condition nifti_header.set_LPS_transformation(trans,fibers.geometry()); - image::flip_xy(fibers); + tipl::flip_xy(fibers); nifti_header << fibers; nifti_header.set_voxel_size(vs); nifti_header.save_to_file(file_name_stat.c_str()); @@ -133,13 +133,13 @@ int exp(void) std::cout << "expected dimension: " << geo[0] << " by " << geo[1] << " by " << geo[2] << std::endl; continue; } - image::basic_image data(geo); + tipl::image data(geo); std::copy(volume,volume+geo.size(),data.begin()); gz_nifti nifti_header; if(trans) //QSDR condition nifti_header.set_LPS_transformation(trans,data.geometry()); - image::flip_xy(data); + tipl::flip_xy(data); nifti_header << data; nifti_header.set_voxel_size(vs); nifti_header.save_to_file(file_name_stat.c_str()); diff --git a/cmd/qc.cpp b/cmd/qc.cpp index 03f890b95..e645e7bd8 100644 --- a/cmd/qc.cpp +++ b/cmd/qc.cpp @@ -26,7 +26,7 @@ std::string quality_check_src_files(QString dir) } unique_prog(false); // output image dimension - out << image::vector<3,int>(handle.voxel.dim.begin()) << "\t"; + out << tipl::vector<3,int>(handle.voxel.dim.begin()) << "\t"; // output image resolution out << handle.voxel.vs << "\t"; // output DWI count diff --git a/cmd/rec.cpp b/cmd/rec.cpp index 0ca7cd1ac..04c40f867 100644 --- a/cmd/rec.cpp +++ b/cmd/rec.cpp @@ -3,7 +3,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "libs/dsi/image_model.hpp" #include "dsi_interface_static_link.h" #include "mapping/fa_template.hpp" @@ -54,7 +54,7 @@ int rec(void) std::cout << "Invalid transfformation matrix." < affine; + tipl::transformation_matrix affine; affine.load_from_transform(T.begin()); std::cout << "rotating images" << std::endl; handle->rotate(handle->voxel.dim,affine); @@ -222,7 +222,7 @@ int rec(void) gz_nifti header; if(header.load_from_file(mask_file.c_str())) { - image::basic_image external_mask; + tipl::image external_mask; header.toLPS(external_mask); if(external_mask.geometry() != handle->voxel.dim) std::cout << "In consistent the mask dimension...using default mask" << std::endl; diff --git a/cmd/src.cpp b/cmd/src.cpp index 0e3ccb6fc..26cba134c 100644 --- a/cmd/src.cpp +++ b/cmd/src.cpp @@ -2,7 +2,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "dicom/dwi_header.hpp" #include "program_option.hpp" diff --git a/cmd/trk.cpp b/cmd/trk.cpp index c074b5a5a..bd69183b5 100644 --- a/cmd/trk.cpp +++ b/cmd/trk.cpp @@ -4,7 +4,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "tracking/region/Regions.h" #include "libs/tracking/tract_model.hpp" #include "libs/tracking/tracking_thread.hpp" @@ -66,7 +66,7 @@ void save_connectivity_matrix(TractModel& tract_model, out << report; } void get_roi_label(QString file_name,std::map& label_map, - std::map& label_color,bool mute_cmd); + std::map& label_color,bool mute_cmd); void get_connectivity_matrix(std::shared_ptr handle, TractModel& tract_model) { @@ -103,7 +103,7 @@ void get_connectivity_matrix(std::shared_ptr handle, std::cout << "Failed to open file as a region:" << fn << std::endl; return; } - data.regions.push_back(std::vector >()); + data.regions.push_back(std::vector >()); region.get_region_voxels(data.regions.back()); data.region_name.push_back(QFileInfo(line.c_str()).baseName().toStdString()); } @@ -112,7 +112,7 @@ void get_connectivity_matrix(std::shared_ptr handle, else { gz_nifti header; - image::basic_image from; + tipl::image from; // if an ROI file is assigned, load it if (header.load_from_file(roi_file_name)) header.toLPS(from); @@ -140,7 +140,7 @@ void get_connectivity_matrix(std::shared_ptr handle, std::cout << roi_file_name << " is used as a native space ROI." << std::endl; std::vector value_map(std::numeric_limits::max()); unsigned int max_value = 0; - for (image::pixel_index<3>index(from.geometry()); index < from.size();++index) + for (tipl::pixel_index<3>index(from.geometry()); index < from.size();++index) { value_map[(unsigned short)from[index.index()]] = 1; max_value = std::max(from[index.index()],max_value); @@ -156,18 +156,18 @@ void get_connectivity_matrix(std::shared_ptr handle, // get label file std::map label_map; - std::map label_color; + std::map label_color; get_roi_label(roi_file_name.c_str(),label_map,label_color,false); for(unsigned int value = 1;value < value_map.size();++value) if(value_map[value]) { - image::basic_image mask(from.geometry()); + tipl::image mask(from.geometry()); for(unsigned int i = 0;i < mask.size();++i) if(from[i] == value) mask[i] = 1; ROIRegion region(handle); region.LoadFromBuffer(mask); - data.regions.push_back(std::vector >()); + data.regions.push_back(std::vector >()); region.get_region_voxels(data.regions.back()); if(label_map.find(value) != label_map.end()) data.region_name.push_back(label_map[value]); @@ -224,30 +224,30 @@ bool load_region(std::shared_ptr handle, std::cout << "Cannot output connectivity: no mni mapping." << std::endl; return false; } - const image::basic_image,3 >& mapping = handle->get_mni_mapping(); + const tipl::image,3 >& mapping = handle->get_mni_mapping(); std::string atlas_name = file_name.substr(0,file_name.find(':')); std::string region_name = file_name.substr(file_name.find(':')+1); std::cout << "Loading " << region_name << " from " << atlas_name << " atlas" << std::endl; if(!atl_load_atlas(atlas_name)) return false; - image::vector<3> null; - std::vector > cur_region; + tipl::vector<3> null; + std::vector > cur_region; for(unsigned int i = 0;i < atlas_list.size();++i) if(atlas_list[i].name == atlas_name) for (unsigned int label_index = 0; label_index < atlas_list[i].get_list().size(); ++label_index) if(atlas_list[i].get_list()[label_index] == region_name) { - for (image::pixel_index<3>index(mapping.geometry());index < mapping.size();++index) + for (tipl::pixel_index<3>index(mapping.geometry());index < mapping.size();++index) if(mapping[index.index()] != null && atlas_list[i].is_labeled_as(mapping[index.index()],label_index)) - cur_region.push_back(image::vector<3,short>(index.begin())); + cur_region.push_back(tipl::vector<3,short>(index.begin())); } roi.add_points(cur_region,false); } else { - image::geometry<3> t1t2_geo; - image::matrix<4,4,float> convert; + tipl::geometry<3> t1t2_geo; + tipl::matrix<4,4,float> convert; if(po.has("t1t2")) { @@ -281,11 +281,11 @@ bool load_region(std::shared_ptr handle, std::cout << "Not a valid nifti file:" << file_name << std::endl; return false; } - image::basic_image from; + tipl::image from; { - image::basic_image tmp; + tipl::image tmp; header.toLPS(tmp); - image::add_constant(tmp,0.5); + tipl::add_constant(tmp,0.5); from = tmp; } if(t1t2_geo != from.geometry()) @@ -431,9 +431,9 @@ int trk(void) } } - image::geometry<3> geometry = handle->dim; + tipl::geometry<3> geometry = handle->dim; const float *fa0 = handle->dir.fa[0]; - float otsu = image::segmentation::otsu_threshold(image::make_image(fa0,geometry)); + float otsu = tipl::segmentation::otsu_threshold(tipl::make_image(fa0,geometry)); ThreadData tracking_thread; @@ -526,12 +526,12 @@ int trk(void) float seed_threshold = tracking_thread.param.threshold; if(seed_threshold == 0) seed_threshold = otsu*tracking_thread.param.default_otsu; - std::vector > seed; + std::vector > seed; std::cout << "no seeding area assigned. use whole brain seeding" << std::endl; - for(image::pixel_index<3> index(geometry);index < geometry.size();++index) + for(tipl::pixel_index<3> index(geometry);index < geometry.size();++index) if(fa0[index.index()] > seed_threshold) - seed.push_back(image::vector<3,short>(index.x(),index.y(),index.z())); - tracking_thread.roi_mgr.setRegions(geometry,seed,1.0,3,"whole brain",image::vector<3>()); + seed.push_back(tipl::vector<3,short>(index.x(),index.y(),index.z())); + tracking_thread.roi_mgr.setRegions(geometry,seed,1.0,3,"whole brain",tipl::vector<3>()); } if(!cnt_file_name.empty()) diff --git a/connectometry/db_window.cpp b/connectometry/db_window.cpp index 12e512342..1fc473f5c 100644 --- a/connectometry/db_window.cpp +++ b/connectometry/db_window.cpp @@ -103,7 +103,7 @@ bool db_window::eventFilter(QObject *obj, QEvent *event) return false; QMouseEvent *mouseEvent = static_cast(event); QPointF point = ui->vbc_view->mapToScene(mouseEvent->pos().x(),mouseEvent->pos().y()); - image::vector<3,float> pos; + tipl::vector<3,float> pos; pos[0] = ((float)point.x()) / ui->zoom->value() - 0.5; pos[1] = ((float)point.y()) / ui->zoom->value() - 0.5; pos[2] = ui->slice_pos->value(); @@ -141,12 +141,12 @@ void db_window::on_subject_list_itemSelectionChanged() if(ui->view_z->isChecked()) ui->z_pos->setValue(ui->slice_pos->value()); - image::basic_image slice; + tipl::image slice; vbc->handle->db.get_subject_slice(ui->subject_list->currentRow(), ui->view_x->isChecked() ? 0:(ui->view_y->isChecked() ? 1:2), ui->slice_pos->value(),slice); - image::normalize(slice); - image::color_image color_slice(slice.geometry()); + tipl::normalize(slice); + tipl::color_image color_slice(slice.geometry()); std::copy(slice.begin(),slice.end(),color_slice.begin()); if(ui->show_mask->isChecked()) { @@ -165,19 +165,19 @@ void db_window::on_subject_list_itemSelectionChanged() //if(ui->subject_view->currentIndex() == 1) { std::vector fp; - float threshold = ui->fp_coverage->value()*image::segmentation::otsu_threshold(image::make_image(vbc->handle->dir.fa[0],vbc->handle->dim)); + float threshold = ui->fp_coverage->value()*tipl::segmentation::otsu_threshold(tipl::make_image(vbc->handle->dir.fa[0],vbc->handle->dim)); vbc->handle->db.get_subject_vector(ui->subject_list->currentRow(),fp,fp_mask,threshold,ui->normalize_fp->isChecked()); fp_image_buf.clear(); - fp_image_buf.resize(image::geometry<2>(ui->fp_zoom->value()*25,ui->fp_zoom->value()*100));// rotated + fp_image_buf.resize(tipl::geometry<2>(ui->fp_zoom->value()*25,ui->fp_zoom->value()*100));// rotated - image::minus_constant(fp.begin(),fp.end(),*std::min_element(fp.begin(),fp.end())); + tipl::minus_constant(fp.begin(),fp.end(),*std::min_element(fp.begin(),fp.end())); float max_fp = *std::max_element(fp.begin(),fp.end()); if(max_fp == 0) return; - image::multiply_constant(fp,(float)fp_image_buf.width()/max_fp); + tipl::multiply_constant(fp,(float)fp_image_buf.width()/max_fp); std::vector ifp(fp.size()); std::copy(fp.begin(),fp.end(),ifp.begin()); - image::upper_lower_threshold(ifp,0,(int)fp_image_buf.width()-1); + tipl::upper_lower_threshold(ifp,0,(int)fp_image_buf.width()-1); unsigned int* base = (unsigned int*)&fp_image_buf[0]; for(unsigned int i = 0;i < fp_image_buf.height();++i,base += fp_image_buf.width()) { @@ -190,16 +190,16 @@ void db_window::on_subject_list_itemSelectionChanged() unsigned int to = ifp[from_index]; if(from > to) std::swap(from,to); - image::add_constant(base+from,base+to,1); + tipl::add_constant(base+from,base+to,1); } } base = (unsigned int*)&fp_image_buf[0]; unsigned int max_value = *std::max_element(base,base+fp_image_buf.size()); if(max_value) for(unsigned int index = 0;index < fp_image_buf.size();++index) - fp_image_buf[index] = image::rgb_color((unsigned char)(255-std::min(255,(fp_image_buf[index].color*512/max_value)))); - image::swap_xy(fp_image_buf); - image::flip_y(fp_image_buf); + fp_image_buf[index] = tipl::rgb((unsigned char)(255-std::min(255,(fp_image_buf[index].color*512/max_value)))); + tipl::swap_xy(fp_image_buf); + tipl::flip_y(fp_image_buf); QImage fp_image_tmp((unsigned char*)&*fp_image_buf.begin(),fp_image_buf.width(),fp_image_buf.height(),QImage::Format_RGB32); fp_image = fp_image_tmp; show_view(fp_scene,fp_image); @@ -207,7 +207,7 @@ void db_window::on_subject_list_itemSelectionChanged() if(!fp_dif_map.empty() && fp_dif_map.width() == vbc->handle->db.num_subjects) { - fp_dif_map.resize(image::geometry<2>(vbc->handle->db.num_subjects,vbc->handle->db.num_subjects)); + fp_dif_map.resize(tipl::geometry<2>(vbc->handle->db.num_subjects,vbc->handle->db.num_subjects)); for(unsigned int index = 0;index < fp_matrix.size();++index) fp_dif_map[index] = color_map[fp_matrix[index]*256.0/fp_max_value]; @@ -264,8 +264,8 @@ void db_window::on_actionSave_fingerprints_triggered() if(filename.isEmpty()) return; - float threshold = ui->fp_coverage->value()*image::segmentation::otsu_threshold( - image::make_image(vbc->handle->dir.fa[0],vbc->handle->dim)); + float threshold = ui->fp_coverage->value()*tipl::segmentation::otsu_threshold( + tipl::make_image(vbc->handle->dir.fa[0],vbc->handle->dim)); vbc->handle->db.save_subject_vector(filename.toLocal8Bit().begin(),fp_mask,threshold,ui->normalize_fp->isChecked()); } @@ -283,7 +283,7 @@ void db_window::on_actionSave_pair_wise_difference_as_triggered() on_calculate_dif_clicked(); if(QFileInfo(filename).suffix().toLower() == "mat") { - image::io::mat_write out(filename.toStdString().c_str()); + tipl::io::mat_write out(filename.toStdString().c_str()); if(!out) return; out.write("dif",(const float*)&*fp_matrix.begin(),vbc->handle->db.num_subjects,vbc->handle->db.num_subjects); @@ -318,7 +318,7 @@ void db_window::on_actionLoad_mask_triggered() "Report file (*.txt *.nii *nii.gz);;All files (*)"); if(file.isEmpty()) return; - image::basic_image I; + tipl::image I; gz_nifti nii; if(!nii.load_from_file(file.toLocal8Bit().begin())) { @@ -348,16 +348,16 @@ void db_window::on_actionSave_mask_triggered() "Report file (*.txt *.nii *nii.gz);;All files (*)"); if(FileName.isEmpty()) return; - float fiber_threshold = ui->fp_coverage->value()*image::segmentation::otsu_threshold( - image::make_image(vbc->handle->dir.fa[0],vbc->handle->dim)); - image::basic_image mask(fp_mask); + float fiber_threshold = ui->fp_coverage->value()*tipl::segmentation::otsu_threshold( + tipl::make_image(vbc->handle->dir.fa[0],vbc->handle->dim)); + tipl::image mask(fp_mask); for(unsigned int index = 0;index < mask.size();++index) if(vbc->handle->dir.fa[0][index] < fiber_threshold) mask[index] = 0; gz_nifti file; file.set_voxel_size(vbc->handle->vs); file.set_LPS_transformation(vbc->handle->trans_to_mni.begin(),mask.geometry()); - image::flip_xy(mask); + tipl::flip_xy(mask); file << mask; file.save_to_file(FileName.toLocal8Bit().begin()); } @@ -373,11 +373,11 @@ void db_window::update_db(void) void db_window::on_calculate_dif_clicked() { - float threshold = ui->fp_coverage->value()*image::segmentation::otsu_threshold( - image::make_image(vbc->handle->dir.fa[0],vbc->handle->dim)); + float threshold = ui->fp_coverage->value()*tipl::segmentation::otsu_threshold( + tipl::make_image(vbc->handle->dir.fa[0],vbc->handle->dim)); vbc->handle->db.get_dif_matrix(fp_matrix,fp_mask,threshold,ui->normalize_fp->isChecked()); fp_max_value = *std::max_element(fp_matrix.begin(),fp_matrix.end()); - fp_dif_map.resize(image::geometry<2>(vbc->handle->db.num_subjects,vbc->handle->db.num_subjects)); + fp_dif_map.resize(tipl::geometry<2>(vbc->handle->db.num_subjects,vbc->handle->db.num_subjects)); for(unsigned int index = 0;index < fp_matrix.size();++index) fp_dif_map[index] = color_map[fp_matrix[index]*255.0/fp_max_value]; on_fp_zoom_valueChanged(ui->fp_zoom->value()); @@ -413,8 +413,8 @@ void db_window::on_delete_subject_clicked() void db_window::on_actionCalculate_change_triggered() { - float threshold = ui->fp_coverage->value()*image::segmentation::otsu_threshold( - image::make_image(vbc->handle->dir.fa[0],vbc->handle->dim)); + float threshold = ui->fp_coverage->value()*tipl::segmentation::otsu_threshold( + tipl::make_image(vbc->handle->dir.fa[0],vbc->handle->dim)); vbc->handle->db.auto_match(fp_mask,threshold,ui->normalize_fp->isChecked()); std::unique_ptr mdb(new match_db(this,vbc)); diff --git a/connectometry/db_window.h b/connectometry/db_window.h index 4b3a76eb4..7c99a8b51 100644 --- a/connectometry/db_window.h +++ b/connectometry/db_window.h @@ -14,14 +14,14 @@ class db_window : public QMainWindow std::shared_ptr vbc; private: QGraphicsScene fp_dif_scene, fp_scene; - image::color_image fp_dif_map; + tipl::color_image fp_dif_map; QImage fp_dif_image,fp_image; - image::color_image fp_image_buf; - image::color_map_rgb color_map; - image::color_bar color_bar; + tipl::color_image fp_image_buf; + tipl::color_map_rgb color_map; + tipl::color_bar color_bar; std::vector fp_matrix; float fp_max_value; - image::basic_image fp_mask; + tipl::image fp_mask; private: QGraphicsScene vbc_scene; QImage vbc_slice_image; diff --git a/connectometry/group_connectometry.cpp b/connectometry/group_connectometry.cpp index ab2b9249a..9dd440fea 100644 --- a/connectometry/group_connectometry.cpp +++ b/connectometry/group_connectometry.cpp @@ -925,13 +925,13 @@ void group_connectometry::on_show_result_clicked() new_data->view_item.push_back(item()); new_data->view_item.back().name = threshold_type[cur_model.threshold_type]; new_data->view_item.back().name += "-"; - new_data->view_item.back().image_data = image::make_image(result_fib->lesser_ptr[0],new_data->dim); + new_data->view_item.back().image_data = tipl::make_image(result_fib->lesser_ptr[0],new_data->dim); new_data->view_item.back().set_scale(result_fib->lesser_ptr[0], result_fib->lesser_ptr[0]+new_data->dim.size()); new_data->view_item.push_back(item()); new_data->view_item.back().name = threshold_type[cur_model.threshold_type]; new_data->view_item.back().name += "+"; - new_data->view_item.back().image_data = image::make_image(result_fib->greater_ptr[0],new_data->dim); + new_data->view_item.back().image_data = tipl::make_image(result_fib->greater_ptr[0],new_data->dim); new_data->view_item.back().set_scale(result_fib->greater_ptr[0], result_fib->greater_ptr[0]+new_data->dim.size()); @@ -982,7 +982,7 @@ void group_connectometry::on_missing_data_checked_toggled(bool checked) } void group_connectometry::add_new_roi(QString name,QString source, - const std::vector >& new_roi, + const std::vector >& new_roi, float r) { ui->roi_table->setRowCount(ui->roi_table->rowCount()+1); @@ -1001,7 +1001,7 @@ void group_connectometry::on_load_roi_from_atlas_clicked() { for(unsigned int i = 0;i < atlas_dialog->roi_list.size();++i) { - std::vector > new_roi; + std::vector > new_roi; float r; vbc->handle->get_atlas_roi(atlas_dialog->atlas_index,atlas_dialog->roi_list[i],new_roi,r); if(!new_roi.empty()) @@ -1026,8 +1026,8 @@ void group_connectometry::on_load_roi_from_file_clicked() "Report file (*.txt *.nii *nii.gz);;All files (*)"); if(file.isEmpty()) return; - image::basic_image I; - image::matrix<4,4,float> transform; + tipl::image I; + tipl::matrix<4,4,float> transform; gz_nifti nii; if(!nii.load_from_file(file.toLocal8Bit().begin())) { @@ -1038,16 +1038,16 @@ void group_connectometry::on_load_roi_from_file_clicked() transform.identity(); nii.get_image_transformation(transform.begin()); transform.inv(); - std::vector > new_roi; - for (image::pixel_index<3> index(vbc->handle->dim);index < vbc->handle->dim.size();++index) + std::vector > new_roi; + for (tipl::pixel_index<3> index(vbc->handle->dim);index < vbc->handle->dim.size();++index) { - image::vector<3> pos; + tipl::vector<3> pos; vbc->handle->subject2mni(index,pos); pos.to(transform); pos.round(); if(!I.geometry().is_valid(pos) || I.at(pos[0],pos[1],pos[2]) == 0) continue; - new_roi.push_back(image::vector<3,short>((const unsigned int*)index.begin())); + new_roi.push_back(tipl::vector<3,short>((const unsigned int*)index.begin())); } if(new_roi.empty()) { diff --git a/connectometry/group_connectometry.hpp b/connectometry/group_connectometry.hpp index 47a1adccd..a5ed2b78f 100644 --- a/connectometry/group_connectometry.hpp +++ b/connectometry/group_connectometry.hpp @@ -4,7 +4,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "vbc/vbc_database.h" #include "atlas.hpp" namespace Ui { @@ -40,13 +40,13 @@ class group_connectometry : public QDialog private: std::auto_ptr result_fib; void show_dis_table(void); - void add_new_roi(QString name,QString source,const std::vector >& new_roi,float r); + void add_new_roi(QString name,QString source,const std::vector >& new_roi,float r); public: bool gui = true; QString work_dir; std::vector file_names; public: - std::vector > > roi_list; + std::vector > > roi_list; std::vector roi_r_list; public: diff --git a/dicom/dicom_parser.cpp b/dicom/dicom_parser.cpp index b8c4fedc3..e318f25b5 100644 --- a/dicom/dicom_parser.cpp +++ b/dicom/dicom_parser.cpp @@ -4,7 +4,7 @@ #include #include "dicom_parser.h" #include "ui_dicom_parser.h" -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "mainwindow.h" #include "prog_interface_static_link.h" #include "libs/gzip_interface.hpp" @@ -12,13 +12,13 @@ -void get_report_from_dicom(const image::io::dicom& header,std::string& report_); -void get_report_from_bruker(const image::io::bruker_info& header,std::string& report_); -void get_report_from_bruker2(const image::io::bruker_info& header,std::string& report_); +void get_report_from_dicom(const tipl::io::dicom& header,std::string& report_); +void get_report_from_bruker(const tipl::io::bruker_info& header,std::string& report_); +void get_report_from_bruker2(const tipl::io::bruker_info& header,std::string& report_); QString get_src_name(QString file_name) { - image::io::dicom header; + tipl::io::dicom header; if (header.load_from_file(file_name.toLocal8Bit().begin())) { std::string Person; @@ -43,7 +43,7 @@ dicom_parser::dicom_parser(QStringList file_list,QWidget *parent) : if (!dwi_files.empty()) { ui->SrcName->setText(get_src_name(file_list[0])); - image::io::dicom header; + tipl::io::dicom header; if (header.load_from_file(file_list[0].toLocal8Bit().begin())) { slice_orientation.resize(9); @@ -63,10 +63,10 @@ dicom_parser::~dicom_parser() bool load_dicom_multi_frame(const char* file_name,std::vector >& dwi_files) { - image::io::dicom dicom_header;// multiple frame image + tipl::io::dicom dicom_header;// multiple frame image if(!dicom_header.load_from_file(file_name)) return false; - image::basic_image buf_image; + tipl::image buf_image; dicom_header >> buf_image; unsigned int slice_num = dicom_header.get_int(0x2001,0x1018); std::vector b_table; @@ -87,7 +87,7 @@ bool load_dicom_multi_frame(const char* file_name,std::vector bvec(bx[i],by[i],bz[i]); + tipl::vector<3, float> bvec(bx[i],by[i],bz[i]); b_table.push_back(b[i]*bvec.length()); if(bvec.length() > 0) bvec.normalize(); @@ -107,7 +107,7 @@ bool load_dicom_multi_frame(const char* file_name,std::vector new_file(new DwiHeader); if(index == 0) get_report_from_dicom(dicom_header,new_file->report); - new_file->image.resize(image::geometry<3>(buf_image.width(),buf_image.height(),slice_num)); + new_file->image.resize(tipl::geometry<3>(buf_image.width(),buf_image.height(),slice_num)); for(unsigned int j = 0;j < slice_num;++j) std::copy(buf_image.begin()+(j*num_gradient + index)*plane_size, @@ -155,7 +155,7 @@ bool load_dicom_multi_frame(const char* file_name,std::vectorfile_name += out.str(); dicom_header.get_voxel_size(new_file->voxel_size); new_file->bvalue = b_table[index*4]; - new_file->bvec = image::vector<3, float>(b_table[index*4+1],b_table[index*4+2],b_table[index*4+3]); + new_file->bvec = tipl::vector<3, float>(b_table[index*4+1],b_table[index*4+2],b_table[index*4+3]); dwi_files.push_back(new_file); } return true; @@ -178,7 +178,7 @@ void load_bvec(const char* file_name,std::vector& b_table) ++total_line; } if(total_line == 3) - image::mat::transpose(b_table.begin(),image::dyndim(3,b_table.size()/3)); + tipl::mat::transpose(b_table.begin(),tipl::dyndim(3,b_table.size()/3)); } void load_bval(const char* file_name,std::vector& bval) { @@ -251,8 +251,8 @@ bool load_4d_nii(const char* file_name,std::vector >& bvecs.clear(); } } - image::basic_image grad_dev; - image::basic_image mask; + tipl::image grad_dev; + tipl::image mask; if(QFileInfo(QFileInfo(file_name).absolutePath() + "/grad_dev.nii.gz").exists()) { gz_nifti grad_header; @@ -277,7 +277,7 @@ bool load_4d_nii(const char* file_name,std::vector >& for(unsigned int index = 0;index < analyze_header.dim(4);++index) { std::auto_ptr new_file(new DwiHeader); - image::basic_image data; + tipl::image data; if(!analyze_header.toLPS(data,index == 0)) break; max_value = std::max(max_value,*std::max_element(data.begin(),data.end())); @@ -289,10 +289,10 @@ bool load_4d_nii(const char* file_name,std::vector >& for(unsigned int index = 0;index < analyze_header.dim(4);++index) { std::shared_ptr new_file(new DwiHeader); - image::basic_image data; + tipl::image data; if(!analyze_header.toLPS(data,false)) break; - image::lower_threshold(data,0.0); + tipl::lower_threshold(data,0.0); if(analyze_header.nif_header2.datatype == 16 || analyze_header.nif_header2.datatype == 64) // if floating point, scale and convert to interger data *= 32767.0/max_value; @@ -312,7 +312,7 @@ bool load_4d_nii(const char* file_name,std::vector >& if(new_file->bvalue < 10) { new_file->bvalue = 0; - new_file->bvec = image::vector<3>(0,0,0); + new_file->bvec = tipl::vector<3>(0,0,0); } } if(index == 0 && !grad_dev.empty()) @@ -328,19 +328,19 @@ bool load_4d_nii(const char* file_name,std::vector >& bool load_4d_2dseq(const char* file_name,std::vector >& dwi_files) { - image::io::bruker_2dseq bruker_header; + tipl::io::bruker_2dseq bruker_header; if(!bruker_header.load_from_file(file_name)) return false; float vs[3]; std::vector bvalues; - std::vector > bvecs; + std::vector > bvecs; std::string report; bruker_header.get_voxel_size(vs); QString system_path =QFileInfo(QFileInfo(QFileInfo(file_name).absolutePath()).absolutePath()).absolutePath(); if(QFileInfo(system_path+"/method").exists()) { - image::io::bruker_info method_file; + tipl::io::bruker_info method_file; QString method_name = system_path+"/method"; if(!method_file.load_from_file(method_name.toLocal8Bit().begin())) { @@ -371,9 +371,9 @@ bool load_4d_2dseq(const char* file_name,std::vector if(QFileInfo(system_path+"/imnd").exists()) { bvalues.push_back(0); - bvecs.push_back(image::vector<3>()); + bvecs.push_back(tipl::vector<3>()); - image::io::bruker_info imnd_file; + tipl::io::bruker_info imnd_file; QString imnd_name = QFileInfo(QFileInfo(QFileInfo(file_name). absolutePath()).absolutePath()).absolutePath()+"/imnd"; if(!imnd_file.load_from_file(imnd_name.toLocal8Bit().begin())) @@ -393,13 +393,13 @@ bool load_4d_2dseq(const char* file_name,std::vector } - image::geometry<3> dim(bruker_header.get_image().geometry()); + tipl::geometry<3> dim(bruker_header.get_image().geometry()); dim[2] /= bvalues.size(); if(dwi_files.size() && dwi_files.back()->image.geometry() != dim) return false; - image::lower_threshold(bruker_header.get_image(),0.0); - image::normalize(bruker_header.get_image(),32767.0); + tipl::lower_threshold(bruker_header.get_image(),0.0); + tipl::normalize(bruker_header.get_image(),32767.0); for (unsigned int index = 0;index < bvalues.size();++index) { @@ -423,8 +423,8 @@ bool load_4d_2dseq(const char* file_name,std::vector bool load_multiple_slice_dicom(QStringList file_list,std::vector >& dwi_files) { - image::io::dicom dicom_header;// multiple frame image - image::geometry<3> geo; + tipl::io::dicom dicom_header;// multiple frame image + tipl::geometry<3> geo; if(!dicom_header.load_from_file(file_list[0].toLocal8Bit().begin())) return false; dicom_header.get_image_dimension(geo); @@ -432,7 +432,7 @@ bool load_multiple_slice_dicom(QStringList file_list,std::vector >& for(unsigned int i = 0;i < dwi_num;++i) { dwi_files.push_back(std::make_shared()); - dwi_files.back()->image.resize(image::geometry<3>(width,height,depth)); + dwi_files.back()->image.resize(tipl::geometry<3>(width,height,depth)); dwi_files.back()->voxel_size[0] = fov1*10.0/width; dwi_files.back()->voxel_size[1] = fov2*10.0/height; dwi_files.back()->voxel_size[2] = fov3*100.0/depth; @@ -848,7 +848,7 @@ void dicom_parser::on_actionOpen_b_table_triggered() { auto& I = dwi_files[0]->image; unsigned int b_count = b_table.size()/4; - image::geometry<3> dim(I.width(),I.height(),I.depth()/b_count); + tipl::geometry<3> dim(I.width(),I.height(),I.depth()/b_count); std::vector > new_files; unsigned int plane_size = I.plane_size(); for(int i = 0;i < b_count;++i) diff --git a/dicom/dwi_header.cpp b/dicom/dwi_header.cpp index 1232abcc7..d39c93ccc 100644 --- a/dicom/dwi_header.cpp +++ b/dicom/dwi_header.cpp @@ -1,11 +1,11 @@ #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "dwi_header.hpp" #include "gzip_interface.hpp" #include "prog_interface_static_link.h" #include "image_model.hpp" -void get_report_from_dicom(const image::io::dicom& header,std::string& report) +void get_report_from_dicom(const tipl::io::dicom& header,std::string& report) { std::string manu,make,seq; header.get_text(0x0008,0x0070,manu);//Manufacturer @@ -28,7 +28,7 @@ void get_report_from_dicom(const image::io::dicom& header,std::string& report) << " TE=" << te << " ms, and TR=" << tr << " ms."; report += out.str(); } -void get_report_from_bruker(const image::io::bruker_info& header,std::string& report) +void get_report_from_bruker(const tipl::io::bruker_info& header,std::string& report) { std::ostringstream out; out << " The diffusion images were acquired on a " << header["ORIGIN"] << " scanner using a " @@ -37,7 +37,7 @@ void get_report_from_bruker(const image::io::bruker_info& header,std::string& re << " The diffusion time was " << header["PVM_DwGradSep"] << " ms. The diffusion encoding duration was " << header["PVM_DwGradDur"] << " ms."; report += out.str(); } -void get_report_from_bruker2(const image::io::bruker_info& header,std::string& report) +void get_report_from_bruker2(const tipl::io::bruker_info& header,std::string& report) { std::ostringstream out; out << " The diffusion images were acquired on a " << header["ORIGIN"] @@ -50,14 +50,14 @@ void get_report_from_bruker2(const image::io::bruker_info& header,std::string& r bool DwiHeader::open(const char* filename) { - image::io::dicom header; + tipl::io::dicom header; if (!header.load_from_file(filename)) { - image::io::nifti analyze_header; + tipl::io::nifti analyze_header; if (!analyze_header.load_from_file(filename)) return false; analyze_header >> image; - image::flip_xy(image); + tipl::flip_xy(image); analyze_header.get_voxel_size(voxel_size); return true; } @@ -73,10 +73,10 @@ bool DwiHeader::open(const char* filename) if(header.get_image_orientation(orientation_matrix)) { - image::get_orientation(3,orientation_matrix,dim_order,flip); - image::reorient_vector(voxel_size,dim_order); - image::reorient_matrix(orientation_matrix,dim_order,flip); - image::reorder(image,dim_order,flip); + tipl::get_orientation(3,orientation_matrix,dim_order,flip); + tipl::reorient_vector(voxel_size,dim_order); + tipl::reorient_matrix(orientation_matrix,dim_order,flip); + tipl::reorder(image,dim_order,flip); has_orientation_info = true; } @@ -250,7 +250,7 @@ bool DwiHeader::open(const char* filename) if(has_orientation_info) { { - image::reorient_vector(bvec.begin(),dim_order); + tipl::reorient_vector(bvec.begin(),dim_order); float x = bvec[dim_order[0]]; float y = bvec[dim_order[1]]; float z = bvec[dim_order[2]]; @@ -258,8 +258,8 @@ bool DwiHeader::open(const char* filename) bvec[1] = y; bvec[2] = z; } - image::vector<3,float> cbvec; - image::vector_rotation(bvec.begin(),cbvec.begin(),orientation_matrix,image::vdim<3>()); + tipl::vector<3,float> cbvec; + tipl::vector_rotation(bvec.begin(),cbvec.begin(),orientation_matrix,tipl::vdim<3>()); bvec = cbvec; } bvec.normalize(); @@ -308,7 +308,7 @@ void sort_dwi(std::vector >& dwi_files) void correct_t2(std::vector >& dwi_files) { - image::geometry<3> geo = dwi_files.front()->image.geometry(); + tipl::geometry<3> geo = dwi_files.front()->image.geometry(); //find out if there are two b0 images having different TE std::vector b0_index; std::vector b0_te; @@ -325,8 +325,8 @@ void correct_t2(std::vector >& dwi_files) // average the b0 images { for (unsigned int index = 0;index < b0_index.size();++index) - image::add(spin_density.begin(),spin_density.end(),dwi_files[b0_index[index]]->begin()); - image::divide_constant(spin_density.begin(),spin_density.end(),b0_index.size()); + tipl::add(spin_density.begin(),spin_density.end(),dwi_files[b0_index[index]]->begin()); + tipl::divide_constant(spin_density.begin(),spin_density.end(),b0_index.size()); } // if multiple TE, then we can perform T2 correction @@ -335,12 +335,12 @@ void correct_t2(std::vector >& dwi_files) std::vector neg_inv_T2(geo.size());//-1/T2 { //begin_prog("Eliminating T2 effect"); - for (image::pixel_index<3> index(geo);index < geo.size();++index) + for (tipl::pixel_index<3> index(geo);index < geo.size();++index) { std::vector te_samples; std::vector log_Mxy_samples; - std::vector > neighbor_index1,neighbor_index2; - image::get_neighbors(index,geo,1,neighbor_index1); + std::vector > neighbor_index1,neighbor_index2; + tipl::get_neighbors(index,geo,1,neighbor_index1); for (unsigned int i = 0;i < b0_te.size();++i) { log_Mxy_samples.push_back(dwi_files[b0_index[i]]->image[index.index()]); @@ -354,7 +354,7 @@ void correct_t2(std::vector >& dwi_files) // if not enough b0 images, take the neighbors! if (b0_te.size() < 4) { - image::get_neighbors(index,geo,2,neighbor_index2); + tipl::get_neighbors(index,geo,2,neighbor_index2); for (unsigned int i = 0;i < b0_te.size();++i) { log_Mxy_samples.push_back(dwi_files[b0_index[i]]->image[index.index()]); @@ -385,7 +385,7 @@ void correct_t2(std::vector >& dwi_files) if (log_Mxy_samples.empty()) continue; // (-1/T2,logM0); - std::pair T2_M0 = image::linear_regression(te_samples.begin(),te_samples.end(),log_Mxy_samples.begin()); + std::pair T2_M0 = tipl::linear_regression(te_samples.begin(),te_samples.end(),log_Mxy_samples.begin()); /* T1 T2 Cerebrospinal fluid (similar to pure water) 2200-2400 500-1400 Gray matter of cerebrum 920 100 @@ -465,7 +465,7 @@ bool DwiHeader::output_src(const char* di_file,std::vector geo = dwi_files.front()->image.geometry(); + tipl::geometry<3> geo = dwi_files.front()->image.geometry(); //store dimension unsigned int output_size = 0; @@ -517,7 +517,7 @@ bool DwiHeader::output_src(const char* di_file,std::vector buffer; + tipl::image buffer; const unsigned short* ptr = 0; name << "image" << index; ptr = (const unsigned short*)dwi_files[index]->begin(); @@ -526,18 +526,18 @@ bool DwiHeader::output_src(const char* di_file,std::vectorget_bvalue()); - image_model.voxel.vs = image::vector<3>(dwi_files.front()->voxel_size); + image_model.voxel.vs = tipl::vector<3>(dwi_files.front()->voxel_size); image_model.get_report(report2); } report1 += report2; diff --git a/dicom/dwi_header.hpp b/dicom/dwi_header.hpp index cfa3fcb4e..f0922c9a3 100644 --- a/dicom/dwi_header.hpp +++ b/dicom/dwi_header.hpp @@ -2,7 +2,7 @@ #define DWI_HEADER_HPP #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" class DwiHeader @@ -10,13 +10,13 @@ class DwiHeader typedef std::vector::iterator image_iterator; public: std::string file_name, report; - image::basic_image image; + tipl::image image; float te; public:// for HCP dataset - image::basic_image grad_dev; - image::basic_image mask; + tipl::image grad_dev; + tipl::image mask; public: - image::vector<3, float> bvec; + tipl::vector<3, float> bvec; float bvalue; float voxel_size[3]; public: diff --git a/dicom/motion_dialog.cpp b/dicom/motion_dialog.cpp index ffb7e1837..96ec679f9 100644 --- a/dicom/motion_dialog.cpp +++ b/dicom/motion_dialog.cpp @@ -5,23 +5,23 @@ #include "dicom_parser.h" #include "libs/prog_interface_static_link.h" -void linear_reg(const image::basic_image& from, - const image::vector<3>& from_vs, - const image::basic_image& to, - const image::vector<3>& to_vs, - image::affine_transform& arg, +void linear_reg(const tipl::image& from, + const tipl::vector<3>& from_vs, + const tipl::image& to, + const tipl::vector<3>& to_vs, + tipl::affine_transform& arg, bool& terminated, unsigned int& finished) { - image::reg::linear_mr(from,from_vs,to,to_vs,arg,image::reg::rigid_body, - image::reg::square_error(),terminated); + tipl::reg::linear_mr(from,from_vs,to,to_vs,arg,tipl::reg::rigid_body, + tipl::reg::square_error(),terminated); ++finished; } void motion_detection(std::vector > >& threads, std::vector >& dwi_files, std::vector& b0_index, - std::vector >& arg, + std::vector >& arg, bool& terminated, unsigned int& finished) { @@ -36,7 +36,7 @@ void motion_detection(std::vector > >& threads for(unsigned int index = 1;index < b0_index.size();++index) threads.push_back(std::make_shared >(std::async(std::launch::async,[&,index](){ - image::vector<3> vs(1,1,1); + tipl::vector<3> vs(1,1,1); linear_reg(dwi_files[b0_index[0]]->image, vs,dwi_files[b0_index[index]]->image, vs,arg[index],terminated,finished);}))); @@ -44,9 +44,9 @@ void motion_detection(std::vector > >& threads void motion_correction(std::vector >& dwi_files, const std::vector& b0_index, - const std::vector >& arg) + const std::vector >& arg) { - image::geometry<3> geo(dwi_files[0]->image.geometry()); + tipl::geometry<3> geo(dwi_files[0]->image.geometry()); unsigned int b1 = 0,b2 = 1; for(unsigned int i = 0;i < dwi_files.size();++i) { @@ -70,23 +70,23 @@ void motion_correction(std::vector >& dwi_files, w1 /= dis; w2 /= dis; } - image::affine_transform interpolated_arg; + tipl::affine_transform interpolated_arg; for(unsigned int j = 0;j < 6;++j) interpolated_arg.translocation[j] = arg[b1].translocation[j]*w1 + arg[b2].translocation[j]*w2; - image::vector<3> vs(1,1,1); - image::transformation_matrix T = - image::transformation_matrix(interpolated_arg,geo,vs,geo,vs); + tipl::vector<3> vs(1,1,1); + tipl::transformation_matrix T = + tipl::transformation_matrix(interpolated_arg,geo,vs,geo,vs); - image::basic_image new_image(geo); - image::resample(dwi_files[i]->image,new_image,T,image::linear); + tipl::image new_image(geo); + tipl::resample(dwi_files[i]->image,new_image,T,tipl::linear); dwi_files[i]->image.swap(new_image); // rotate b-table - image::matrix<3,3,float> iT = image::inverse(T.get()); - image::vector<3> tmp; - image::vector_rotation(dwi_files[i]->bvec.begin(),tmp.begin(),iT,image::vdim<3>()); + tipl::matrix<3,3,float> iT = tipl::inverse(T.get()); + tipl::vector<3> tmp; + tipl::vector_rotation(dwi_files[i]->bvec.begin(),tmp.begin(),iT,tipl::vdim<3>()); tmp.normalize(); dwi_files[i]->bvec = tmp; } @@ -201,16 +201,16 @@ void motion_dialog::show_progress(void) std::vector m(arg.size()),r(arg.size()); for(unsigned int i = 0;i < arg.size();++i) { - image::vector<3> t(arg[i].translocation); + tipl::vector<3> t(arg[i].translocation); t[0] *= dwi_files.front()->voxel_size[0]; t[1] *= dwi_files.front()->voxel_size[1]; t[2] *= dwi_files.front()->voxel_size[2]; m[i] = t.length(); - r[i] = image::vector<3>(arg[i].rotation).length()*180.0/3.14159265358979323846; + r[i] = tipl::vector<3>(arg[i].rotation).length()*180.0/3.14159265358979323846; } ui->label->setText(QString("averaged translocation:%1 mm rotation:%2 degrees"). - arg(image::mean(m.begin(),m.end())). - arg(image::mean(r.begin(),r.end()))); + arg(tipl::mean(m.begin(),m.end())). + arg(tipl::mean(r.begin(),r.end()))); } if(finished == arg.size()-1) diff --git a/dicom/motion_dialog.hpp b/dicom/motion_dialog.hpp index dd95ee4c0..c89a5a1c2 100644 --- a/dicom/motion_dialog.hpp +++ b/dicom/motion_dialog.hpp @@ -2,7 +2,7 @@ #define MOTION_DIALOG_HPP #include #include "dwi_header.hpp" -#include "image/image.hpp" +#include "tipl/tipl.hpp" namespace Ui { class motion_dialog; @@ -15,7 +15,7 @@ class motion_dialog : public QDialog dicom_parser& dicom_gui; std::vector >& dwi_files; std::vector b0_index; - std::vector > arg; + std::vector > arg; bool terminated; unsigned int finished; std::vector > > threads; diff --git a/dsi_studio.pro.user b/dsi_studio.pro.user index e621acdd8..85eb3a759 100644 --- a/dsi_studio.pro.user +++ b/dsi_studio.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/filebrowser.cpp b/filebrowser.cpp index 212524c32..cffd15ec0 100644 --- a/filebrowser.cpp +++ b/filebrowser.cpp @@ -4,7 +4,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "filebrowser.h" #include "ui_filebrowser.h" #include "dicom/dicom_parser.h" @@ -97,7 +97,7 @@ void FileBrowser::on_subject_list_currentCellChanged(int currentRow, int , int p std::sort(seq_list.begin(),seq_list.end()); for(int index = 0;index < seq_list.size();++index) { - image::io::bruker_info method,acq,reco_file,d3proc_file; + tipl::io::bruker_info method,acq,reco_file,d3proc_file; bool method_file = true; QString method_dir = directory.absolutePath() + "/" + QString::number(seq_list[index]); QString method_file_name = method_dir+ "/method"; @@ -183,7 +183,7 @@ void FileBrowser::on_subject_list_currentCellChanged(int currentRow, int , int p std::vector dcm_file_list_full; for(unsigned int j = 0;j < dcm_file_list.size();++j) dcm_file_list_full.push_back((sub_dir.absolutePath() + "/" + dcm_file_list[j]).toLocal8Bit().begin()); - image::io::volume dcm; + tipl::io::volume dcm; if(!dcm.load_from_files(dcm_file_list_full,dcm_file_list_full.size())) continue; int row = ui->tableWidget->rowCount(); @@ -284,7 +284,7 @@ void FileBrowser::populateDirs(void) QString subject_file_name = ui->WorkDir->text()+"/" + script_list[index] + "/subject"; - image::io::bruker_info subject_file; + tipl::io::bruker_info subject_file; if(subject_file.load_from_file(subject_file_name.toLocal8Bit().begin())) { std::istringstream in(subject_file["SUBJECT_date"]); @@ -343,9 +343,9 @@ void FileBrowser::show_image(void) cur_z = 0; { - image::basic_image data_buffer; - image::reslicing(data,data_buffer,2,cur_z); - image::normalize(data_buffer,slice_image,255); + tipl::image data_buffer; + tipl::reslicing(data,data_buffer,2,cur_z); + tipl::normalize(data_buffer,slice_image,255); } view_image = QImage((unsigned char*)&*slice_image.begin(),slice_image.width(),slice_image.height(),QImage::Format_RGB32); show_view(scene,view_image); @@ -356,7 +356,7 @@ void FileBrowser::preview_image(QString file_name) preview_data.clear(); if(QFileInfo(file_name).fileName() == "2dseq") { - image::io::bruker_2dseq header; + tipl::io::bruker_2dseq header; if(header.load_from_file(file_name.toLocal8Bit().begin())) { header.get_image().swap(preview_data); @@ -371,7 +371,7 @@ void FileBrowser::preview_image(QString file_name) std::vector dcm_file_list_full; for(unsigned int j = 0;j < dcm_file_list.size();++j) dcm_file_list_full.push_back((dir.absolutePath() + "/" + dcm_file_list[j]).toLocal8Bit().begin()); - image::io::volume dcm; + tipl::io::volume dcm; if(dcm.load_from_files(dcm_file_list_full,dcm_file_list_full.size())) dcm >> preview_data; preview_loaded = true; @@ -386,7 +386,7 @@ void FileBrowser::preview_image(QString file_name) const short* dim = 0; if(mat.read("dimension",r,c,dim)) { - preview_data.resize(image::geometry<3>(dim)); + preview_data.resize(tipl::geometry<3>(dim)); const float* ptr = 0; if(!mat.read("fa0",r,c,ptr)) mat.read("image0",r,c,ptr); diff --git a/filebrowser.h b/filebrowser.h index 03f01aaad..e2f4254f4 100644 --- a/filebrowser.h +++ b/filebrowser.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include @@ -17,8 +17,8 @@ class FileBrowser : public QMainWindow QGraphicsScene scene; public: unsigned int cur_z; - image::basic_image data; - image::color_image slice_image; + tipl::image data; + tipl::color_image slice_image; QImage view_image; public: explicit FileBrowser(QWidget *parent); @@ -35,7 +35,7 @@ class FileBrowser : public QMainWindow QString preview_file_name; float preview_voxel_size[3]; bool preview_loaded; - image::basic_image preview_data; + tipl::image preview_data; std::auto_ptr> preview_thread; void preview_image(QString file_name); private slots: diff --git a/libs/dsi/basic_voxel.cpp b/libs/dsi/basic_voxel.cpp index 537c1e799..6c61a869d 100644 --- a/libs/dsi/basic_voxel.cpp +++ b/libs/dsi/basic_voxel.cpp @@ -31,7 +31,7 @@ void Voxel::calculate_sinc_ql(std::vector& sinc_ql) for (unsigned int j = 0,index = 0; j < odf_size; ++j) for (unsigned int i = 0; i < bvalues.size(); ++i,++index) sinc_ql[index] = bvectors[i]* - image::vector<3,float>(ti.vertices[j])* + tipl::vector<3,float>(ti.vertices[j])* std::sqrt(bvalues[i]*0.01506); for (unsigned int index = 0; index < sinc_ql.size(); ++index) @@ -39,7 +39,7 @@ void Voxel::calculate_sinc_ql(std::vector& sinc_ql) base_function(sinc_ql[index]*sigma): boost::math::sinc_pi(sinc_ql[index]*sigma); } -void Voxel::calculate_q_vec_t(std::vector >& q_vectors_time) +void Voxel::calculate_q_vec_t(std::vector >& q_vectors_time) { float sigma = param[0]; q_vectors_time.resize(bvalues.size()); @@ -72,7 +72,7 @@ void Voxel::load_from_src(ImageModel& image_model) if(image_model.src_bvalues[sorted_index[0]] == 0.0f) { bvalues.push_back(0); - bvectors.push_back(image::vector<3,float>(0,0,0)); + bvectors.push_back(tipl::vector<3,float>(0,0,0)); dwi_data.push_back(image_model.src_dwi_data[sorted_index[0]]); b0_index = 0; } @@ -86,33 +86,33 @@ void Voxel::load_from_src(ImageModel& image_model) if(image_model.has_image_rotation) for (unsigned int index = 0;index < bvectors.size();++index) { - image::vector<3> tmp; - image::vector_rotation(bvectors[index].begin(),tmp.begin(),image_model.src_bvectors_rotate,image::vdim<3>()); + tipl::vector<3> tmp; + tipl::vector_rotation(bvectors[index].begin(),tmp.begin(),image_model.src_bvectors_rotate,tipl::vdim<3>()); tmp.normalize(); bvectors[index] = tmp; } } -void Voxel::calculate_mask(const image::basic_image& dwi_sum) +void Voxel::calculate_mask(const tipl::image& dwi_sum) { - image::threshold(dwi_sum,mask,0.2f,1,0); + tipl::threshold(dwi_sum,mask,0.2f,1,0); if(dwi_sum.depth() < 10) { for(unsigned int i = 0;i < mask.depth();++i) { - image::pointer_image I(&mask[0]+i*mask.plane_size(), - image::geometry<2>(mask.width(),mask.height())); - image::morphology::defragment(I); - image::morphology::recursive_smoothing(I,10); - image::morphology::defragment(I); + tipl::pointer_image I(&mask[0]+i*mask.plane_size(), + tipl::geometry<2>(mask.width(),mask.height())); + tipl::morphology::defragment(I); + tipl::morphology::recursive_smoothing(I,10); + tipl::morphology::defragment(I); } } else { - image::morphology::recursive_smoothing(mask,10); - image::morphology::defragment(mask); - image::morphology::recursive_smoothing(mask,10); + tipl::morphology::recursive_smoothing(mask,10); + tipl::morphology::defragment(mask); + tipl::morphology::recursive_smoothing(mask,10); } } @@ -129,7 +129,7 @@ void Voxel::run(void) ++total_voxel; unsigned int total = 0; - image::par_for2(mask.size(), + tipl::par_for2(mask.size(), [&](int voxel_index,int thread_index) { ++total; diff --git a/libs/dsi/basic_voxel.hpp b/libs/dsi/basic_voxel.hpp index 32e5777c1..cfe7fe8ce 100644 --- a/libs/dsi/basic_voxel.hpp +++ b/libs/dsi/basic_voxel.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include "tessellated_icosahedron.hpp" #include "gzip_interface.hpp" @@ -31,16 +31,16 @@ struct VoxelData std::vector odf; std::vector fa; std::vector rdi; - std::vector > dir; + std::vector > dir; std::vector dir_index; float min_odf; - image::matrix<3,3,float> jacobian; + tipl::matrix<3,3,float> jacobian; void init(void) { std::fill(fa.begin(),fa.end(),0.0); std::fill(dir_index.begin(),dir_index.end(),0); - std::fill(dir.begin(),dir.end(),image::vector<3,float>()); + std::fill(dir.begin(),dir.end(),tipl::vector<3,float>()); } }; @@ -50,15 +50,15 @@ class Voxel private: std::vector > process_list; public: - image::geometry<3> dim; - image::vector<3> vs; + tipl::geometry<3> dim; + tipl::vector<3> vs; public: - image::basic_image mask; - void calculate_mask(const image::basic_image& dwi_sum); + tipl::image mask; + void calculate_mask(const tipl::image& dwi_sum); public: std::vector dwi_data; - std::vector > bvectors; + std::vector > bvectors; std::vector bvalues; std::string report; @@ -80,34 +80,34 @@ class Voxel bool half_sphere = false; int b0_index = -1; void calculate_sinc_ql(std::vector& sinc_ql); - void calculate_q_vec_t(std::vector >& q_vector_time); + void calculate_q_vec_t(std::vector >& q_vector_time); public://used in GQI bool scheme_balance = false; bool csf_calibration = false; public:// odf sharpening bool odf_deconvolusion = false; bool odf_decomposition = false; - image::vector<3,short> odf_xyz; + tipl::vector<3,short> odf_xyz; public:// gradient deviation - std::vector > new_grad_dev; - std::vector > grad_dev; + std::vector > new_grad_dev; + std::vector > grad_dev; public:// used in QSDR std::string external_template; unsigned char reg_method = 0; - image::transformation_matrix qsdr_trans; + tipl::transformation_matrix qsdr_trans; bool output_jacobian = false; bool output_mapping = false; bool output_rdi = false; bool qsdr = false; - image::vector<3,int> csf_pos1,csf_pos2,csf_pos3,csf_pos4; + tipl::vector<3,int> csf_pos1,csf_pos2,csf_pos3,csf_pos4; double R2; public: // for QSDR associated T1WT2W - std::vector > other_image; + std::vector > other_image; std::vector other_image_name; - std::vector > other_image_affine; + std::vector > other_image_affine; public: // for T1W based DMDM - image::basic_image t1w,t1wt; - image::vector<3> t1w_vs,t1wt_vs; + tipl::image t1w,t1wt; + tipl::vector<3> t1w_vs,t1wt_vs; float t1wt_tran[16]; std::string t1w_file_name; @@ -122,7 +122,7 @@ class Voxel float z0 = 0.0; // other information for second pass processing std::vector response_function,free_water_diffusion; - image::basic_image qa_map; + tipl::image qa_map; float reponse_function_scaling; public:// for template creation std::vector > template_odfs; diff --git a/libs/dsi/dsi_interface_imp.cpp b/libs/dsi/dsi_interface_imp.cpp index 4d4cfbcaa..31f5f2788 100644 --- a/libs/dsi/dsi_interface_imp.cpp +++ b/libs/dsi/dsi_interface_imp.cpp @@ -362,7 +362,7 @@ const char* reconstruction(ImageModel* image_model, " The restricted diffusion was quantified using restricted diffusion imaging (Yeh et al., MRM, 77:603–612 (2017))."; { - std::vector > tmp; + std::vector > tmp; tmp.swap(image_model->voxel.grad_dev); // clear mask to create whole volume QA map std::fill(image_model->voxel.mask.begin(),image_model->voxel.mask.end(),1.0); @@ -402,14 +402,14 @@ const char* reconstruction(ImageModel* image_model, begin_prog("Registration between longitudinal scans"); { - image::transformation_matrix arg; + tipl::transformation_matrix arg; bool terminated = false; check_prog(0,1); - image::reg::two_way_linear_mr(image_model->dwi_sum, + tipl::reg::two_way_linear_mr(image_model->dwi_sum, image_model->voxel.vs, image_model->study_src->dwi_sum, image_model->study_src->voxel.vs, - arg,image::reg::rigid_body,image::reg::correlation(),terminated); + arg,tipl::reg::rigid_body,tipl::reg::correlation(),terminated); image_model->study_src->rotate(image_model->dwi_sum,arg); image_model->study_src->voxel.load_from_src(*(image_model->study_src.get())); image_model->study_src->voxel.vs = image_model->voxel.vs; @@ -423,16 +423,16 @@ const char* reconstruction(ImageModel* image_model, { begin_prog("Smoothing"); check_prog(0,2); - image::par_for(image_model->src_dwi_data.size(),[&](int i) + tipl::par_for(image_model->src_dwi_data.size(),[&](int i) { - auto I = image::make_image((unsigned short*)image_model->src_dwi_data[i],image_model->voxel.dim); - image::filter::gaussian(I); + auto I = tipl::make_image((unsigned short*)image_model->src_dwi_data[i],image_model->voxel.dim); + tipl::filter::gaussian(I); },image_model->voxel.thread_count); check_prog(1,2); - image::par_for(image_model->study_src->new_dwi.size(),[&](int i) + tipl::par_for(image_model->study_src->new_dwi.size(),[&](int i) { - auto I = image::make_image((unsigned short*)&image_model->study_src->new_dwi[i][0],image_model->study_src->voxel.dim); - image::filter::gaussian(I); + auto I = tipl::make_image((unsigned short*)&image_model->study_src->new_dwi[i][0],image_model->study_src->voxel.dim); + tipl::filter::gaussian(I); },image_model->voxel.thread_count); check_prog(2,2); } @@ -440,16 +440,16 @@ const char* reconstruction(ImageModel* image_model, double r2 = 0.0; { double a,b; - image::linear_regression(image_model->study_src->src_dwi_data[0], + tipl::linear_regression(image_model->study_src->src_dwi_data[0], image_model->study_src->src_dwi_data[0]+ image_model->study_src->voxel.dim.size(), image_model->src_dwi_data[0],a,b,r2); std::cout << "y=" << a << "x+" << b << " r2=" << r2 << std::endl; - image::par_for(image_model->study_src->new_dwi.size(),[&](int i) + tipl::par_for(image_model->study_src->new_dwi.size(),[&](int i) { - image::multiply_constant(image_model->study_src->new_dwi[i].begin(),image_model->study_src->new_dwi[i].end(),a); - image::add_constant(image_model->study_src->new_dwi[i].begin(),image_model->study_src->new_dwi[i].end(),b); - image::lower_threshold(image_model->study_src->new_dwi[i].begin(),image_model->study_src->new_dwi[i].end(),0.0f); + tipl::multiply_constant(image_model->study_src->new_dwi[i].begin(),image_model->study_src->new_dwi[i].end(),a); + tipl::add_constant(image_model->study_src->new_dwi[i].begin(),image_model->study_src->new_dwi[i].end(),b); + tipl::lower_threshold(image_model->study_src->new_dwi[i].begin(),image_model->study_src->new_dwi[i].end(),0.0f); },image_model->voxel.thread_count); } @@ -486,7 +486,7 @@ const char* reconstruction(ImageModel* image_model, } -bool output_odfs(const image::basic_image& mni_mask, +bool output_odfs(const tipl::image& mni_mask, const char* out_name, const char* ext, std::vector >& odfs, @@ -522,7 +522,7 @@ const char* odf_average(const char* out_name,std::vector& file_name static std::string error_msg,report; tessellated_icosahedron ti; float vs[3]; - image::basic_image mask; + tipl::image mask; std::vector > odfs; unsigned int half_vertex_count = 0; unsigned int row,col; @@ -574,7 +574,7 @@ const char* odf_average(const char* out_name,std::vector& file_name check_prog(0,0); return error_msg.c_str(); } - mask.resize(image::geometry<3>(dimension)); + mask.resize(tipl::geometry<3>(dimension)); for(unsigned int index = 0;index < mask.size();++index) if(fa0[index] != 0.0) mask[index] = 1; @@ -684,7 +684,7 @@ const char* odf_average(const char* out_name,std::vector& file_name } } for(unsigned int i = 0;i < odf_bufs.size();++i) - image::add(odfs[i].begin(),odfs[i].end(),odf_bufs[i]); + tipl::add(odfs[i].begin(),odfs[i].end(),odf_bufs[i]); } if (prog_aborted()) return 0; diff --git a/libs/dsi/dsi_process.hpp b/libs/dsi/dsi_process.hpp index 2dde5d2a5..b2c34c954 100644 --- a/libs/dsi/dsi_process.hpp +++ b/libs/dsi/dsi_process.hpp @@ -14,7 +14,7 @@ class QSpace2Pdf : public BaseProcess std::vector qspace_mapping1; std::vector qspace_mapping2; std::vector hanning_filter; - std::auto_ptr > fft; + std::auto_ptr > fft; public: static double get_min_b(const Voxel& voxel) { @@ -32,18 +32,18 @@ class QSpace2Pdf : public BaseProcess } return 0; } - static void get_q_table(const Voxel& voxel,std::vector >& q_table) + static void get_q_table(const Voxel& voxel,std::vector >& q_table) { float b_min = get_min_b(voxel); for (unsigned int index = 0; index < voxel.bvalues.size(); ++index) { - image::vector<3,float> bvec = voxel.bvectors[index]; + tipl::vector<3,float> bvec = voxel.bvectors[index]; bvec.normalize(); bvec *= std::sqrt(std::abs(voxel.bvalues[index]/b_min)); bvec[0] = std::round(bvec[0]); bvec[1] = std::round(bvec[1]); bvec[2] = std::round(bvec[2]); - q_table.push_back(image::vector<3,int>(bvec[0],bvec[1],bvec[2])); + q_table.push_back(tipl::vector<3,int>(bvec[0],bvec[1],bvec[2])); } } @@ -53,7 +53,7 @@ class QSpace2Pdf : public BaseProcess qspace_mapping1.resize(voxel.bvalues.size()); qspace_mapping2.resize(voxel.bvalues.size()); hanning_filter.resize(voxel.bvalues.size()); - std::vector > q_table; + std::vector > q_table; get_q_table(voxel,q_table); @@ -69,7 +69,7 @@ class QSpace2Pdf : public BaseProcess float r = (float)std::sqrt((float)(x*x+y*y+z*z)); hanning_filter[index] = 0.5 * (1.0+std::cos(2.0*r*M_PI/((float)filter_width))); } - fft.reset(new image::fftn<3>(image::geometry<3>(space_length,space_length,space_length))); + fft.reset(new tipl::fftn<3>(tipl::geometry<3>(space_length,space_length,space_length))); } virtual void run(Voxel&, VoxelData& data) { @@ -114,9 +114,9 @@ struct Pdf2Odf : public BaseProcess for(unsigned int index = 0;index < sample_group.size();++index) sample_group[index].sampleODFValueWeighted(data.space,data.odf); // normalization - float sum = image::mean(data.odf.begin(),data.odf.end()); + float sum = tipl::mean(data.odf.begin(),data.odf.end()); if (sum != 0.0) - image::multiply_constant(data.odf,data.space[b0_index]/sum); + tipl::multiply_constant(data.odf,data.space[b0_index]/sum); } }; diff --git a/libs/dsi/dti_process.hpp b/libs/dsi/dti_process.hpp index db82fb6f5..c4170e5c6 100644 --- a/libs/dsi/dti_process.hpp +++ b/libs/dsi/dti_process.hpp @@ -2,7 +2,7 @@ #define DTI_PROCESS_HPP #include #include "basic_voxel.hpp" -#include "image/image.hpp" +#include "tipl/tipl.hpp" class Dwi2Tensor : public BaseProcess { @@ -61,7 +61,7 @@ class Dwi2Tensor : public BaseProcess } b_count = voxel.bvalues.size()-1; - std::vector > b_data(b_count); + std::vector > b_data(b_count); //skip b0 std::copy(voxel.bvectors.begin()+1,voxel.bvectors.end(),b_data.begin()); for(unsigned int index = 0; index < b_count; ++index) @@ -76,8 +76,8 @@ class Dwi2Tensor : public BaseProcess { //qq = q qT std::vector qq(3*3); - image::mat::product_transpose(b_data[i].begin(),b_data[i].begin(),qq.begin(), - image::dyndim(3,1),image::dyndim(3,1)); + tipl::mat::product_transpose(b_data[i].begin(),b_data[i].begin(),qq.begin(), + tipl::dyndim(3,1),tipl::dyndim(3,1)); /* q11 q15 q19 2*q12 2*q13 2*q16 @@ -94,15 +94,15 @@ class Dwi2Tensor : public BaseProcess { iKtK[i].resize(6*6); iKtK_pivot[i].resize(6); - image::mat::product_transpose(Kt.begin(),Kt.begin(),iKtK[i].begin(), - image::dyndim(6,b_count),image::dyndim(6,b_count)); + tipl::mat::product_transpose(Kt.begin(),Kt.begin(),iKtK[i].begin(), + tipl::dyndim(6,b_count),tipl::dyndim(6,b_count)); if(i) { double w = 0.005*std::pow(2.0,(double)i)*(*std::max_element(iKtK[i].begin(),iKtK[i].end())); for(unsigned int j = 0;j < 36;j += 7) iKtK[i][j] += w; } - image::mat::lu_decomposition(iKtK[i].begin(),iKtK_pivot[i].begin(),image::dyndim(6,6)); + tipl::mat::lu_decomposition(iKtK[i].begin(),iKtK_pivot[i].begin(),tipl::dyndim(6,6)); } } public: @@ -121,15 +121,15 @@ class Dwi2Tensor : public BaseProcess double V[9],d[3]; for(unsigned int i = 0;i < iKtK.size();++i) { - image::mat::product(Kt.begin(),signal.begin(),KtS,image::dyndim(6,b_count),image::dyndim(b_count,1)); - image::mat::lu_solve(iKtK[i].begin(),iKtK_pivot[i].begin(),KtS,tensor_param,image::dyndim(6,6)); + tipl::mat::product(Kt.begin(),signal.begin(),KtS,tipl::dyndim(6,b_count),tipl::dyndim(b_count,1)); + tipl::mat::lu_solve(iKtK[i].begin(),iKtK_pivot[i].begin(),KtS,tensor_param,tipl::dyndim(6,6)); unsigned int tensor_index[9] = {0,3,4,3,1,5,4,5,2}; for (unsigned int index = 0; index < 9; ++index) tensor[index] = tensor_param[tensor_index[index]]; - image::mat::eigen_decomposition_sym(tensor,V,d,image::dim<3,3>()); + tipl::mat::eigen_decomposition_sym(tensor,V,d,tipl::dim<3,3>()); if(d[0] > 0.0 && d[1] > 0.0 && d[2] > 0.0) break; } diff --git a/libs/dsi/gqi_mni_reconstruction.hpp b/libs/dsi/gqi_mni_reconstruction.hpp index dc1bd5661..8f38649e3 100644 --- a/libs/dsi/gqi_mni_reconstruction.hpp +++ b/libs/dsi/gqi_mni_reconstruction.hpp @@ -12,25 +12,25 @@ extern fa_template fa_template_imp; class DWINormalization : public BaseProcess { protected: - image::geometry<3> src_geo; - image::geometry<3> des_geo; + tipl::geometry<3> src_geo; + tipl::geometry<3> des_geo; protected: - std::auto_ptr > mni; + std::auto_ptr > mni; protected: - image::basic_image,3> cdm_dis; + tipl::image,3> cdm_dis; protected: - image::transformation_matrix affine; + tipl::transformation_matrix affine; float affine_volume_scale; float resolution_ratio; // output resolution protected: // for warping other image modality - std::vector > other_image,other_image_x,other_image_y,other_image_z; + std::vector > other_image,other_image_x,other_image_y,other_image_z; protected: double trans_to_mni[16]; protected: std::vector jdet; std::vector mx,my,mz; protected: - typedef image::const_pointer_image point_image_type; + typedef tipl::const_pointer_image point_image_type; std::vector ptr_images; public: @@ -41,9 +41,9 @@ class DWINormalization : public BaseProcess voxel.vs[2] == 0.0) throw std::runtime_error("No spatial information found in src file. Recreate src file or contact developer for assistance"); - image::basic_image VG,VF; - image::vector<3> VGvs = fa_template_imp.vs; - image::vector<3> VGshift = fa_template_imp.shift; + tipl::image VG,VF; + tipl::vector<3> VGvs = fa_template_imp.vs; + tipl::vector<3> VGshift = fa_template_imp.shift; VG = fa_template_imp.I; VF = voxel.qa_map; if(!voxel.external_template.empty()) @@ -102,45 +102,45 @@ class DWINormalization : public BaseProcess { int prog = 0; // calculate the space shift between DWI and T1W - image::vector<3> from(VGshift),to; + tipl::vector<3> from(VGshift),to; from[0] -= (int)VG.width()+voxel.t1wt_tran[3]-(int)voxel.t1wt.width(); from[1] -= (int)VG.height()+voxel.t1wt_tran[7]-(int)voxel.t1wt.height(); from[2] -= voxel.t1wt_tran[11]; to = from; - to += image::vector<3>(VG.geometry()); + to += tipl::vector<3>(VG.geometry()); - image::normalize(voxel.t1w,1.0); - image::normalize(voxel.t1wt,1.0); + tipl::normalize(voxel.t1w,1.0); + tipl::normalize(voxel.t1wt,1.0); - image::thread thread1,thread2; - image::transformation_matrix reg1T,reg2T; + tipl::thread thread1,thread2; + tipl::transformation_matrix reg1T,reg2T; thread1.run([&](){ if(export_intermediate) { - image::flip_xy(voxel.qa_map); + tipl::flip_xy(voxel.qa_map); gz_nifti nii; nii.set_voxel_size(voxel.vs); nii << voxel.qa_map; nii.save_to_file("b0.nii.gz"); - image::flip_xy(voxel.qa_map); + tipl::flip_xy(voxel.qa_map); } - image::reg::two_way_linear_mr(voxel.t1w,voxel.t1w_vs,voxel.qa_map,voxel.vs, - reg1T,image::reg::rigid_body,image::reg::mutual_information(), + tipl::reg::two_way_linear_mr(voxel.t1w,voxel.t1w_vs,voxel.qa_map,voxel.vs, + reg1T,tipl::reg::rigid_body,tipl::reg::mutual_information(), thread1.terminated,voxel.thread_count); }); thread2.run([&](){ prog = 1; - image::reg::two_way_linear_mr(voxel.t1wt,voxel.t1wt_vs,voxel.t1w,voxel.t1w_vs, - reg2T,image::reg::affine,image::reg::mutual_information(), + tipl::reg::two_way_linear_mr(voxel.t1wt,voxel.t1wt_vs,voxel.t1w,voxel.t1w_vs, + reg2T,tipl::reg::affine,tipl::reg::mutual_information(), thread2.terminated,voxel.thread_count); - image::basic_image J(voxel.t1wt.geometry()); - image::resample_mt(voxel.t1w,J,reg2T,image::cubic); + tipl::image J(voxel.t1wt.geometry()); + tipl::resample_mt(voxel.t1w,J,reg2T,tipl::cubic); prog = 3; { - image::basic_image Is(J),It(voxel.t1wt); - image::filter::gaussian(Is); + tipl::image Is(J),It(voxel.t1wt); + tipl::filter::gaussian(Is); if(export_intermediate) { It.save_to_file("It.nii.gz"); @@ -148,13 +148,13 @@ class DWINormalization : public BaseProcess } float resolution = 2.0f; float smoothness = 0.5f; - voxel.R2 = image::reg::cdm(It,Is,cdm_dis,thread2.terminated,resolution,smoothness); + voxel.R2 = tipl::reg::cdm(It,Is,cdm_dis,thread2.terminated,resolution,smoothness); voxel.R2 *= voxel.R2; } - image::compose_displacement(J,cdm_dis,voxel.t1w); + tipl::compose_displacement(J,cdm_dis,voxel.t1w); // From T1W template space to FA template space - image::crop(voxel.t1w,from,to); - image::crop(cdm_dis,from,to); + tipl::crop(voxel.t1w,from,to); + tipl::crop(cdm_dis,from,to); if(export_intermediate) { @@ -183,21 +183,21 @@ class DWINormalization : public BaseProcess if(export_intermediate) { - image::basic_image b0J(VG.geometry()); - image::resample_mt(voxel.qa_map,b0J,affine,image::cubic); + tipl::image b0J(VG.geometry()); + tipl::resample_mt(voxel.qa_map,b0J,affine,tipl::cubic); b0J.save_to_file("b0j.nii.gz"); } goto end_normalization; } { - image::filter::gaussian(VF); - VF -= image::segmentation::otsu_threshold(VF); - image::lower_threshold(VF,0.0); - image::normalize(VG,1.0); - image::normalize(VF,1.0); + tipl::filter::gaussian(VF); + VF -= tipl::segmentation::otsu_threshold(VF); + tipl::lower_threshold(VF,0.0); + tipl::normalize(VG,1.0); + tipl::normalize(VF,1.0); - image::basic_image VFF; + tipl::image VFF; { begin_prog("linear registration"); @@ -214,17 +214,17 @@ class DWINormalization : public BaseProcess else { bool terminated = false; - image::reg::two_way_linear_mr(VG,VGvs,VF,voxel.vs,affine, - image::reg::affine,image::reg::correlation(),terminated,voxel.thread_count); + tipl::reg::two_way_linear_mr(VG,VGvs,VF,voxel.vs,affine, + tipl::reg::affine,tipl::reg::correlation(),terminated,voxel.thread_count); } VFF.resize(VG.geometry()); - image::resample(VF,VFF,affine,image::cubic); + tipl::resample(VF,VFF,affine,tipl::cubic); if(prog_aborted()) throw std::runtime_error("Reconstruction canceled"); } //linear regression - image::match_signal(VG,VFF); + tipl::match_signal(VG,VFF); if(export_intermediate) @@ -240,23 +240,23 @@ class DWINormalization : public BaseProcess { if(factor <= 3) { - mni.reset(new image::reg::bfnorm_mapping(VG.geometry(),image::geometry<3>(factor*7,factor*9,factor*7))); - image::reg::bfnorm(*mni.get(),VG,VFF,ter,voxel.thread_count); - voxel.R2 = -image::reg::correlation()(VG,VFF,(*mni.get())); + mni.reset(new tipl::reg::bfnorm_mapping(VG.geometry(),tipl::geometry<3>(factor*7,factor*9,factor*7))); + tipl::reg::bfnorm(*mni.get(),VG,VFF,ter,voxel.thread_count); + voxel.R2 = -tipl::reg::correlation()(VG,VFF,(*mni.get())); if(export_intermediate) { - image::basic_image VFFF(VG.geometry()); - image::resample(VFF,VFFF,*mni.get(),image::cubic); + tipl::image VFFF(VG.geometry()); + tipl::resample(VFF,VFFF,*mni.get(),tipl::cubic); VFFF.save_to_file("Subject_QA_nonlinear_reg.nii.gz"); } } else { bool terminated = false; - image::reg::cdm(VG,VFF,cdm_dis,terminated,2.0*resolution_ratio,0.5); - image::basic_image VFFF; - image::compose_displacement(VFF,cdm_dis,VFFF); - float r = image::correlation(VG.begin(),VG.end(),VFFF.begin()); + tipl::reg::cdm(VG,VFF,cdm_dis,terminated,2.0*resolution_ratio,0.5); + tipl::image VFFF; + tipl::compose_displacement(VFF,cdm_dis,VFFF); + float r = tipl::correlation(VG.begin(),VG.end(),VFFF.begin()); voxel.R2 = r*r; } std::cout << "R2=" << voxel.R2 << std::endl; @@ -276,9 +276,9 @@ class DWINormalization : public BaseProcess voxel.dim = des_geo; voxel.mask.resize(des_geo); std::fill(voxel.mask.begin(),voxel.mask.end(),0); - for(image::pixel_index<3> index(des_geo);index < des_geo.size();++index) + for(tipl::pixel_index<3> index(des_geo);index < des_geo.size();++index) { - image::vector<3,float> mni_pos(index); + tipl::vector<3,float> mni_pos(index); mni_pos *= resolution_ratio; mni_pos.round(); if(VG.geometry().is_valid(mni_pos) && @@ -310,12 +310,12 @@ class DWINormalization : public BaseProcess ptr_images.clear(); for (unsigned int index = 0; index < voxel.dwi_data.size(); ++index) - ptr_images.push_back(image::make_image(voxel.dwi_data[index],src_geo)); + ptr_images.push_back(tipl::make_image(voxel.dwi_data[index],src_geo)); std::fill(voxel.vs.begin(),voxel.vs.end(),VGvs[0]*resolution_ratio); - if(VG.geometry() == image::geometry<3>(157,189,136)) // if default template is used + if(VG.geometry() == tipl::geometry<3>(157,189,136)) // if default template is used { voxel.csf_pos1 = mni_to_voxel_index(6,0,18); voxel.csf_pos2 = mni_to_voxel_index(-6,0,18); @@ -324,7 +324,7 @@ class DWINormalization : public BaseProcess } else { - voxel.csf_pos1 = voxel.csf_pos2 = voxel.csf_pos3 = voxel.csf_pos4 = image::vector<3,int>(0,0,0); + voxel.csf_pos1 = voxel.csf_pos2 = voxel.csf_pos3 = voxel.csf_pos4 = tipl::vector<3,int>(0,0,0); } // output mapping if(voxel.output_jacobian) @@ -339,7 +339,7 @@ class DWINormalization : public BaseProcess voxel.qsdr = true; } - image::vector<3,int> mni_to_voxel_index(int x,int y,int z) const + tipl::vector<3,int> mni_to_voxel_index(int x,int y,int z) const { x = trans_to_mni[3]-x; y = trans_to_mni[7]-y; @@ -347,10 +347,10 @@ class DWINormalization : public BaseProcess x /= resolution_ratio; y /= resolution_ratio; z /= resolution_ratio; - return image::vector<3,int>(x,y,z); + return tipl::vector<3,int>(x,y,z); } template - void interpolate_dwi(Voxel& voxel, VoxelData& data,const image::vector<3,double>& Jpos,interpolation_type) + void interpolate_dwi(Voxel& voxel, VoxelData& data,const tipl::vector<3,double>& Jpos,interpolation_type) { interpolation_type interpolation; @@ -374,10 +374,10 @@ class DWINormalization : public BaseProcess if(!voxel.grad_dev.empty()) { - image::matrix<3,3,float> grad_dev,new_j; + tipl::matrix<3,3,float> grad_dev,new_j; for(unsigned int i = 0; i < 9; ++i) interpolation.estimate(voxel.grad_dev[i],grad_dev[i]); - image::mat::transpose(grad_dev.begin(),image::dim<3,3>()); + tipl::mat::transpose(grad_dev.begin(),tipl::dim<3,3>()); new_j = grad_dev*data.jacobian; data.jacobian = new_j; } @@ -387,7 +387,7 @@ class DWINormalization : public BaseProcess { if(voxel.other_image[index].geometry() != src_geo) { - image::vector<3,double> Opos; + tipl::vector<3,double> Opos; voxel.other_image_affine[index](Jpos,Opos); if(voxel.output_mapping) { @@ -395,7 +395,7 @@ class DWINormalization : public BaseProcess other_image_y[index][data.voxel_index] = Opos[1]; other_image_z[index][data.voxel_index] = Opos[2]; } - image::estimate(voxel.other_image[index],Opos,other_image[index][data.voxel_index]); + tipl::estimate(voxel.other_image[index],Opos,other_image[index][data.voxel_index]); } else interpolation.estimate(voxel.other_image[index],other_image[index][data.voxel_index]); @@ -404,25 +404,25 @@ class DWINormalization : public BaseProcess virtual void run(Voxel& voxel, VoxelData& data) { - image::vector<3,double> pos(image::pixel_index<3>(data.voxel_index,voxel.dim)),Jpos; + tipl::vector<3,double> pos(tipl::pixel_index<3>(data.voxel_index,voxel.dim)),Jpos; pos[0] *= resolution_ratio; pos[1] *= resolution_ratio; pos[2] *= resolution_ratio; pos.round(); - image::vector<3,int> ipos(pos[0],pos[1],pos[2]); + tipl::vector<3,int> ipos(pos[0],pos[1],pos[2]); std::copy(affine.get(),affine.get()+9,data.jacobian.begin()); if(cdm_dis.empty()) { (*mni.get())(ipos,Jpos); affine(Jpos); - image::matrix<3,3,float> M; - image::reg::bfnorm_get_jacobian(*mni.get(),ipos,M.begin()); + tipl::matrix<3,3,float> M; + tipl::reg::bfnorm_get_jacobian(*mni.get(),ipos,M.begin()); data.jacobian *= M; } else { - image::pixel_index<3> pos_index(ipos[0],ipos[1],ipos[2],cdm_dis.geometry()); + tipl::pixel_index<3> pos_index(ipos[0],ipos[1],ipos[2],cdm_dis.geometry()); if(!cdm_dis.geometry().is_valid(pos_index)) return; Jpos = pos; @@ -430,12 +430,12 @@ class DWINormalization : public BaseProcess affine(Jpos); if(!cdm_dis.geometry().is_edge(pos_index)) { - image::matrix<3,3,float> M; - image::jacobian_dis_at(cdm_dis,pos_index,M.begin()); + tipl::matrix<3,3,float> M; + tipl::jacobian_dis_at(cdm_dis,pos_index,M.begin()); data.jacobian *= M; } } - interpolate_dwi(voxel,data,Jpos,image::cubic_interpolation<3>()); + interpolate_dwi(voxel,data,Jpos,tipl::cubic_interpolation<3>()); if(voxel.output_jacobian) jdet[data.voxel_index] = std::abs(data.jacobian.det()*affine_volume_scale); @@ -484,9 +484,9 @@ class DWINormalization : public BaseProcess if(!cdm_dis.empty() && !voxel.t1w.empty()) { //convert T1W from FA template space to QSDR space - image::basic_image output_t1w(des_geo); - output_t1w.for_each_mt([&](float& v,const image::pixel_index<3>& index){ - image::vector<3,float> p(index); + tipl::image output_t1w(des_geo); + output_t1w.for_each_mt([&](float& v,const tipl::pixel_index<3>& index){ + tipl::vector<3,float> p(index); p *= resolution_ratio; if(voxel.t1w.geometry().is_valid(p)) v = voxel.t1w.at(p[0],p[1],p[2]); @@ -512,9 +512,9 @@ class EstimateZ0_MNI : public BaseProcess void run(Voxel& voxel, VoxelData& data) { // perform csf cross-subject normalization - if(voxel.csf_pos1 != image::vector<3,int>(0,0,0)) + if(voxel.csf_pos1 != tipl::vector<3,int>(0,0,0)) { - image::vector<3,int> cur_pos(image::pixel_index<3>(data.voxel_index,voxel.dim)); + tipl::vector<3,int> cur_pos(tipl::pixel_index<3>(data.voxel_index,voxel.dim)); if((cur_pos-voxel.csf_pos1).length() <= 1.0 || (cur_pos-voxel.csf_pos2).length() <= 1.0 || (cur_pos-voxel.csf_pos3).length() <= 1.0 || (cur_pos-voxel.csf_pos4).length() <= 1.0) { @@ -534,7 +534,7 @@ class EstimateZ0_MNI : public BaseProcess void end(Voxel& voxel,gz_mat_write&) { if(!samples.empty()) - voxel.z0 = image::median(samples.begin(),samples.end()); + voxel.z0 = tipl::median(samples.begin(),samples.end()); if(voxel.z0 == 0.0) voxel.z0 = 1.0; } diff --git a/libs/dsi/gqi_process.hpp b/libs/dsi/gqi_process.hpp index 1faec0038..905aa4add 100644 --- a/libs/dsi/gqi_process.hpp +++ b/libs/dsi/gqi_process.hpp @@ -12,7 +12,7 @@ double base_function(double theta); class GQI_Recon : public BaseProcess { public:// recorded for scheme balanced - std::vector > q_vectors_time; + std::vector > q_vectors_time; public: std::vector sinc_ql; public: @@ -36,12 +36,12 @@ class GQI_Recon : public BaseProcess // new_bvecs = (I+grad_dev) * bvecs; for(unsigned int i = 0; i < 9; ++i) data.jacobian[i] = voxel.grad_dev[i][data.voxel_index]; - image::mat::transpose(data.jacobian.begin(),image::dim<3,3>()); + tipl::mat::transpose(data.jacobian.begin(),tipl::dim<3,3>()); } std::vector sinc_ql_(data.odf.size()*data.space.size()); for (unsigned int j = 0,index = 0; j < data.odf.size(); ++j) { - image::vector<3,float> from(voxel.ti.vertices[j]); + tipl::vector<3,float> from(voxel.ti.vertices[j]); from.rotate(data.jacobian); from.normalize(); if(voxel.r2_weighted) @@ -52,12 +52,12 @@ class GQI_Recon : public BaseProcess sinc_ql_[index] = boost::math::sinc_pi(q_vectors_time[i]*from); } - image::mat::vector_product(&*sinc_ql_.begin(),&*data.space.begin(),&*data.odf.begin(), - image::dyndim(data.odf.size(),data.space.size())); + tipl::mat::vector_product(&*sinc_ql_.begin(),&*data.space.begin(),&*data.odf.begin(), + tipl::dyndim(data.odf.size(),data.space.size())); } else - image::mat::vector_product(&*sinc_ql.begin(),&*data.space.begin(),&*data.odf.begin(), - image::dyndim(data.odf.size(),data.space.size())); + tipl::mat::vector_product(&*sinc_ql.begin(),&*data.space.begin(),&*data.odf.begin(), + tipl::dyndim(data.odf.size(),data.space.size())); } }; @@ -87,7 +87,7 @@ class HGQI_Recon : public BaseProcess { int r2 = dx*dx+dy*dy+dz*dz; voxel.bvalues.push_back(r2*500); - image::vector<3> dir(dx,dy,dz); + tipl::vector<3> dir(dx,dy,dz); dir.normalize(); voxel.bvectors.push_back(dir); offset.push_back(dx + dy*voxel.dim.width() + dz*voxel.dim.plane_size()); @@ -106,7 +106,7 @@ class HGQI_Recon : public BaseProcess return; } hraw[data.voxel_index] = data.space[0]; - auto I = image::make_image(voxel.dwi_data[0],voxel.dim); + auto I = tipl::make_image(voxel.dwi_data[0],voxel.dim); data.space.resize(voxel.bvalues.size()); for(int i = 1;i < voxel.bvalues.size();++i) { @@ -121,8 +121,8 @@ class HGQI_Recon : public BaseProcess data.space[i] = std::fabs(data.space[0]-(I[pos1]+I[pos2])/2.0f)*scaling[i-1]; } - image::mat::vector_product(&*sinc_ql.begin(),&*data.space.begin(),&*data.odf.begin(), - image::dyndim(data.odf.size(),data.space.size())); + tipl::mat::vector_product(&*sinc_ql.begin(),&*data.space.begin(),&*data.odf.begin(), + tipl::dyndim(data.odf.size(),data.space.size())); } virtual void end(Voxel&,gz_mat_write& mat_writer) { @@ -135,7 +135,7 @@ class SchemeConverter : public BaseProcess { GQI_Recon from,to; std::vector piv; - std::vector > bvectors; + std::vector > bvectors; std::vector bvalues; std::vector > dwi; std::vector b0; @@ -156,7 +156,7 @@ class SchemeConverter : public BaseProcess if(values[i*4] == 0.0) continue; bvalues.push_back(voxel.param[1]); - bvectors.push_back(image::vector<3,float>(values[i*4+1],values[i*4+2],values[i*4+3])); + bvectors.push_back(tipl::vector<3,float>(values[i*4+1],values[i*4+2],values[i*4+3])); } } else @@ -185,15 +185,15 @@ class SchemeConverter : public BaseProcess b0.resize(voxel.dim.size()); Rt.resize(dwi.size()*dwi.size()); - image::mat::transpose(&*to.sinc_ql.begin(),&*Rt.begin(),image::dyndim(dwi.size(),dwi.size())); + tipl::mat::transpose(&*to.sinc_ql.begin(),&*Rt.begin(),tipl::dyndim(dwi.size(),dwi.size())); A.resize(dwi.size()*dwi.size()); piv.resize(dwi.size()); - image::mat::product_transpose(&*Rt.begin(),&*Rt.begin(),&*A.begin(), - image::dyndim(dwi.size(),dwi.size()),image::dyndim(dwi.size(),dwi.size())); + tipl::mat::product_transpose(&*Rt.begin(),&*Rt.begin(),&*A.begin(), + tipl::dyndim(dwi.size(),dwi.size()),tipl::dyndim(dwi.size(),dwi.size())); float max_value = *std::max_element(A.begin(),A.end()); for (unsigned int i = 0,index = 0; i < dwi.size(); ++i,index += dwi.size() + 1) A[index] += max_value*voxel.param[2]; - image::mat::lu_decomposition(A.begin(),piv.begin(),image::dyndim(dwi.size(),dwi.size())); + tipl::mat::lu_decomposition(A.begin(),piv.begin(),tipl::dyndim(dwi.size(),dwi.size())); total_negative_value = 0; total_value = 0; @@ -211,8 +211,8 @@ class SchemeConverter : public BaseProcess } from.run(voxel,data); std::vector hardi_data(dwi.size()),tmp(dwi.size()); - image::mat::vector_product(&*Rt.begin(),&*data.odf.begin(),&*tmp.begin(),image::dyndim(dwi.size(),dwi.size())); - image::mat::lu_solve(&*A.begin(),&*piv.begin(),&*tmp.begin(),&*hardi_data.begin(),image::dyndim(dwi.size(),dwi.size())); + tipl::mat::vector_product(&*Rt.begin(),&*data.odf.begin(),&*tmp.begin(),tipl::dyndim(dwi.size(),dwi.size())); + tipl::mat::lu_solve(&*A.begin(),&*piv.begin(),&*tmp.begin(),&*hardi_data.begin(),tipl::dyndim(dwi.size(),dwi.size())); for(unsigned int index = 0;index < dwi.size();++index) { if(hardi_data[index] < 0.0) @@ -366,9 +366,9 @@ class QSpaceSpectral : public BaseProcess for(unsigned int index = 0;index < max_length;++index) { dis[index][data.voxel_index] = - image::vec::dot(data.space.begin(),data.space.end(),disw[index].begin()); + tipl::vec::dot(data.space.begin(),data.space.end(),disw[index].begin()); cdf[index][data.voxel_index] = - image::vec::dot(data.space.begin(),data.space.end(),cdfw[index].begin()); + tipl::vec::dot(data.space.begin(),data.space.end(),cdfw[index].begin()); // make sure that cdf is increamental if(index && cdf[index][data.voxel_index] < cdf[index-1][data.voxel_index]) cdf[index][data.voxel_index] = cdf[index-1][data.voxel_index]; @@ -428,7 +428,7 @@ class RDI_Recon : public BaseProcess for(unsigned int index = 0;index < rdi.size();++index) { // force incremental - rdi_values[index] = std::max(last_value,image::vec::dot(rdi[index].begin(),rdi[index].end(),data.space.begin())); + rdi_values[index] = std::max(last_value,tipl::vec::dot(rdi[index].begin(),rdi[index].end(),data.space.begin())); last_value = rdi_values[index]; } data.rdi.swap(rdi_values); diff --git a/libs/dsi/image_model.cpp b/libs/dsi/image_model.cpp index 053bd82e5..5bf236c2b 100644 --- a/libs/dsi/image_model.cpp +++ b/libs/dsi/image_model.cpp @@ -7,7 +7,7 @@ void ImageModel::calculate_dwi_sum(void) { dwi_sum.clear(); dwi_sum.resize(voxel.dim); - image::par_for(dwi_sum.size(),[&](unsigned int pos) + tipl::par_for(dwi_sum.size(),[&](unsigned int pos) { for (unsigned int index = 0;index < src_dwi_data.size();++index) dwi_sum[pos] += src_dwi_data[index][pos]; @@ -20,11 +20,11 @@ void ImageModel::calculate_dwi_sum(void) min_value = dwi_sum[index]; - image::minus_constant(dwi_sum,min_value); - image::lower_threshold(dwi_sum,0.0f); - float t = image::segmentation::otsu_threshold(dwi_sum); - image::upper_threshold(dwi_sum,t*3.0f); - image::normalize(dwi_sum,1.0); + tipl::minus_constant(dwi_sum,min_value); + tipl::lower_threshold(dwi_sum,0.0f); + float t = tipl::segmentation::otsu_threshold(dwi_sum); + tipl::upper_threshold(dwi_sum,t*3.0f); + tipl::normalize(dwi_sum,1.0); } void ImageModel::remove(unsigned int index) @@ -40,7 +40,7 @@ typedef boost::mpl::vector< Dwi2Tensor > check_btable_process; std::pair evaluate_fib( - const image::geometry<3>& dim, + const tipl::geometry<3>& dim, const std::vector >& fib_fa, const std::vector >& fib_dir) { @@ -48,10 +48,10 @@ std::pair evaluate_fib( char dx[13] = {1,0,0,1,1,0, 1, 1, 0, 1,-1, 1, 1}; char dy[13] = {0,1,0,1,0,1,-1, 0, 1, 1, 1,-1, 1}; char dz[13] = {0,0,1,0,1,1, 0,-1,-1, 1, 1, 1,-1}; - std::vector > dis(13); + std::vector > dis(13); for(unsigned int i = 0;i < 13;++i) { - dis[i] = image::vector<3>(dx[i],dy[i],dz[i]); + dis[i] = tipl::vector<3>(dx[i],dy[i],dz[i]); dis[i].normalize(); } float otsu = *std::max_element(fib_fa[0].begin(),fib_fa[0].end())*0.1; @@ -59,7 +59,7 @@ std::pair evaluate_fib( for(unsigned int index = 0;index < connected.size();++index) connected[index].resize(dim.size()); float connection_count = 0; - for(image::pixel_index<3> index(dim);index < dim.size();++index) + for(tipl::pixel_index<3> index(dim);index < dim.size();++index) { if(fib_fa[0][index.index()] <= otsu) continue; @@ -71,18 +71,18 @@ std::pair evaluate_fib( for(unsigned int j = 0;j < 2;++j) for(unsigned int i = 0;i < 13;++i) { - image::vector<3,int> pos; - pos = j ? image::vector<3,int>(index[0] + dx[i],index[1] + dy[i],index[2] + dz[i]) - :image::vector<3,int>(index[0] - dx[i],index[1] - dy[i],index[2] - dz[i]); + tipl::vector<3,int> pos; + pos = j ? tipl::vector<3,int>(index[0] + dx[i],index[1] + dy[i],index[2] + dz[i]) + :tipl::vector<3,int>(index[0] - dx[i],index[1] - dy[i],index[2] - dz[i]); if(!dim.is_valid(pos)) continue; - image::pixel_index<3> other_index(pos[0],pos[1],pos[2],dim); + tipl::pixel_index<3> other_index(pos[0],pos[1],pos[2],dim); unsigned int other_index3 = other_index.index()+other_index.index()+other_index.index(); - if(std::abs(image::vector<3>(&fib_dir[fib1][index3])*dis[i]) <= 0.8665) + if(std::abs(tipl::vector<3>(&fib_dir[fib1][index3])*dis[i]) <= 0.8665) continue; for(unsigned char fib2 = 0;fib2 < num_fib;++fib2) if(fib_fa[fib2][other_index.index()] > otsu && - std::abs(image::vector<3>(&fib_dir[fib2][other_index3])*dis[i]) > 0.8665) + std::abs(tipl::vector<3>(&fib_dir[fib2][other_index3])*dis[i]) > 0.8665) { connected[fib1][index.index()] = 1; connected[fib2][other_index.index()] = 1; @@ -92,7 +92,7 @@ std::pair evaluate_fib( } } float no_connection_count = 0; - for(image::pixel_index<3> index(dim);index < dim.size();++index) + for(tipl::pixel_index<3> index(dim);index < dim.size();++index) { for(unsigned int i = 0;i < num_fib;++i) if(fib_fa[i][index.index()] > otsu && !connected[i][index.index()]) @@ -194,7 +194,7 @@ float ImageModel::quality_control_neighboring_dwi_corr(void) int min_j = 0; for(int j = i+1;j < src_bvalues.size();++j) { - image::vector<3> v1(src_bvectors[i]),v2(src_bvectors[j]); + tipl::vector<3> v1(src_bvectors[i]),v2(src_bvectors[j]); v1 *= std::sqrt(src_bvalues[i]); v2 *= std::sqrt(src_bvalues[j]); float dis = std::min((v1-v2).length(),(v1+v2).length()); @@ -208,7 +208,7 @@ float ImageModel::quality_control_neighboring_dwi_corr(void) } float self_cor = 0.0f; unsigned int count = 0; - image::par_for(corr_pairs.size(),[&](int index) + tipl::par_for(corr_pairs.size(),[&](int index) { int i1 = corr_pairs[index].first; int i2 = corr_pairs[index].second; @@ -221,7 +221,7 @@ float ImageModel::quality_control_neighboring_dwi_corr(void) I1.push_back(src_dwi_data[i1][i]); I2.push_back(src_dwi_data[i2][i]); } - self_cor += image::correlation(I1.begin(),I1.end(),I2.begin()); + self_cor += tipl::correlation(I1.begin(),I1.end(),I2.begin()); ++count; }); self_cor/= (float)count; @@ -298,52 +298,52 @@ void ImageModel::flip_dwi(unsigned char type) flip_b_table(type); else swap_b_table(type-3); - image::flip(dwi_sum,type); - image::flip(voxel.mask,type); + tipl::flip(dwi_sum,type); + tipl::flip(voxel.mask,type); for(unsigned int i = 0;i < voxel.grad_dev.size();++i) { - auto I = image::make_image((float*)&*(voxel.grad_dev[i].begin()),voxel.dim); - image::flip(I,type); + auto I = tipl::make_image((float*)&*(voxel.grad_dev[i].begin()),voxel.dim); + tipl::flip(I,type); } for (unsigned int index = 0;check_prog(index,src_dwi_data.size());++index) { - auto I = image::make_image((unsigned short*)src_dwi_data[index],voxel.dim); - image::flip(I,type); + auto I = tipl::make_image((unsigned short*)src_dwi_data[index],voxel.dim); + tipl::flip(I,type); } voxel.dim = dwi_sum.geometry(); } // used in eddy correction for each dwi -void ImageModel::rotate_one_dwi(unsigned int dwi_index,const image::transformation_matrix& affine) +void ImageModel::rotate_one_dwi(unsigned int dwi_index,const tipl::transformation_matrix& affine) { - image::basic_image tmp(voxel.dim); - auto I = image::make_image((unsigned short*)src_dwi_data[dwi_index],voxel.dim); - image::resample(I,tmp,affine,image::cubic); - image::lower_threshold(tmp,0); + tipl::image tmp(voxel.dim); + auto I = tipl::make_image((unsigned short*)src_dwi_data[dwi_index],voxel.dim); + tipl::resample(I,tmp,affine,tipl::cubic); + tipl::lower_threshold(tmp,0); std::copy(tmp.begin(),tmp.end(),I.begin()); // rotate b-table - image::matrix<3,3,float> iT = image::inverse(affine.get()); - image::vector<3> v; - image::vector_rotation(src_bvectors[dwi_index].begin(),v.begin(),iT,image::vdim<3>()); + tipl::matrix<3,3,float> iT = tipl::inverse(affine.get()); + tipl::vector<3> v; + tipl::vector_rotation(src_bvectors[dwi_index].begin(),v.begin(),iT,tipl::vdim<3>()); v.normalize(); src_bvectors[dwi_index] = v; } -void ImageModel::rotate(const image::basic_image& ref, - const image::transformation_matrix& affine, +void ImageModel::rotate(const tipl::image& ref, + const tipl::transformation_matrix& affine, bool super_resolution) { - image::geometry<3> new_geo = ref.geometry(); - std::vector > dwi(src_dwi_data.size()); - image::par_for2(src_dwi_data.size(),[&](unsigned int index,unsigned int id) + tipl::geometry<3> new_geo = ref.geometry(); + std::vector > dwi(src_dwi_data.size()); + tipl::par_for2(src_dwi_data.size(),[&](unsigned int index,unsigned int id) { if(!id) check_prog(index,src_dwi_data.size()); dwi[index].resize(new_geo); - auto I = image::make_image((unsigned short*)src_dwi_data[index],voxel.dim); + auto I = tipl::make_image((unsigned short*)src_dwi_data[index],voxel.dim); if(super_resolution) - image::resample_with_ref(I,ref,dwi[index],affine); + tipl::resample_with_ref(I,ref,dwi[index],affine); else - image::resample(I,dwi[index],affine,image::cubic); + tipl::resample(I,dwi[index],affine,tipl::cubic); src_dwi_data[index] = &(dwi[index][0]); }); check_prog(0,0); @@ -352,11 +352,11 @@ void ImageModel::rotate(const image::basic_image& ref, // rotate b-table if(has_image_rotation) { - image::matrix<3,3,float> T = image::inverse(affine.get()); + tipl::matrix<3,3,float> T = tipl::inverse(affine.get()); src_bvectors_rotate *= T; } else - src_bvectors_rotate = image::inverse(affine.get()); + src_bvectors_rotate = tipl::inverse(affine.get()); has_image_rotation = true; @@ -368,7 +368,7 @@ void ImageModel::rotate(const image::basic_image& ref, begin_prog("rotating grad_dev"); for(unsigned int index = 0;check_prog(index,voxel.dim.size());++index) { - image::matrix<3,3,float> grad_dev,G_invR; + tipl::matrix<3,3,float> grad_dev,G_invR; for(unsigned int i = 0; i < 9; ++i) grad_dev[i] = voxel.grad_dev[i][index]; G_invR = grad_dev*affine.get(); @@ -376,13 +376,13 @@ void ImageModel::rotate(const image::basic_image& ref, for(unsigned int i = 0; i < 9; ++i) voxel.grad_dev[i][index] = grad_dev[i]/det; } - std::vector > new_gra_dev(voxel.grad_dev.size()); + std::vector > new_gra_dev(voxel.grad_dev.size()); begin_prog("rotating grad_dev volume"); for (unsigned int index = 0;check_prog(index,new_gra_dev.size());++index) { new_gra_dev[index].resize(new_geo); - image::resample(voxel.grad_dev[index],new_gra_dev[index],affine,image::cubic); - voxel.grad_dev[index] = image::make_image((float*)&(new_gra_dev[index][0]),voxel.dim); + tipl::resample(voxel.grad_dev[index],new_gra_dev[index],affine,tipl::cubic); + voxel.grad_dev[index] = tipl::make_image((float*)&(new_gra_dev[index][0]),voxel.dim); } new_gra_dev.swap(voxel.new_grad_dev); } @@ -393,17 +393,17 @@ void ImageModel::rotate(const image::basic_image& ref, } void ImageModel::trim(void) { - image::geometry<3> range_min,range_max; - image::bounding_box(voxel.mask,range_min,range_max,0); + tipl::geometry<3> range_min,range_max; + tipl::bounding_box(voxel.mask,range_min,range_max,0); for (unsigned int index = 0;check_prog(index,src_dwi_data.size());++index) { - auto I = image::make_image((unsigned short*)src_dwi_data[index],voxel.dim); - image::basic_image I0 = I; - image::crop(I0,range_min,range_max); + auto I = tipl::make_image((unsigned short*)src_dwi_data[index],voxel.dim); + tipl::image I0 = I; + tipl::crop(I0,range_min,range_max); std::fill(I.begin(),I.end(),0); std::copy(I0.begin(),I0.end(),I.begin()); } - image::crop(voxel.mask,range_min,range_max); + tipl::crop(voxel.mask,range_min,range_max); voxel.dim = voxel.mask.geometry(); calculate_dwi_sum(); voxel.calculate_mask(dwi_sum); @@ -418,11 +418,11 @@ float interpo_pos(float v1,float v2,float u1,float u2) template void get_distortion_map(const image_type& v1, const image_type& v2, - image::basic_image& dis_map) + tipl::image& dis_map) { int h = v1.height(),w = v1.width(),hw = v1.plane_size(); dis_map.resize(v1.geometry()); - image::par_for(v1.depth(),[&](int z) + tipl::par_for(v1.depth(),[&](int z) { for(int x = 0;x < w;++x) { @@ -436,7 +436,7 @@ void get_distortion_map(const image_type& v1, } //if(cdf_y1.back() == 0.0 || cdf_y2.back() == 0.0) // continue; - image::multiply_constant(cdf_y2,cdf_y1.back()/cdf_y2.back()); + tipl::multiply_constant(cdf_y2,cdf_y1.back()/cdf_y2.back()); for(int y = 0,pos = x + z*hw;y < h;++y,pos += w) { @@ -513,12 +513,12 @@ void get_distortion_map(const image_type& v1, template void apply_distortion_map(const image_type& v1, const image_type& v2, - const image::basic_image& dis_map, + const tipl::image& dis_map, out_type& dwi) { int h = v1.height(),w = v1.width(),hw = v1.plane_size(); dwi.resize(v1.geometry()); - image::par_for(v1.depth(),[&](int z) + tipl::par_for(v1.depth(),[&](int z) { for(int x = 0;x < w;++x) { @@ -529,14 +529,14 @@ void apply_distortion_map(const image_type& v1, cdf_y2[y] = v2[pos] + (y ? cdf_y2[y-1]:0); } - auto I1 = image::make_image(&cdf_y1[0],image::geometry<1>(cdf_y1.size())); - auto I2 = image::make_image(&cdf_y2[0],image::geometry<1>(cdf_y2.size())); + auto I1 = tipl::make_image(&cdf_y1[0],tipl::geometry<1>(cdf_y1.size())); + auto I2 = tipl::make_image(&cdf_y2[0],tipl::geometry<1>(cdf_y2.size())); for(int y = 0,pos = x + z*hw;y < h;++y,pos += w) { float d = dis_map[pos]; float y1 = y-d; float y2 = y+d; - cdf[y] = image::estimate(I1,y1)+image::estimate(I2,y2); + cdf[y] = tipl::estimate(I1,y1)+tipl::estimate(I2,y2); cdf[y] *= 0.5; } for(int y = 1,pos = x + z*hw+w;y < h;++y,pos += w) @@ -551,49 +551,49 @@ void apply_distortion_map(const image_type& v1, void ImageModel::distortion_correction(const ImageModel& rhs) { - image::basic_image v1,v2; + tipl::image v1,v2; v1 = dwi_sum; v2 = rhs.dwi_sum; bool swap_xy = false; { - image::basic_image px1,px2,py1,py2; - image::project_x(v1,px1); - image::project_x(v2,px2); - image::project_y(v1,py1); - image::project_y(v2,py2); - float cx = image::correlation(px1.begin(),px1.end(),px2.begin()); - float cy = image::correlation(py1.begin(),py1.end(),py2.begin()); + tipl::image px1,px2,py1,py2; + tipl::project_x(v1,px1); + tipl::project_x(v2,px2); + tipl::project_y(v1,py1); + tipl::project_y(v2,py2); + float cx = tipl::correlation(px1.begin(),px1.end(),px2.begin()); + float cy = tipl::correlation(py1.begin(),py1.end(),py2.begin()); if(cx > cy) { - image::swap_xy(v1); - image::swap_xy(v2); + tipl::swap_xy(v1); + tipl::swap_xy(v2); swap_xy = true; } } - image::basic_image dis_map; - image::filter::gaussian(v1); - image::filter::gaussian(v2); + tipl::image dis_map; + tipl::filter::gaussian(v1); + tipl::filter::gaussian(v2); get_distortion_map(v1,v2,dis_map); //dwi_sum = dis_map; //return; - std::vector > dwi(src_dwi_data.size()); + std::vector > dwi(src_dwi_data.size()); for(int i = 0;i < src_dwi_data.size();++i) { - v1 = image::make_image(src_dwi_data[i],voxel.dim); - v2 = image::make_image(rhs.src_dwi_data[i],rhs.voxel.dim); + v1 = tipl::make_image(src_dwi_data[i],voxel.dim); + v2 = tipl::make_image(rhs.src_dwi_data[i],rhs.voxel.dim); if(swap_xy) { - image::swap_xy(v1); - image::swap_xy(v2); + tipl::swap_xy(v1); + tipl::swap_xy(v2); } apply_distortion_map(v1,v2,dis_map,dwi[i]); if(swap_xy) - image::swap_xy(dwi[i]); + tipl::swap_xy(dwi[i]); } @@ -798,12 +798,12 @@ bool ImageModel::load_from_file(const char* dwi_file_name) if(mat_reader.read("grad_dev",row,col,grad_dev) && row*col == voxel.dim.size()*9) { for(unsigned int index = 0;index < 9;index++) - voxel.grad_dev.push_back(image::make_image((float*)grad_dev+index*voxel.dim.size(),voxel.dim)); + voxel.grad_dev.push_back(tipl::make_image((float*)grad_dev+index*voxel.dim.size(),voxel.dim)); if(std::fabs(voxel.grad_dev[0][0])+std::fabs(voxel.grad_dev[4][0])+std::fabs(voxel.grad_dev[8][0]) < 1.0) { - image::add_constant(voxel.grad_dev[0].begin(),voxel.grad_dev[0].end(),1.0); - image::add_constant(voxel.grad_dev[4].begin(),voxel.grad_dev[4].end(),1.0); - image::add_constant(voxel.grad_dev[8].begin(),voxel.grad_dev[8].end(),1.0); + tipl::add_constant(voxel.grad_dev[0].begin(),voxel.grad_dev[0].end(),1.0); + tipl::add_constant(voxel.grad_dev[4].begin(),voxel.grad_dev[4].end(),1.0); + tipl::add_constant(voxel.grad_dev[8].begin(),voxel.grad_dev[8].end(),1.0); } } @@ -867,17 +867,17 @@ bool ImageModel::save_to_nii(const char* nifti_file_name) const std::copy(voxel.vs.begin(),voxel.vs.end(),vs); vs[3] = 1.0; header.set_voxel_size(vs); - image::geometry<4> nifti_dim; + tipl::geometry<4> nifti_dim; std::copy(voxel.dim.begin(),voxel.dim.end(),nifti_dim.begin()); nifti_dim[3] = src_bvalues.size(); - image::basic_image buffer(nifti_dim); + tipl::image buffer(nifti_dim); for(unsigned int index = 0;index < src_bvalues.size();++index) { std::copy(src_dwi_data[index], src_dwi_data[index]+voxel.dim.size(), buffer.begin() + (size_t)index*voxel.dim.size()); } - image::flip_xy(buffer); + tipl::flip_xy(buffer); header << buffer; return header.save_to_file(nifti_file_name); } @@ -885,8 +885,8 @@ bool ImageModel::save_b0_to_nii(const char* nifti_file_name) const { gz_nifti header; header.set_voxel_size(voxel.vs); - image::basic_image buffer(src_dwi_data[0],voxel.dim); - image::flip_xy(buffer); + tipl::image buffer(src_dwi_data[0],voxel.dim); + tipl::flip_xy(buffer); header << buffer; return header.save_to_file(nifti_file_name); } diff --git a/libs/dsi/image_model.hpp b/libs/dsi/image_model.hpp index 69fce08f5..acb8031e3 100644 --- a/libs/dsi/image_model.hpp +++ b/libs/dsi/image_model.hpp @@ -1,12 +1,12 @@ #ifndef IMAGE_MODEL_HPP #define IMAGE_MODEL_HPP -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "basic_voxel.hpp" struct distortion_map{ const float pi_2 = 3.14159265358979323846f/2.0f; - image::basic_image i1,i2; - image::basic_image w1,w2; - void operator=(const image::basic_image& d) + tipl::image i1,i2; + tipl::image w1,w2; + void operator=(const tipl::image& d) { int n = d.width(); i1.resize(d.geometry()); @@ -14,7 +14,7 @@ struct distortion_map{ w1.resize(d.geometry()); w2.resize(d.geometry()); int max_n = n-1.001f; - image::par_for(d.height()*d.depth(),[&](int pos) + tipl::par_for(d.height()*d.depth(),[&](int pos) { pos *= n; int* i1p = &i1[0]+pos; @@ -41,16 +41,16 @@ struct distortion_map{ } }); } - void calculate_displaced(image::basic_image& j1, - image::basic_image& j2, - const image::basic_image& v) + void calculate_displaced(tipl::image& j1, + tipl::image& j2, + const tipl::image& v) { int n = v.width(); j1.clear(); j2.clear(); j1.resize(v.geometry()); j2.resize(v.geometry()); - image::par_for(v.height()*v.depth(),[&](int pos) + tipl::par_for(v.height()*v.depth(),[&](int pos) { pos *= n; const int* i1p = &i1[0]+pos; @@ -78,16 +78,16 @@ struct distortion_map{ } - void calculate_original(const image::basic_image& v1, - const image::basic_image& v2, - image::basic_image& v) + void calculate_original(const tipl::image& v1, + const tipl::image& v2, + tipl::image& v) { int n = v1.width(); int n2 = n + n; int block2 = n*n; v.clear(); v.resize(v1.geometry()); - image::par_for(v1.height()*v1.depth(),[&](int pos) + tipl::par_for(v1.height()*v1.depth(),[&](int pos) { pos *= n; const int* i1p = &i1[0]+pos; @@ -110,17 +110,17 @@ struct distortion_map{ std::vector y(n2); std::copy(v1p,v1p+n,y.begin()); std::copy(v2p,v2p+n,y.begin()+n); - image::mat::pseudo_inverse_solve(&M[0],&y[0],&v[0]+pos,image::dyndim(n,n2)); + tipl::mat::pseudo_inverse_solve(&M[0],&y[0],&v[0]+pos,tipl::dyndim(n,n2)); }); } - void sample_gradient(const image::basic_image& g1, - const image::basic_image& g2, - image::basic_image& new_g) + void sample_gradient(const tipl::image& g1, + const tipl::image& g2, + tipl::image& new_g) { int n = g1.width(); new_g.clear(); new_g.resize(g1.geometry()); - image::par_for(g1.height()*g1.depth(),[&](int pos) + tipl::par_for(g1.height()*g1.depth(),[&](int pos) { pos *= n; const int* i1p = &i1[0]+pos; @@ -158,21 +158,21 @@ template void distortion_estimate(const image_type& v1,const image_type& v2, image_type& d) { - image::geometry<3> geo(v1.geometry()); + tipl::geometry<3> geo(v1.geometry()); if(geo.width() > 8) { image_type vv1,vv2; - image::downsample_with_padding(v1,vv1); - image::downsample_with_padding(v2,vv2); + tipl::downsample_with_padding(v1,vv1); + tipl::downsample_with_padding(v2,vv2); distortion_estimate(vv1,vv2,d); - image::upsample_with_padding(d,d,geo); + tipl::upsample_with_padding(d,d,geo); d *= 2.0f; - image::filter::gaussian(d); + tipl::filter::gaussian(d); } else d.resize(geo); int n = v1.width(); - image::basic_image old_d(geo),v(geo),new_g(geo),j1(geo),j2(geo); + tipl::image old_d(geo),v(geo),new_g(geo),j1(geo),j2(geo); float sum_dif = 0.0f; float s = 0.5f; distortion_map m; @@ -184,8 +184,8 @@ void distortion_estimate(const image_type& v1,const image_type& v2, // calculate the displaced image j1 j2 using v and d m.calculate_displaced(j1,j2,v); // calculate difference between current and estimated - image::minus(j1,v1); - image::minus(j2,v2); + tipl::minus(j1,v1); + tipl::minus(j2,v2); float sum = 0.0f; for(int i = 0;i < j1.size();++i) @@ -205,18 +205,18 @@ void distortion_estimate(const image_type& v1,const image_type& v2, else { sum_dif = sum; - image::basic_image g1(geo),g2(geo); - image::gradient(j1.begin(),j1.end(),g1.begin(),2,1); - image::gradient(j2.begin(),j2.end(),g2.begin(),2,1); + tipl::image g1(geo),g2(geo); + tipl::gradient(j1.begin(),j1.end(),g1.begin(),2,1); + tipl::gradient(j2.begin(),j2.end(),g2.begin(),2,1); for(int i = 0;i < g1.size();++i) g1[i] = -g1[i]; // sample gradient m.sample_gradient(g1,g2,new_g); old_d = d; } - image::multiply_constant(new_g,s); - image::add(d,new_g); - image::lower_threshold(d,0.0f); + tipl::multiply_constant(new_g,s); + tipl::add(d,new_g); + tipl::lower_threshold(d,0.0f); for(int i = 0,pos = 0;i < geo.depth()*geo.height();++i,pos+=n) { d[pos] = 0.0f; @@ -229,7 +229,7 @@ void distortion_estimate(const image_type& v1,const image_type& v2, struct ImageModel { public: - std::vector > new_dwi;//used in rotated volume + std::vector > new_dwi;//used in rotated volume public: Voxel voxel; @@ -237,13 +237,13 @@ struct ImageModel gz_mat_read mat_reader; public: // untouched b-table and DWI from SRC file (the ones in Voxel class will be sorted - std::vector > src_bvectors; + std::vector > src_bvectors; bool has_image_rotation = false; - image::matrix<3,3,float> src_bvectors_rotate; + tipl::matrix<3,3,float> src_bvectors_rotate; public: std::vector src_bvalues; std::vector src_dwi_data; - image::basic_image dwi_sum; + tipl::image dwi_sum; std::shared_ptr study_src; void calculate_dwi_sum(void); void remove(unsigned int index); @@ -263,9 +263,9 @@ struct ImageModel void flip_b_table(unsigned char dim); void swap_b_table(unsigned char dim); void flip_dwi(unsigned char type); - void rotate_one_dwi(unsigned int dwi_index,const image::transformation_matrix& affine); - void rotate(const image::basic_image& ref, - const image::transformation_matrix& affine, + void rotate_one_dwi(unsigned int dwi_index,const tipl::transformation_matrix& affine); + void rotate(const tipl::image& ref, + const tipl::transformation_matrix& affine, bool super_resolution = false); void trim(void); void distortion_correction(const ImageModel& rhs); diff --git a/libs/dsi/layout.hpp b/libs/dsi/layout.hpp index 1133b366e..482b66bc6 100644 --- a/libs/dsi/layout.hpp +++ b/libs/dsi/layout.hpp @@ -22,8 +22,8 @@ class Layout } private: tessellated_icosahedron ti; - image::geometry<3> dim; - std::vector > bvectors; + tipl::geometry<3> dim; + std::vector > bvectors; std::vector bvalues; private: @@ -56,7 +56,7 @@ class Layout for (unsigned int index = 0; index + 3 < data.size(); index += 4) { - image::vector<3,float> v(data[index+1],data[index+2],data[index+3]); + tipl::vector<3,float> v(data[index+1],data[index+2],data[index+3]); v.normalize(); bvalues.push_back(data[index]); bvectors.push_back(v); @@ -91,7 +91,7 @@ class Layout findex[1].resize(total_size); - unsigned int main_fiber_index = ti.discretize(image::vector<3>(1.0,0.0,0.0)); + unsigned int main_fiber_index = ti.discretize(tipl::vector<3>(1.0,0.0,0.0)); std::fill(models.begin(),models.end(),(MixGaussianModel*)0); begin_prog("creating layout"); @@ -128,7 +128,7 @@ class Layout fa[1][index] = fiber_fraction*(1.0-xf); gfa[index] = fa_value; findex[0][index] = main_fiber_index; - findex[1][index] = ti.discretize(image::vector<3>(std::cos(angle),std::sin(angle),0.0)); + findex[1][index] = ti.discretize(tipl::vector<3>(std::cos(angle),std::sin(angle),0.0)); } } } @@ -162,7 +162,7 @@ class Layout fa[1][index] = fiber_fraction/2.0; gfa[index] = fa_value; findex[0][index] = main_fiber_index; - findex[1][index] = ti.discretize(image::vector<3>(std::cos(inner_angle),std::sin(inner_angle),0.0)); + findex[1][index] = ti.discretize(tipl::vector<3>(std::cos(inner_angle),std::sin(inner_angle),0.0)); } } } diff --git a/libs/dsi/mix_gaussian_model.hpp b/libs/dsi/mix_gaussian_model.hpp index 1537e8a6a..d2597f315 100644 --- a/libs/dsi/mix_gaussian_model.hpp +++ b/libs/dsi/mix_gaussian_model.hpp @@ -1,9 +1,9 @@ #ifndef MIX_GAUSSIAN_MODEL_HPP #define MIX_GAUSSIAN_MODEL_HPP #include -#include +#include struct basic_sigal_model{ - virtual float operator()(float b,const image::vector<3,float>& g_dir) const = 0; + virtual float operator()(float b,const tipl::vector<3,float>& g_dir) const = 0; }; @@ -11,12 +11,12 @@ class GaussianModel { private: float lambda1,lambda2; - image::vector<3,float> axis; + tipl::vector<3,float> axis; public: - GaussianModel(float l1,float l2,const image::vector<3,float>& axis_): + GaussianModel(float l1,float l2,const tipl::vector<3,float>& axis_): lambda1(l1),lambda2(l2),axis(axis_) {} - float operator()(float b,const image::vector<3,float>& g_dir) const + float operator()(float b,const tipl::vector<3,float>& g_dir) const { float cos2 = axis*g_dir; cos2*= cos2; @@ -34,14 +34,14 @@ class MixGaussianModel: public basic_sigal_model float iso_l; public: MixGaussianModel(float l1,float l2,float l0,float angle,float fraction1,float fraction2): - g1(l1,l2,image::vector<3,float>(1.0,0.0,0.0)), - g2(l1,l2,image::vector<3,float>(std::cos(angle),std::sin(angle),0.0)), + g1(l1,l2,tipl::vector<3,float>(1.0,0.0,0.0)), + g2(l1,l2,tipl::vector<3,float>(std::cos(angle),std::sin(angle),0.0)), f1(fraction1), f2(fraction2), f3(1.0-fraction1-fraction2), iso_l(l0) {} - float operator()(float b,const image::vector<3,float>& g_dir) const + float operator()(float b,const tipl::vector<3,float>& g_dir) const { return f1*g1(b,g_dir)+f2*g2(b,g_dir)+f3*std::exp(-b*iso_l); } @@ -64,11 +64,11 @@ class GaussianDispersion: public basic_sigal_model for(unsigned int fib = 0;fib <= 999;++fib) { float angle = -dis_angle/2.0 + dis_angle*((float)fib)/999.0; - g.push_back(GaussianModel(l1,l2,image::vector<3,float>(std::cos(angle),std::sin(angle),0.0))); + g.push_back(GaussianModel(l1,l2,tipl::vector<3,float>(std::cos(angle),std::sin(angle),0.0))); } } - float operator()(float b,const image::vector<3,float>& g_dir) const + float operator()(float b,const tipl::vector<3,float>& g_dir) const { float sum_signal = 0.0f; for(unsigned int index = 0;index < g.size();++index) diff --git a/libs/dsi/odf_decomposition.hpp b/libs/dsi/odf_decomposition.hpp index 8a43670ff..939f937f8 100644 --- a/libs/dsi/odf_decomposition.hpp +++ b/libs/dsi/odf_decomposition.hpp @@ -4,7 +4,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "basic_process.hpp" #include "basic_voxel.hpp" @@ -50,10 +50,10 @@ struct ODFDecomposition : public BaseProcess template void normalize_vector(iterator_type from,iterator_type to) { - image::minus_constant(from,to,std::accumulate(from,to,0.0)/((float)(to-from))); - float length = image::vec::norm2(from,to); + tipl::minus_constant(from,to,std::accumulate(from,to,0.0)/((float)(to-from))); + float length = tipl::vec::norm2(from,to); if(length+1.0 != 1.0) - image::divide_constant(from,to,length); + tipl::divide_constant(from,to,length); } void estimate_Rt(Voxel& voxel) @@ -76,7 +76,7 @@ struct ODFDecomposition : public BaseProcess for (unsigned int i = 0; i < half_odf_size; ++i) { normalize_vector(Rt.begin()+i*half_odf_size,Rt.begin()+(i+1)*half_odf_size); - image::divide_constant(oRt.begin()+i*half_odf_size,oRt.begin()+(i+1)*half_odf_size, + tipl::divide_constant(oRt.begin()+i*half_odf_size,oRt.begin()+(i+1)*half_odf_size, *std::max_element(oRt.begin()+i*half_odf_size,oRt.begin()+(i+1)*half_odf_size)); } @@ -116,8 +116,8 @@ struct ODFDecomposition : public BaseProcess { // calculate the correlation with each SFO - image::mat::vector_product(&*x.begin(),&*residual.begin(),&*tmp.begin(), - image::dyndim(y_dim,y_dim)); + tipl::mat::vector_product(&*x.begin(),&*residual.begin(),&*tmp.begin(), + tipl::dyndim(y_dim,y_dim)); // get the most correlated orientation int dir = std::max_element(tmp.begin(),tmp.end())-tmp.begin(); float corr = tmp[dir]; @@ -148,12 +148,12 @@ struct ODFDecomposition : public BaseProcess } } w[dir] += min_step_value; - image::vec::axpy(residual.begin(),residual.end(),-min_step_value,xi); + tipl::vec::axpy(residual.begin(),residual.end(),-min_step_value,xi); } else { w[dir] += corr*step_size; - image::vec::axpy(residual.begin(),residual.end(),-corr*step_size,xi); + tipl::vec::axpy(residual.begin(),residual.end(),-corr*step_size,xi); } } } @@ -191,7 +191,7 @@ struct ODFDecomposition : public BaseProcess is_neighbor[i3][i2] = 1; } // scale the free water diffusion to 1 - image::divide_constant(voxel.free_water_diffusion,voxel.reponse_function_scaling); + tipl::divide_constant(voxel.free_water_diffusion,voxel.reponse_function_scaling); estimate_Rt(voxel); } @@ -218,7 +218,7 @@ struct ODFDecomposition : public BaseProcess if(dir_list.empty()) { results.resize(1); - results[0] = image::mean(old_odf.begin(),old_odf.end()); + results[0] = tipl::mean(old_odf.begin(),old_odf.end()); has_isotropic = 1; break; } @@ -237,7 +237,7 @@ struct ODFDecomposition : public BaseProcess } results.resize(dir_list.size()+has_isotropic); - image::mat::pseudo_inverse_solve(&*RRt.begin(),&*old_odf.begin(),&*results.begin(),image::dyndim(results.size(),half_odf_size)); + tipl::mat::pseudo_inverse_solve(&*RRt.begin(),&*old_odf.begin(),&*results.begin(),tipl::dyndim(results.size(),half_odf_size)); // drop negative int min_index = std::min_element(results.begin()+has_isotropic,results.end())-results.begin(); @@ -291,7 +291,7 @@ struct ODFDecomposition : public BaseProcess if (!voxel.odf_decomposition) return; if(max_iso + 1.0 != 1.0) - image::divide_constant(fiber_ratio,max_iso); + tipl::divide_constant(fiber_ratio,max_iso); mat_writer.write("fiber_ratio",&*fiber_ratio.begin(),1,fiber_ratio.size()); } diff --git a/libs/dsi/odf_deconvolusion.hpp b/libs/dsi/odf_deconvolusion.hpp index b20e6e4d5..9e6fe6a69 100644 --- a/libs/dsi/odf_deconvolusion.hpp +++ b/libs/dsi/odf_deconvolusion.hpp @@ -106,14 +106,14 @@ class ODFDeconvolusion : public BaseProcess void deconvolution(std::vector& odf) { std::vector tmp(half_odf_size); - image::mat::vector_product(&*Rt.begin(),&*odf.begin(),&*tmp.begin(),image::dyndim(half_odf_size,half_odf_size)); - image::mat::lu_solve(&*A.begin(),&*pv.begin(),&*tmp.begin(),&*odf.begin(),image::dyndim(half_odf_size,half_odf_size)); + tipl::mat::vector_product(&*Rt.begin(),&*odf.begin(),&*tmp.begin(),tipl::dyndim(half_odf_size,half_odf_size)); + tipl::mat::lu_solve(&*A.begin(),&*pv.begin(),&*tmp.begin(),&*odf.begin(),tipl::dyndim(half_odf_size,half_odf_size)); } void remove_isotropic(std::vector& odf) { float min_value = *std::min_element(odf.begin(),odf.end()); if (min_value > 0) - image::minus_constant(odf,min_value); + tipl::minus_constant(odf,min_value); else for (unsigned int index = 0; index < half_odf_size; ++index) if (odf[index] < 0.0) @@ -141,7 +141,7 @@ class ODFDeconvolusion : public BaseProcess deconvolution(free_water_odf); remove_isotropic(free_water_odf); - specificity_error_percentage = image::mean(free_water_odf.begin(),free_water_odf.end())/ + specificity_error_percentage = tipl::mean(free_water_odf.begin(),free_water_odf.end())/ (*std::max_element(single_fiber_odf.begin(),single_fiber_odf.end())); @@ -154,11 +154,11 @@ class ODFDeconvolusion : public BaseProcess if (!voxel.odf_deconvolusion) return; voxel.recon_report << "Diffusion ODF deconvolution (Yeh et al., Neuroimage, 2011) was conducted using a regularization parameter of " << voxel.param[2]; - image::divide_constant(voxel.response_function, + tipl::divide_constant(voxel.response_function, (std::accumulate(voxel.response_function.begin(),voxel.response_function.end(),0.0) /((double)voxel.response_function.size()))); // scale the free water diffusion to 1 - image::divide_constant(voxel.free_water_diffusion,voxel.reponse_function_scaling); + tipl::divide_constant(voxel.free_water_diffusion,voxel.reponse_function_scaling); half_odf_size = voxel.ti.half_vertices_count; @@ -166,13 +166,13 @@ class ODFDeconvolusion : public BaseProcess A.resize(half_odf_size*half_odf_size); pv.resize(half_odf_size); - image::mat::product_transpose(Rt.begin(),Rt.begin(),A.begin(), - image::dyndim(half_odf_size,half_odf_size),image::dyndim(half_odf_size,half_odf_size)); + tipl::mat::product_transpose(Rt.begin(),Rt.begin(),A.begin(), + tipl::dyndim(half_odf_size,half_odf_size),tipl::dyndim(half_odf_size,half_odf_size)); AA = A; for (unsigned int i = 0,index = 0; i < half_odf_size; ++i,index += half_odf_size + 1) A[index] += voxel.param[2]; - image::mat::lu_decomposition(A.begin(),pv.begin(),image::dyndim(half_odf_size,half_odf_size)); + tipl::mat::lu_decomposition(A.begin(),pv.begin(),tipl::dyndim(half_odf_size,half_odf_size)); get_error_percentage(voxel); @@ -183,7 +183,7 @@ class ODFDeconvolusion : public BaseProcess // scale the dODF using the reference to free water diffusion if (!voxel.odf_deconvolusion) return; - image::divide_constant(data.odf,voxel.reponse_function_scaling); + tipl::divide_constant(data.odf,voxel.reponse_function_scaling); deconvolution(data.odf); remove_isotropic(data.odf); } diff --git a/libs/dsi/odf_process.hpp b/libs/dsi/odf_process.hpp index 64d5ebeee..7954af4bd 100644 --- a/libs/dsi/odf_process.hpp +++ b/libs/dsi/odf_process.hpp @@ -45,8 +45,8 @@ class CalculateDifference : public BaseProcess{ } virtual void run(Voxel& voxel, VoxelData& data) { - image::minus_constant(data.rdi,*std::min_element(data.rdi.begin(),data.rdi.end())); - image::minus_constant(data.odf,*std::min_element(data.odf.begin(),data.odf.end())); + tipl::minus_constant(data.rdi,*std::min_element(data.rdi.begin(),data.rdi.end())); + tipl::minus_constant(data.odf,*std::min_element(data.odf.begin(),data.odf.end())); float qa = *std::max_element(data.rdi.begin(),data.rdi.end()); if(qa > voxel.z0) @@ -55,14 +55,14 @@ class CalculateDifference : public BaseProcess{ // data.odf : study ODF if(!voxel.ddi_type) // study decreased connectivity std::swap(data.rdi,data.odf); - image::minus(data.odf.begin(),data.odf.end(),data.rdi.begin()); - image::lower_threshold(data.odf,0); + tipl::minus(data.odf.begin(),data.odf.end(),data.rdi.begin()); + tipl::lower_threshold(data.odf,0); nqa[data.voxel_index] = qa; } virtual void end(Voxel& voxel,gz_mat_write& mat_writer) { if(voxel.z0 != 0.0f) - image::divide_constant(nqa,voxel.z0); + tipl::divide_constant(nqa,voxel.z0); mat_writer.write("base_nqa",&*nqa.begin(),1,nqa.size()); } }; @@ -75,7 +75,7 @@ class BalanceScheme : public BaseProcess{ unsigned int old_q_count; private: Voxel* stored_voxel; - std::vector > old_bvectors; + std::vector > old_bvectors; std::vector old_bvalues; public: BalanceScheme(void):stored_voxel(0){} @@ -92,7 +92,7 @@ class BalanceScheme : public BaseProcess{ tessellated_icosahedron new_dir; new_dir.init(6); - std::vector > new_bvectors; + std::vector > new_bvectors; std::vector new_bvalues; // if b0 @@ -131,7 +131,7 @@ class BalanceScheme : public BaseProcess{ averaged_angle /= num; //calculate averaged b_value - double avg_b = image::mean(voxel.bvalues.begin()+from,voxel.bvalues.begin()+to); + double avg_b = tipl::mean(voxel.bvalues.begin()+from,voxel.bvalues.begin()+to); unsigned int trans_old_size = trans.size(); trans.resize(trans.size() + new_dir.half_vertices_count*b_count); for(unsigned int i = 0; i < new_dir.half_vertices_count;++i) @@ -146,7 +146,7 @@ class BalanceScheme : public BaseProcess{ effective_b += t[j]*voxel.bvalues[j]; } double sum_t = std::accumulate(t.begin(),t.end(),0.0); - image::multiply_constant(t,avg_b/1000.0/sum_t); + tipl::multiply_constant(t,avg_b/1000.0/sum_t); std::copy(t.begin(),t.end(),trans.begin() + trans_old_size + i * b_count); new_bvalues.push_back(effective_b/sum_t); new_bvectors.push_back(new_dir.vertices[i]); @@ -176,7 +176,7 @@ class BalanceScheme : public BaseProcess{ } std::vector new_data(new_q_count); data.space.swap(new_data); - image::mat::vector_product(trans.begin(),new_data.begin(),data.space.begin(),image::dyndim(new_q_count,old_q_count)); + tipl::mat::vector_product(trans.begin(),new_data.begin(),data.space.begin(),tipl::dyndim(new_q_count,old_q_count)); } }; @@ -272,7 +272,7 @@ struct OutputODF : public BaseProcess for (unsigned int index = 0;index < odf_data.size();++index) { if (!voxel.odf_deconvolusion) - image::divide_constant(odf_data[index],voxel.z0); + tipl::divide_constant(odf_data[index],voxel.z0); std::ostringstream out; out << "odf" << index; mat_writer.write(out.str().c_str(),&*odf_data[index].begin(), @@ -413,9 +413,9 @@ struct SaveMetrics : public BaseProcess dwi[i] = water_b0*std::exp(-voxel.bvalues[i]*0.003f); // free water diffusivity std::vector sinc_ql; voxel.calculate_sinc_ql(sinc_ql); - image::mat::vector_product(&*sinc_ql.begin(),&*dwi.begin(),&*odf.begin(), - image::dyndim(odf.size(),dwi.size())); - z0 = image::mean(odf.begin(),odf.end()); + tipl::mat::vector_product(&*sinc_ql.begin(),&*dwi.begin(),&*odf.begin(), + tipl::dyndim(odf.size(),dwi.size())); + z0 = tipl::mean(odf.begin(),odf.end()); } voxel.z0 = 0.0; } @@ -445,7 +445,7 @@ struct SaveMetrics : public BaseProcess for (unsigned int index = 0;index < voxel.max_fiber_number;++index) { - image::divide_constant(fa[index],voxel.z0); + tipl::divide_constant(fa[index],voxel.z0); std::ostringstream out; out << index; std::string num = out.str(); @@ -455,7 +455,7 @@ struct SaveMetrics : public BaseProcess mat_writer.write(fa_str.c_str(),&*fa[index].begin(),1,fa[index].size()); } - image::divide_constant(iso,voxel.z0); + tipl::divide_constant(iso,voxel.z0); mat_writer.write("iso",&*iso.begin(),1,iso.size()); @@ -468,7 +468,7 @@ struct SaveMetrics : public BaseProcess if(max_qa != 0.0) for (unsigned int index = 0;index < voxel.max_fiber_number;++index) { - image::divide_constant(fa[index],max_qa); + tipl::divide_constant(fa[index],max_qa); std::ostringstream out; out << index; std::string num = out.str(); @@ -482,7 +482,7 @@ struct SaveMetrics : public BaseProcess if(voxel.output_rdi) { for(unsigned int i = 0;i < rdi.size();++i) - image::divide_constant(rdi[i],voxel.z0); + tipl::divide_constant(rdi[i],voxel.z0); float L = 0.2f; for(unsigned int i = 0;i < rdi.size();++i,L += 0.2f) { diff --git a/libs/dsi/qbi_process.hpp b/libs/dsi/qbi_process.hpp index 294e25dfd..945c31303 100644 --- a/libs/dsi/qbi_process.hpp +++ b/libs/dsi/qbi_process.hpp @@ -2,7 +2,7 @@ #define QBI_PROCESS_HPP #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" template void rotation_matrix(value_type r[9],value_type* u) { @@ -18,7 +18,7 @@ void rotation_matrix(value_type r[9],value_type* u) z_u[0] = z[0] + u[0]; z_u[1] = z[1] + u[1]; z_u[2] = z[2] + u[2]; - image::mat::product(z_u,z_u,r,image::dim<3,1>(),image::dim<1,3>()); + tipl::mat::product(z_u,z_u,r,tipl::dim<3,1>(),tipl::dim<1,3>()); for (unsigned int i = 0; i < 9; ++i) r[i] /= value; @@ -65,14 +65,14 @@ struct QBIReconstruction : public BaseProcess for (unsigned int m = 0; m < b_count; ++m,++index) { float value = std::abs( - voxel.bvectors[m]*image::vector<3,float>(voxel.ti.vertices[n])); + voxel.bvectors[m]*tipl::vector<3,float>(voxel.ti.vertices[n])); Ht[index] = spherical_guassian(value,interop_angle); } iHtH.resize(half_odf_size*half_odf_size); iHtH_pivot.resize(half_odf_size); - image::mat::square(Ht.begin(),iHtH.begin(),image::dyndim(half_odf_size,b_count)); + tipl::mat::square(Ht.begin(),iHtH.begin(),tipl::dyndim(half_odf_size,b_count)); - image::mat::lu_decomposition(iHtH.begin(),iHtH_pivot.begin(),image::dyndim(half_odf_size,half_odf_size)); + tipl::mat::lu_decomposition(iHtH.begin(),iHtH_pivot.begin(),tipl::dyndim(half_odf_size,half_odf_size)); // vector of angles std::vector C(3*k); // 3 by k matrix @@ -88,14 +88,14 @@ struct QBIReconstruction : public BaseProcess std::vector icosa_data_r(half_odf_size*3); for (unsigned int gi = 0; gi < half_odf_size; ++gi) { - image::vector<3,float> u(voxel.ti.vertices[gi]); + tipl::vector<3,float> u(voxel.ti.vertices[gi]); float r[9];// a 3-by-3 matrix rotation_matrix(r,u.begin()); std::vector Gt(half_odf_size*k); // a half_odf_size-by-k matrix // Gt = icosa_data*r*C; - image::mat::product(icosa_data.begin(),r,icosa_data_r.begin(),image::dyndim(half_odf_size,3),image::dim<3,3>()); - image::mat::product(icosa_data_r.begin(),C.begin(),Gt.begin(),image::dyndim(half_odf_size,3),image::dyndim(3,k)); + tipl::mat::product(icosa_data.begin(),r,icosa_data_r.begin(),tipl::dyndim(half_odf_size,3),tipl::dim<3,3>()); + tipl::mat::product(icosa_data_r.begin(),C.begin(),Gt.begin(),tipl::dyndim(half_odf_size,3),tipl::dyndim(3,k)); for (unsigned int i = 0; i < Gt.size(); ++i) Gt[i] = spherical_guassian(std::abs(Gt[i]),interop_angle); @@ -119,7 +119,7 @@ struct QBIReconstruction : public BaseProcess } sG.resize(half_odf_size*half_odf_size); //sG = S*G; - image::mat::product(S.begin(),G.begin(),sG.begin(),image::dyndim(half_odf_size,half_odf_size),image::dyndim(half_odf_size,half_odf_size)); + tipl::mat::product(S.begin(),G.begin(),sG.begin(),tipl::dyndim(half_odf_size,half_odf_size),tipl::dyndim(half_odf_size,half_odf_size)); } public: @@ -127,12 +127,12 @@ struct QBIReconstruction : public BaseProcess { // Ht_s = Ht * signal std::vector Ht_s(half_odf_size); - image::mat::vector_product(Ht.begin(),data.space.begin(),Ht_s.begin(),image::dyndim(half_odf_size,data.space.size())); + tipl::mat::vector_product(Ht.begin(),data.space.begin(),Ht_s.begin(),tipl::dyndim(half_odf_size,data.space.size())); // solve HtH * x = Ht_s std::vector x(half_odf_size); - image::mat::lu_solve(iHtH.begin(),iHtH_pivot.begin(),Ht_s.begin(),x.begin(),image::dyndim(half_odf_size,half_odf_size)); + tipl::mat::lu_solve(iHtH.begin(),iHtH_pivot.begin(),Ht_s.begin(),x.begin(),tipl::dyndim(half_odf_size,half_odf_size)); // odf = sG*x - image::mat::vector_product(sG.begin(),x.begin(),data.odf.begin(),image::dyndim(half_odf_size,half_odf_size)); + tipl::mat::vector_product(sG.begin(),x.begin(),data.odf.begin(),tipl::dyndim(half_odf_size,half_odf_size)); for (unsigned int index = 0; index < data.odf.size(); ++index) if (data.odf[index] < 0.0) diff --git a/libs/dsi/racian_noise.hpp b/libs/dsi/racian_noise.hpp index a330eb267..5b9aa7aaa 100644 --- a/libs/dsi/racian_noise.hpp +++ b/libs/dsi/racian_noise.hpp @@ -3,7 +3,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" double modified_bessel_order0(double x) { @@ -39,8 +39,8 @@ class RacianNoise float max_prob; float max_int; private: - static image::normal_dist gen_normal; - static image::uniform_dist gen_uniform; + static tipl::normal_dist gen_normal; + static tipl::uniform_dist gen_uniform; private: struct RicianDistribution { diff --git a/libs/dsi/sh_process.hpp b/libs/dsi/sh_process.hpp index 4ad448306..90f038e61 100644 --- a/libs/dsi/sh_process.hpp +++ b/libs/dsi/sh_process.hpp @@ -4,7 +4,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #define _USE_MATH_DEFINES @@ -73,28 +73,28 @@ struct SHDecomposition : public BaseProcess for (unsigned int i = 0,index = 0; i < R; ++i,index += R+1) P[index] = boost::math::legendre_p(j_map[i].second,0.0)*2.0*M_PI; - image::mat::product(U.begin(),P.begin(),UP.begin(),image::dyndim(half_odf_size,R),image::dyndim(R,R)); + tipl::mat::product(U.begin(),P.begin(),UP.begin(),tipl::dyndim(half_odf_size,R),tipl::dyndim(R,R)); } std::vector iB(Bt.size()); { std::vector BtB(R*R); // BtB = Bt * trans(Bt); - image::mat::square(Bt.begin(),BtB.begin(),image::dyndim(R,voxel.bvectors.size())); + tipl::mat::square(Bt.begin(),BtB.begin(),tipl::dyndim(R,voxel.bvectors.size())); for (unsigned int i = 0,index = 0; i < R; ++i,index += R+1) { float l = j_map[i].second; BtB[index] += l*l*(l+1.0)*(l+1.0)*lambda; } std::vector pivot(R); - image::mat::lu_decomposition(BtB.begin(),pivot.begin(),image::dyndim(R,R)); + tipl::mat::lu_decomposition(BtB.begin(),pivot.begin(),tipl::dyndim(R,R)); //iB = inv(BtB)*Bt; - image::mat::lu_solve(BtB.begin(),pivot.begin(),Bt.begin(),iB.begin(),image::dyndim(R,R),image::dyndim(R,voxel.bvectors.size())); + tipl::mat::lu_solve(BtB.begin(),pivot.begin(),Bt.begin(),iB.begin(),tipl::dyndim(R,R),tipl::dyndim(R,voxel.bvectors.size())); } UPiB.resize(half_odf_size*voxel.bvectors.size()); - image::mat::product(UP.begin(),iB.begin(),UPiB.begin(),image::dyndim(half_odf_size,R),image::dyndim(R,voxel.bvectors.size())); + tipl::mat::product(UP.begin(),iB.begin(),UPiB.begin(),tipl::dyndim(half_odf_size,R),tipl::dyndim(R,voxel.bvectors.size())); @@ -108,7 +108,7 @@ struct SHDecomposition : public BaseProcess for(unsigned int index = 0;index < b0_index.size();++index) data.space[b0_index[index]] = 0; - image::mat::vector_product(&*UPiB.begin(),&*data.space.begin(),&*data.odf.begin(),image::dyndim(half_odf_size,data.space.size())); + tipl::mat::vector_product(&*UPiB.begin(),&*data.space.begin(),&*data.odf.begin(),tipl::dyndim(half_odf_size,data.space.size())); for (unsigned int index = 0; index < data.odf.size(); ++index) if (data.odf[index] < 0.0) data.odf[index] = 0.0; diff --git a/libs/dsi/tessellated_icosahedron.hpp b/libs/dsi/tessellated_icosahedron.hpp index 45eb8906e..326fc5f74 100644 --- a/libs/dsi/tessellated_icosahedron.hpp +++ b/libs/dsi/tessellated_icosahedron.hpp @@ -1,6 +1,6 @@ #ifndef TESSELLATED_ICOSAHEDRON_HPP #define TESSELLATED_ICOSAHEDRON_HPP -#include +#include #include #include #include @@ -19,30 +19,30 @@ class tessellated_icosahedron unsigned int fold; unsigned int vertices_count; unsigned int half_vertices_count; - std::vector > vertices; - std::vector > faces; + std::vector > vertices; + std::vector > faces; std::vector > icosa_cos; private: float face_dis,angle_res; unsigned short cur_vertex; - void add_vertex(const image::vector<3,float>& vertex) + void add_vertex(const tipl::vector<3,float>& vertex) { vertices[cur_vertex] = vertex; vertices[cur_vertex + half_vertices_count] = -vertex; ++cur_vertex; } - void get_mid_vertex(const image::vector<3,float>& v1, - const image::vector<3,float>& v2, - image::vector<3,float>& v3) const + void get_mid_vertex(const tipl::vector<3,float>& v1, + const tipl::vector<3,float>& v2, + tipl::vector<3,float>& v3) const { v3 = v1; v3 += v2; v3.normalize(); } - void get_mid_vertex(const image::vector<3,float>& v1, - const image::vector<3,float>& v2, - const image::vector<3,float>& v3, - image::vector<3,float>& v4) const + void get_mid_vertex(const tipl::vector<3,float>& v1, + const tipl::vector<3,float>& v2, + const tipl::vector<3,float>& v3, + tipl::vector<3,float>& v4) const { v4 = v1; v4 += v2; @@ -54,7 +54,7 @@ class tessellated_icosahedron std::vector& edge) { edge.push_back(from_vertex); - image::vector<3,float> uv = vertices[to_vertex]; + tipl::vector<3,float> uv = vertices[to_vertex]; uv -= vertices[from_vertex]; double angle = std::acos(1.0-uv.length2()*0.5); uv.normalize(); @@ -64,7 +64,7 @@ class tessellated_icosahedron float phi = angle*index; phi /= (float)fold; float y = face_d/std::cos(phi-angle*0.5); - image::vector<3,float> vec = uv; + tipl::vector<3,float> vec = uv; vec *= std::sqrt(1.0 + y*(y-2.0*std::cos(phi))); vec += vertices[from_vertex]; vec.normalize(); @@ -80,7 +80,7 @@ class tessellated_icosahedron edge.push_back(from_vertex); if (fold == 2) { - image::vector<3,float> uv; + tipl::vector<3,float> uv; get_mid_vertex(vertices[to_vertex],vertices[from_vertex],uv); edge.push_back(cur_vertex); add_vertex(uv); @@ -88,9 +88,9 @@ class tessellated_icosahedron else if(fold == 4) { - image::vector<3,float> mid; + tipl::vector<3,float> mid; get_mid_vertex(vertices[to_vertex],vertices[from_vertex],mid); - image::vector<3,float> u = mid; + tipl::vector<3,float> u = mid; get_mid_vertex(mid,vertices[from_vertex],u); edge.push_back(cur_vertex); add_vertex(u); @@ -102,7 +102,7 @@ class tessellated_icosahedron } else { - image::vector<3,float> uv = vertices[to_vertex]; + tipl::vector<3,float> uv = vertices[to_vertex]; uv -= vertices[from_vertex]; uv.normalize(); for (unsigned int index = 1;index < fold;++index) @@ -111,7 +111,7 @@ class tessellated_icosahedron phi /= (float)fold; float y = face_dis/std::cos(phi-angle_res*0.5); - image::vector<3,float> vec = uv; + tipl::vector<3,float> vec = uv; vec *= std::sqrt(1.0 + y*(y-2.0*std::cos(phi))); vec += vertices[from_vertex]; vec.normalize(); @@ -128,8 +128,8 @@ class tessellated_icosahedron } void add_face(short v1,short v2,short v3) { - faces.push_back(image::vector<3,short>(v1,v2,v3)); - faces.push_back(image::vector<3,short>(opposite(v1),opposite(v3),opposite(v2))); + faces.push_back(tipl::vector<3,short>(v1,v2,v3)); + faces.push_back(tipl::vector<3,short>(opposite(v1),opposite(v3),opposite(v2))); } template void add_faces_in_line(input_type1 up,input_type2 down,unsigned int up_count) @@ -188,14 +188,14 @@ class tessellated_icosahedron add_faces_in_triangle(edge0,edge1,edge2,fold); if(fold == 3) { - image::vector<3,float> mid; + tipl::vector<3,float> mid; get_mid_vertex(vertices[edge0[0]],vertices[edge1[0]],vertices[edge2[0]],mid); add_vertex(mid); return; } if(fold == 4) { - image::vector<3,float> u; + tipl::vector<3,float> u; get_mid_vertex(vertices[edge0[2]],vertices[edge2[2]],u); add_vertex(u); get_mid_vertex(vertices[edge0[2]],vertices[edge1[2]],u); @@ -206,7 +206,7 @@ class tessellated_icosahedron } if(fold == 5) { - image::vector<3,float> u1,u2,u3,u4,u5,u6; + tipl::vector<3,float> u1,u2,u3,u4,u5,u6; get_mid_vertex(vertices[edge0[0]],vertices[edge0[3]],vertices[edge2[2]],u1); get_mid_vertex(vertices[edge1[0]],vertices[edge1[3]],vertices[edge0[2]],u3); get_mid_vertex(vertices[edge2[0]],vertices[edge2[3]],vertices[edge1[2]],u6); @@ -223,7 +223,7 @@ class tessellated_icosahedron } if(fold == 6) { - image::vector<3,float> u1,u2,u3,u4,u5,u6,u7,u8,u9,u10;// (6-1)*(6-2)/2 + tipl::vector<3,float> u1,u2,u3,u4,u5,u6,u7,u8,u9,u10;// (6-1)*(6-2)/2 get_mid_vertex(vertices[edge0[0]],vertices[edge1[0]],vertices[edge2[0]],u6); get_mid_vertex(vertices[edge0[0]],vertices[edge0[3]],vertices[edge2[3]],u1); @@ -253,7 +253,7 @@ class tessellated_icosahedron } if(fold == 8) { - image::vector<3,float> u[22]; // (8-1)*(8-2)/2=21, add one for index started from1 + tipl::vector<3,float> u[22]; // (8-1)*(8-2)/2=21, add one for index started from1 get_mid_vertex(vertices[edge0[4]],vertices[edge2[4]],u[8]); get_mid_vertex(vertices[edge1[4]],vertices[edge2[4]],u[17]); get_mid_vertex(vertices[edge0[4]],vertices[edge1[4]],u[10]); @@ -290,13 +290,13 @@ class tessellated_icosahedron void build_icosahedron() { // the top vertex - add_vertex(image::vector<3,float>(0,0,1.0)); + add_vertex(tipl::vector<3,float>(0,0,1.0)); //central vertices around the upper staggered circles float sqrt5 = std::sqrt(5.0); float height = 1.0/sqrt5; float radius = 2.0/sqrt5; for (unsigned int index = 0;index < 5;++index) - add_vertex(image::vector<3,float>( + add_vertex(tipl::vector<3,float>( std::cos(((float)index)*M_PI*0.4)*radius, std::sin(((float)index)*M_PI*0.4)*radius,height)); @@ -328,8 +328,8 @@ class tessellated_icosahedron for(unsigned int index = 0;index < redges.size();++index) { redges[index] = edges[index]; - image::add_constant(redges[index],half_vertices_count); - image::mod_constant(redges[index],vertices_count); + tipl::add_constant(redges[index],half_vertices_count); + tipl::mod_constant(redges[index],vertices_count); } // hat faces @@ -376,8 +376,8 @@ class tessellated_icosahedron } void sort_vertices(void) { - std::vector > sorted_vertices(vertices.begin(),vertices.end()); - std::sort(sorted_vertices.begin(),sorted_vertices.end(),std::greater >()); + std::vector > sorted_vertices(vertices.begin(),vertices.end()); + std::sort(sorted_vertices.begin(),sorted_vertices.end(),std::greater >()); for(unsigned int index = 0;index < half_vertices_count;++index) sorted_vertices[index+half_vertices_count] = -sorted_vertices[index]; std::vector index_map(vertices_count); @@ -523,7 +523,7 @@ class tessellated_icosahedron std::copy(faces[i].begin(),faces[i].end(),short_data.begin()+index); } - unsigned short discretize(const image::vector<3,float>& v) + unsigned short discretize(const tipl::vector<3,float>& v) { short dir_index = 0; float max_value = 0.0; diff --git a/libs/gzip_interface.hpp b/libs/gzip_interface.hpp index 8543daeb7..0cb15fc64 100644 --- a/libs/gzip_interface.hpp +++ b/libs/gzip_interface.hpp @@ -5,7 +5,7 @@ #else #include "zlib.h" #endif -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "prog_interface_static_link.h" extern bool prog_aborted_; class gz_istream{ @@ -188,8 +188,8 @@ class gz_ostream{ }; -typedef image::io::nifti_base gz_nifti; -typedef image::io::mat_write_base gz_mat_write; -typedef image::io::mat_read_base gz_mat_read; +typedef tipl::io::nifti_base gz_nifti; +typedef tipl::io::mat_write_base gz_mat_write; +typedef tipl::io::mat_read_base gz_mat_read; #endif // GZIP_INTERFACE_HPP diff --git a/libs/mapping/atlas.cpp b/libs/mapping/atlas.cpp index 6aebd2c86..54ec6e1dd 100644 --- a/libs/mapping/atlas.cpp +++ b/libs/mapping/atlas.cpp @@ -103,7 +103,7 @@ void atlas::load_from_file(void) if(is_track) { nii >> track; - I.resize(image::geometry<3>(track.width(),track.height(),track.depth())); + I.resize(tipl::geometry<3>(track.width(),track.height(),track.depth())); for(unsigned int i = 0;i < track.size();i += I.size()) track_base_pos.push_back(i); } @@ -179,7 +179,7 @@ void mni_to_tal(float& x,float &y, float &z) /* -std::string atlas::get_label_name_at(const image::vector<3,float>& mni_space) +std::string atlas::get_label_name_at(const tipl::vector<3,float>& mni_space) { if(I.empty()) load_from_file(); @@ -202,7 +202,7 @@ std::string atlas::get_label_name_at(const image::vector<3,float>& mni_space) return result; } */ -int atlas::get_index(image::vector<3,float> atlas_space) +int atlas::get_index(tipl::vector<3,float> atlas_space) { atlas_space.to(transform); atlas_space.round(); @@ -211,7 +211,7 @@ int atlas::get_index(image::vector<3,float> atlas_space) return ((int)atlas_space[2]*I.height()+(int)atlas_space[1])*I.width()+(int)atlas_space[0]; } -bool atlas::is_labeled_as(const image::vector<3,float>& mni_space,unsigned int label_name_index) +bool atlas::is_labeled_as(const tipl::vector<3,float>& mni_space,unsigned int label_name_index) { if(I.empty()) load_from_file(); @@ -239,7 +239,7 @@ bool atlas::is_labeled_as(const image::vector<3,float>& mni_space,unsigned int l return false; return std::find(index2label[l].begin(),index2label[l].end(),label_name_index) != index2label[l].end(); } -int atlas::get_track_label(const std::vector >& points) +int atlas::get_track_label(const std::vector >& points) { if(I.empty()) load_from_file(); diff --git a/libs/mapping/atlas.hpp b/libs/mapping/atlas.hpp index d1cf60792..ccaceed74 100644 --- a/libs/mapping/atlas.hpp +++ b/libs/mapping/atlas.hpp @@ -1,22 +1,22 @@ #ifndef ATLAS_HPP #define ATLAS_HPP -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include #include class atlas{ private: - image::basic_image I; + tipl::image I; std::vector label_num; std::vector labels; - image::matrix<4,4,float> transform; + tipl::matrix<4,4,float> transform; void load_from_file(void); void load_label(void); - int get_index(image::vector<3,float> atlas_space); + int get_index(tipl::vector<3,float> atlas_space); private:// for talairach only std::vector > index2label; std::vector > label2index; private:// for track atlas only - image::basic_image track; + tipl::image track; std::vector track_base_pos; bool is_track; public: @@ -42,9 +42,9 @@ class atlas{ } return label_num; } - //std::string get_label_name_at(const image::vector<3,float>& mni_space); - bool is_labeled_as(const image::vector<3,float>& mni_space,unsigned int label); - int get_track_label(const std::vector >& points); + //std::string get_label_name_at(const tipl::vector<3,float>& mni_space); + bool is_labeled_as(const tipl::vector<3,float>& mni_space,unsigned int label); + int get_track_label(const std::vector >& points); }; #endif // ATLAS_HPP diff --git a/libs/mapping/connectometry_db.cpp b/libs/mapping/connectometry_db.cpp index 10e5b3667..bdc761216 100644 --- a/libs/mapping/connectometry_db.cpp +++ b/libs/mapping/connectometry_db.cpp @@ -21,8 +21,8 @@ void connectometry_db::read_db(fib_data* handle_) subject_qa_sd.push_back(0); } - image::par_for(subject_qa.size(),[&](int i){ - subject_qa_sd[i] = image::standard_deviation(subject_qa[i],subject_qa[i]+subject_qa_length); + tipl::par_for(subject_qa.size(),[&](int i){ + subject_qa_sd[i] = tipl::standard_deviation(subject_qa[i],subject_qa[i]+subject_qa_length); if(subject_qa_sd[i] == 0.0) subject_qa_sd[i] = 1.0; else @@ -231,7 +231,7 @@ bool connectometry_db::add_subject_file(const std::string& file_name, subject_qa_buf.push_back(std::move(new_subject_qa)); subject_qa.push_back(&(subject_qa_buf.back()[0])); subject_names.push_back(subject_name); - subject_qa_sd.push_back(image::standard_deviation(subject_qa.back(), + subject_qa_sd.push_back(tipl::standard_deviation(subject_qa.back(), subject_qa.back()+subject_qa_length)); if(subject_qa_sd.back() == 0.0) subject_qa_sd.back() = 1.0; @@ -244,12 +244,12 @@ bool connectometry_db::add_subject_file(const std::string& file_name, void connectometry_db::get_subject_vector(unsigned int from,unsigned int to, std::vector >& subject_vector, - const image::basic_image& cerebrum_mask,float fiber_threshold,bool normalize_fp) const + const tipl::image& cerebrum_mask,float fiber_threshold,bool normalize_fp) const { unsigned int total_count = to-from; subject_vector.clear(); subject_vector.resize(total_count); - image::par_for(total_count,[&](unsigned int index) + tipl::par_for(total_count,[&](unsigned int index) { unsigned int subject_index = index + from; for(unsigned int s_index = 0;s_index < si2vi.size();++s_index) @@ -263,16 +263,16 @@ void connectometry_db::get_subject_vector(unsigned int from,unsigned int to, } }); if(normalize_fp) - image::par_for(num_subjects,[&](unsigned int index) + tipl::par_for(num_subjects,[&](unsigned int index) { - float sd = image::standard_deviation(subject_vector[index].begin(),subject_vector[index].end(),image::mean(subject_vector[index].begin(),subject_vector[index].end())); + float sd = tipl::standard_deviation(subject_vector[index].begin(),subject_vector[index].end(),tipl::mean(subject_vector[index].begin(),subject_vector[index].end())); if(sd > 0.0) - image::multiply_constant(subject_vector[index].begin(),subject_vector[index].end(),1.0/sd); + tipl::multiply_constant(subject_vector[index].begin(),subject_vector[index].end(),1.0/sd); }); } void connectometry_db::get_subject_vector(unsigned int subject_index,std::vector& subject_vector, - const image::basic_image& cerebrum_mask,float fiber_threshold,bool normalize_fp) const + const tipl::image& cerebrum_mask,float fiber_threshold,bool normalize_fp) const { subject_vector.clear(); for(unsigned int s_index = 0;s_index < si2vi.size();++s_index) @@ -286,24 +286,24 @@ void connectometry_db::get_subject_vector(unsigned int subject_index,std::vector } if(normalize_fp) { - float sd = image::standard_deviation(subject_vector.begin(),subject_vector.end(),image::mean(subject_vector.begin(),subject_vector.end())); + float sd = tipl::standard_deviation(subject_vector.begin(),subject_vector.end(),tipl::mean(subject_vector.begin(),subject_vector.end())); if(sd > 0.0) - image::multiply_constant(subject_vector.begin(),subject_vector.end(),1.0/sd); + tipl::multiply_constant(subject_vector.begin(),subject_vector.end(),1.0/sd); } } -void connectometry_db::get_dif_matrix(std::vector& matrix,const image::basic_image& cerebrum_mask,float fiber_threshold,bool normalize_fp) +void connectometry_db::get_dif_matrix(std::vector& matrix,const tipl::image& cerebrum_mask,float fiber_threshold,bool normalize_fp) { matrix.clear(); matrix.resize(num_subjects*num_subjects); std::vector > subject_vector; get_subject_vector(0,num_subjects,subject_vector,cerebrum_mask,fiber_threshold,normalize_fp); begin_prog("calculating"); - image::par_for2(num_subjects,[&](int i,int id){ + tipl::par_for2(num_subjects,[&](int i,int id){ if(id == 0) check_prog(i,num_subjects); for(unsigned int j = i+1; j < num_subjects;++j) { - double result = image::root_mean_suqare_error( + double result = tipl::root_mean_suqare_error( subject_vector[i].begin(),subject_vector[i].end(), subject_vector[j].begin()); matrix[i*num_subjects+j] = result; @@ -314,7 +314,7 @@ void connectometry_db::get_dif_matrix(std::vector& matrix,const image::ba } void connectometry_db::save_subject_vector(const char* output_name, - const image::basic_image& cerebrum_mask, + const tipl::image& cerebrum_mask, float fiber_threshold, bool normalize_fp) const { @@ -369,8 +369,8 @@ void connectometry_db::save_subject_vector(const char* output_name, for(unsigned int j = 0,fib_offset = 0;j < handle->dir.num_fiber && handle->dir.fa[j][cur_index] > fiber_threshold;++j,fib_offset+=si2vi.size()) { voxel_location.push_back(cur_index); - image::pixel_index<3> p(cur_index,handle->dim); - image::vector<3> p2; + tipl::pixel_index<3> p(cur_index,handle->dim); + tipl::vector<3> p2; handle->subject2mni(p,p2); mni_location.push_back(p2[0]); mni_location.push_back(p2[1]); @@ -431,10 +431,10 @@ bool connectometry_db::save_subject_data(const char* output_name) } void connectometry_db::get_subject_slice(unsigned int subject_index,unsigned char dim,unsigned int pos, - image::basic_image& slice) const + tipl::image& slice) const { - image::basic_image tmp; - image::reslicing(vi2si, tmp, dim, pos); + tipl::image tmp; + tipl::reslicing(vi2si, tmp, dim, pos); slice.clear(); slice.resize(tmp.geometry()); for(unsigned int index = 0;index < slice.size();++index) @@ -599,7 +599,7 @@ void connectometry_db::move_down(int id) std::swap(subject_qa_sd[id],subject_qa_sd[id+1]); } -void connectometry_db::auto_match(const image::basic_image& cerebrum_mask,float fiber_threshold,bool normalize_fp) +void connectometry_db::auto_match(const tipl::image& cerebrum_mask,float fiber_threshold,bool normalize_fp) { std::vector dif; get_dif_matrix(dif,cerebrum_mask,fiber_threshold,normalize_fp); @@ -820,7 +820,7 @@ bool connectometry_result::individual_vs_db(std::shared_ptr handle,con info.individual_data = &(data[0]); //info.individual_data_sd = normalize_qa ? individual_data_sd[subject_id]:1.0; info.individual_data_sd = 1.0; - float fa_threshold = 0.6*image::segmentation::otsu_threshold(image::make_image(handle->dir.fa[0],handle->dim)); + float fa_threshold = 0.6*tipl::segmentation::otsu_threshold(tipl::make_image(handle->dir.fa[0],handle->dim)); calculate_spm(handle,*this,info,fa_threshold,normalized_qa,terminated); add_mapping_for_tracking(handle,">%","<%"); return true; @@ -868,7 +868,7 @@ bool connectometry_result::compare(std::shared_ptr handle,const std::v if(normalization == 2) // linear regression { out << " Normalization was conducted by a linear regression between the comparison scans."; - std::pair r = image::linear_regression(fa2[0],fa2[0] + handle->dim.size(),fa1[0]); + std::pair r = tipl::linear_regression(fa2[0],fa2[0] + handle->dim.size(),fa1[0]); for(unsigned char fib = 0;fib < handle->dir.num_fiber;++fib) { for(unsigned int index = 0;index < handle->dim.size();++index) @@ -886,8 +886,8 @@ bool connectometry_result::compare(std::shared_ptr handle,const std::v if(normalization == 3) // variance to one { out << " Normalization was conducted by scaling the variance to one."; - float sd1 = image::standard_deviation(fa1[0],fa1[0] + handle->dim.size()); - float sd2 = image::standard_deviation(fa2[0],fa2[0] + handle->dim.size()); + float sd1 = tipl::standard_deviation(fa1[0],fa1[0] + handle->dim.size()); + float sd2 = tipl::standard_deviation(fa2[0],fa2[0] + handle->dim.size()); for(unsigned char fib = 0;fib < handle->dir.num_fiber;++fib) { for(unsigned int index = 0;index < handle->dim.size();++index) @@ -1159,7 +1159,7 @@ double stat_model::operator()(const std::vector& original_population,uns g0[i0] = population[index]; ++i0; } - return image::t_statistics(g0.begin(),g0.end(),g1.begin(),g1.end()); + return tipl::t_statistics(g0.begin(),g0.end(),g1.begin(),g1.end()); } else { @@ -1192,7 +1192,7 @@ double stat_model::operator()(const std::vector& original_population,uns { std::vector b(feature_count); mr.regress(&*population.begin(),&*b.begin()); - double mean = image::mean(population.begin(),population.end()); + double mean = tipl::mean(population.begin(),population.end()); return mean == 0 ? 0:b[study_feature]*X_range[study_feature]/mean; } else @@ -1216,11 +1216,11 @@ double stat_model::operator()(const std::vector& original_population,uns if(value == 0.0) return 0.0; if(threshold_type == mean_dif) - return value-image::mean(population.begin(),population.end()); + return value-tipl::mean(population.begin(),population.end()); else if(threshold_type == percentage) { - float mean = image::mean(population.begin(),population.end()); + float mean = tipl::mean(population.begin(),population.end()); if(mean == 0.0) return 0.0; return value/mean-1.0; diff --git a/libs/mapping/connectometry_db.hpp b/libs/mapping/connectometry_db.hpp index 1a49720ee..5ec5d4dbe 100644 --- a/libs/mapping/connectometry_db.hpp +++ b/libs/mapping/connectometry_db.hpp @@ -3,7 +3,7 @@ #include #include #include "gzip_interface.hpp" -#include "image/image.hpp" +#include "tipl/tipl.hpp" class fib_data; class connectometry_db { @@ -20,12 +20,12 @@ class connectometry_db public: std::list > subject_qa_buf;// merged from other db unsigned int subject_qa_length; - image::basic_image vi2si; + tipl::image vi2si; std::vector si2vi; std::string index_name; public://longitudinal studies std::vector > match; - void auto_match(const image::basic_image& cerebrum_mask,float fiber_threshold,bool normalize_fp); + void auto_match(const tipl::image& cerebrum_mask,float fiber_threshold,bool normalize_fp); void calculate_change(unsigned char dif_type,bool norm); public: connectometry_db():num_subjects(0),modified(false){;} @@ -40,17 +40,17 @@ class connectometry_db const std::string& subject_name); void get_subject_vector(unsigned int from,unsigned int to, std::vector >& subject_vector, - const image::basic_image& cerebrum_mask,float fiber_threshold,bool normalize_fp) const; + const tipl::image& cerebrum_mask,float fiber_threshold,bool normalize_fp) const; void get_subject_vector(unsigned int subject_index,std::vector& subject_vector, - const image::basic_image& cerebrum_mask,float fiber_threshold,bool normalize_fp) const; - void get_dif_matrix(std::vector& matrix,const image::basic_image& cerebrum_mask,float fiber_threshold,bool normalize_fp); + const tipl::image& cerebrum_mask,float fiber_threshold,bool normalize_fp) const; + void get_dif_matrix(std::vector& matrix,const tipl::image& cerebrum_mask,float fiber_threshold,bool normalize_fp); void save_subject_vector(const char* output_name, - const image::basic_image& cerebrum_mask, + const tipl::image& cerebrum_mask, float fiber_threshold, bool normalize_fp) const; bool save_subject_data(const char* output_name); void get_subject_slice(unsigned int subject_index,unsigned char dim,unsigned int pos, - image::basic_image& slice) const; + tipl::image& slice) const; void get_subject_fa(unsigned int subject_index,std::vector >& fa_data) const; void get_data_at(unsigned int index,unsigned int fib_index,std::vector& data,bool normalize_qa) const; bool get_odf_profile(const char* file_name,std::vector& cur_subject_data); @@ -67,7 +67,7 @@ class connectometry_db class stat_model{ public: - image::uniform_dist rand_gen; + tipl::uniform_dist rand_gen; std::mutex lock_random; public: std::vector subject_index; @@ -81,7 +81,7 @@ class stat_model{ unsigned int feature_count; unsigned int study_feature; enum {percentage = 0,t = 1,beta = 2,percentile = 3,mean_dif = 4} threshold_type; - image::multiple_regression mr; + tipl::multiple_regression mr; void select_variables(const std::vector& sel); public: // individual const float* individual_data; diff --git a/libs/mapping/fa_template.cpp b/libs/mapping/fa_template.cpp index f2cdf132b..e261f8e7d 100644 --- a/libs/mapping/fa_template.cpp +++ b/libs/mapping/fa_template.cpp @@ -1,4 +1,4 @@ -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "fa_template.hpp" #include "libs/gzip_interface.hpp" diff --git a/libs/mapping/fa_template.hpp b/libs/mapping/fa_template.hpp index 4d36ccb92..0149b507f 100644 --- a/libs/mapping/fa_template.hpp +++ b/libs/mapping/fa_template.hpp @@ -1,11 +1,11 @@ #ifndef FA_TEMPLATE_HPP #define FA_TEMPLATE_HPP -#include "image/image.hpp" +#include "tipl/tipl.hpp" struct fa_template{ std::string template_file_name,error_msg; - image::vector<3> vs,shift; - image::basic_image I; + tipl::vector<3> vs,shift; + tipl::image I; float tran[16]; bool load_from_file(void); template diff --git a/libs/tracking/basic_process.hpp b/libs/tracking/basic_process.hpp index de95f4daf..64eac8c7b 100644 --- a/libs/tracking/basic_process.hpp +++ b/libs/tracking/basic_process.hpp @@ -1,6 +1,6 @@ #ifndef BASIC_PROCESS_HPP #define BASIC_PROCESS_HPP -#include "image/image.hpp" +#include "tipl/tipl.hpp" extern char fib_dx[80]; extern char fib_dy[80]; @@ -12,20 +12,20 @@ struct LocateVoxel{ template void operator()(method& info) { - image::vector<3,short> cur_pos(info.position); + tipl::vector<3,short> cur_pos(info.position); unsigned int cur_pos_index; - cur_pos_index = image::pixel_index<3>(cur_pos[0],cur_pos[1],cur_pos[2],info.trk.dim).index(); + cur_pos_index = tipl::pixel_index<3>(cur_pos[0],cur_pos[1],cur_pos[2],info.trk.dim).index(); - std::vector > next_voxels_dir; - std::vector > next_voxels_pos; + std::vector > next_voxels_dir; + std::vector > next_voxels_pos; std::vector next_voxels_index; std::vector voxel_angle; // assume isotropic for(unsigned int index = 0;index < 80;++index) { - image::vector<3,float> dis(fib_dx[index],fib_dy[index],fib_dz[index]); - image::vector<3,short> pos(cur_pos); + tipl::vector<3,float> dis(fib_dx[index],fib_dy[index],fib_dz[index]); + tipl::vector<3,short> pos(cur_pos); pos += dis; if(!info.trk.dim.is_valid(pos)) continue; @@ -34,7 +34,7 @@ struct LocateVoxel{ if(angle_cos < info.current_tracking_angle) continue; next_voxels_pos.push_back(pos); - next_voxels_index.push_back(image::pixel_index<3>(pos[0],pos[1],pos[2],info.trk.dim).index()); + next_voxels_index.push_back(tipl::pixel_index<3>(pos[0],pos[1],pos[2],info.trk.dim).index()); next_voxels_dir.push_back(dis); voxel_angle.push_back(angle_cos); } @@ -82,8 +82,8 @@ struct EstimateNextDirectionRungeKutta4 template void operator()(method& info) { - image::vector<3,float> y; - image::vector<3,float> k1,k2,k3,k4; + tipl::vector<3,float> y; + tipl::vector<3,float> k1,k2,k3,k4; if (!info.get_dir(info.position,info.dir,k1)) { info.terminated = true; @@ -166,7 +166,7 @@ struct MoveTrack { if (info.terminated) return; - image::vector<3,float> step(info.next_dir); + tipl::vector<3,float> step(info.next_dir); info.scaling_in_voxel(step); info.position += step; info.dir = info.next_dir; diff --git a/libs/tracking/fib_data.cpp b/libs/tracking/fib_data.cpp index d4f576ad1..f0f442adb 100644 --- a/libs/tracking/fib_data.cpp +++ b/libs/tracking/fib_data.cpp @@ -38,7 +38,7 @@ bool odf_data::read(gz_mat_read& mat_reader) return false; // dimension - image::geometry<3> dim; + tipl::geometry<3> dim; { const unsigned short* dim_buf = 0; if (!mat_reader.read("dimension",row,col,dim_buf)) @@ -299,7 +299,7 @@ const float* fiber_directions::get_dir(unsigned int index,unsigned int order) co bool tracking_data::get_nearest_dir_fib(unsigned int space_index, - const image::vector<3,float>& ref_dir, // reference direction, should be unit vector + const tipl::vector<3,float>& ref_dir, // reference direction, should be unit vector unsigned char& fib_order_, unsigned char& reverse_, float threshold, @@ -347,8 +347,8 @@ void tracking_data::read(const fib_data& fib) other_index = fib.dir.index_data; } bool tracking_data::get_dir(unsigned int space_index, - const image::vector<3,float>& dir, // reference direction, should be unit vector - image::vector<3,float>& main_dir, + const tipl::vector<3,float>& dir, // reference direction, should be unit vector + tipl::vector<3,float>& main_dir, float threshold, float cull_cos_angle) const { @@ -373,7 +373,7 @@ const float* tracking_data::get_dir(unsigned int space_index,unsigned char fib_o return &*(odf_table[findex[fib_order][space_index]].begin()); } -float tracking_data::cos_angle(const image::vector<3>& cur_dir,unsigned int space_index,unsigned char fib_order) const +float tracking_data::cos_angle(const tipl::vector<3>& cur_dir,unsigned int space_index,unsigned char fib_order) const { if(!dir.empty()) { @@ -384,7 +384,7 @@ float tracking_data::cos_angle(const image::vector<3>& cur_dir,unsigned int spac } float tracking_data::get_track_specific_index(unsigned int space_index,unsigned int index_num, - const image::vector<3,float>& dir) const + const tipl::vector<3,float>& dir) const { if(space_index >= dim.size() || fa[0][space_index] == 0.0) return 0.0; @@ -410,15 +410,15 @@ float tracking_data::get_track_specific_index(unsigned int space_index,unsigned return other_index[index_num][fib_order][space_index]; } -bool tracking_data::is_white_matter(const image::vector<3,float>& pos,float t) const +bool tracking_data::is_white_matter(const tipl::vector<3,float>& pos,float t) const { - return image::estimate(image::make_image(fa[0],dim),pos) > t && pos[2] > 0.5; + return tipl::estimate(tipl::make_image(fa[0],dim),pos) > t && pos[2] > 0.5; } bool fib_data::load_from_file(const char* file_name) { - image::basic_image I; + tipl::image I; float vs[3]; if(QFileInfo(file_name).completeSuffix() == "nii" || QFileInfo(file_name).completeSuffix() == "nii.gz") @@ -435,7 +435,7 @@ bool fib_data::load_from_file(const char* file_name) else if(QFileInfo(file_name).fileName() == "2dseq") { - image::io::bruker_2dseq bruker_header; + tipl::io::bruker_2dseq bruker_header; if(!bruker_header.load_from_file(file_name)) { error_msg = "Invalid 2dseq format"; @@ -492,13 +492,13 @@ bool fib_data::load_from_mat(void) view_item.push_back(item()); view_item.back().name = dir.fa.size() == 1 ? "fa":"qa"; - view_item.back().image_data = image::make_image(dir.fa[0],dim); + view_item.back().image_data = tipl::make_image(dir.fa[0],dim); view_item.back().set_scale(dir.fa[0],dir.fa[0]+dim.size()); for(unsigned int index = 1;index < dir.index_name.size();++index) { view_item.push_back(item()); view_item.back().name = dir.index_name[index]; - view_item.back().image_data = image::make_image(dir.index_data[index][0],dim); + view_item.back().image_data = tipl::make_image(dir.index_data[index][0],dim); view_item.back().set_scale(dir.index_data[index][0],dir.index_data[index][0]+dim.size()); } view_item.push_back(item()); @@ -548,7 +548,7 @@ bool fib_data::load_from_mat(void) continue; view_item.push_back(item()); view_item.back().name = matrix_name; - view_item.back().image_data = image::make_image(buf,dim); + view_item.back().image_data = tipl::make_image(buf,dim); view_item.back().set_scale(buf,buf+dim.size()); } if (!dim[2]) @@ -607,10 +607,10 @@ bool fib_data::load_from_mat(void) mat_reader.read((name+"_z").c_str(),row,col,mz) && mat_reader.read((name+"_d").c_str(),row,col,native_geo)) { - view_item[i].mx = image::make_image(mx,dim); - view_item[i].my = image::make_image(my,dim); - view_item[i].mz = image::make_image(mz,dim); - view_item[i].native_geo = image::geometry<3>(native_geo[0],native_geo[1],native_geo[2]); + view_item[i].mx = tipl::make_image(mx,dim); + view_item[i].my = tipl::make_image(my,dim); + view_item[i].mz = tipl::make_image(mz,dim); + view_item[i].native_geo = tipl::geometry<3>(native_geo[0],native_geo[1],native_geo[2]); } } } @@ -646,13 +646,13 @@ std::pair fib_data::get_value_range(const std::string& view_name) c void fib_data::get_slice(unsigned int view_index, unsigned char d_index,unsigned int pos, - image::color_image& show_image,const image::value_to_color& v2c) + tipl::color_image& show_image,const tipl::value_to_color& v2c) { if(view_item[view_index].name == "color") { { - image::basic_image buf; - image::reslicing(view_item[0].image_data, buf, d_index, pos); + tipl::image buf; + tipl::reslicing(view_item[0].image_data, buf, d_index, pos); v2c.convert(buf,show_image); } @@ -662,8 +662,8 @@ void fib_data::get_slice(unsigned int view_index, for (unsigned int index = 0;index < dim.size();++index) view_item[view_index].color_map_buf[index] = index; } - image::basic_image buf; - image::reslicing(view_item[view_index].color_map_buf, buf, d_index, pos); + tipl::image buf; + tipl::reslicing(view_item[view_index].color_map_buf, buf, d_index, pos); for (unsigned int index = 0;index < buf.size();++index) { const float* d = dir.get_dir(buf[index],0); @@ -674,8 +674,8 @@ void fib_data::get_slice(unsigned int view_index, } else { - image::basic_image buf; - image::reslicing(view_item[view_index].image_data, buf, d_index, pos); + tipl::image buf; + tipl::reslicing(view_item[view_index].image_data, buf, d_index, pos); v2c.convert(buf,show_image); } @@ -714,9 +714,9 @@ void fib_data::get_voxel_information(int x,int y,int z,std::vector& buf) continue; if(view_item[i].image_data.geometry() != dim) { - image::vector<3> pos(x,y,z); + tipl::vector<3> pos(x,y,z); pos.to(view_item[i].iT); - buf.push_back(image::estimate(view_item[i].image_data,pos)); + buf.push_back(tipl::estimate(view_item[i].image_data,pos)); } else buf.push_back(view_item[i].image_data.empty() ? 0.0 : view_item[i].image_data[index]); @@ -745,53 +745,53 @@ void fib_data::run_normalization(bool background) prog = 5; return; } - image::affine_transform arg,arg2; - image::transformation_matrix T,T2; - image::basic_image S(dir.fa[0],dim); - image::filter::gaussian(S); - S -= image::segmentation::otsu_threshold(S); - image::lower_threshold(S,0.0); - image::normalize(S,1.0); + tipl::affine_transform arg,arg2; + tipl::transformation_matrix T,T2; + tipl::image S(dir.fa[0],dim); + tipl::filter::gaussian(S); + S -= tipl::segmentation::otsu_threshold(S); + tipl::lower_threshold(S,0.0); + tipl::normalize(S,1.0); prog = 1; - image::par_for(2,[&](int i){ + tipl::par_for(2,[&](int i){ if(i) { - image::reg::linear_mr(fa_template_imp.I,fa_template_imp.vs,S,vs,arg,image::reg::affine, - image::reg::mutual_information(),thread.terminated); + tipl::reg::linear_mr(fa_template_imp.I,fa_template_imp.vs,S,vs,arg,tipl::reg::affine, + tipl::reg::mutual_information(),thread.terminated); } else { - image::reg::linear_mr(S,vs,fa_template_imp.I,fa_template_imp.vs,arg2,image::reg::affine, - image::reg::mutual_information(),thread.terminated); + tipl::reg::linear_mr(S,vs,fa_template_imp.I,fa_template_imp.vs,arg2,tipl::reg::affine, + tipl::reg::mutual_information(),thread.terminated); } }); - T = image::transformation_matrix(arg,fa_template_imp.I.geometry(),fa_template_imp.vs,S.geometry(),vs); - T2 = image::transformation_matrix(arg2,S.geometry(),vs,fa_template_imp.I.geometry(),fa_template_imp.vs); + T = tipl::transformation_matrix(arg,fa_template_imp.I.geometry(),fa_template_imp.vs,S.geometry(),vs); + T2 = tipl::transformation_matrix(arg2,S.geometry(),vs,fa_template_imp.I.geometry(),fa_template_imp.vs); T2.inverse(); - if(image::reg::mutual_information()(fa_template_imp.I,S,T2) < image::reg::mutual_information()(fa_template_imp.I,S,T)) + if(tipl::reg::mutual_information()(fa_template_imp.I,S,T2) < tipl::reg::mutual_information()(fa_template_imp.I,S,T)) T = T2; prog = 2; if(thread.terminated) return; - image::reg::bfnorm_mapping bf(fa_template_imp.I.geometry(),image::geometry<3>(7,9,7)); - image::basic_image new_S(fa_template_imp.I.geometry()); - image::resample_mt(S,new_S,T,image::linear); + tipl::reg::bfnorm_mapping bf(fa_template_imp.I.geometry(),tipl::geometry<3>(7,9,7)); + tipl::image new_S(fa_template_imp.I.geometry()); + tipl::resample_mt(S,new_S,T,tipl::linear); prog = 3; - image::reg::bfnorm(bf,new_S,fa_template_imp.I,thread.terminated,std::thread::hardware_concurrency()); + tipl::reg::bfnorm(bf,new_S,fa_template_imp.I,thread.terminated,std::thread::hardware_concurrency()); if(thread.terminated) return; prog = 4; - image::basic_image,3 > mni(S.geometry()); + tipl::image,3 > mni(S.geometry()); T.inverse(); if(thread.terminated) return; - mni.for_each_mt([&](image::vector<3,float>& v,const image::pixel_index<3>& pos) + mni.for_each_mt([&](tipl::vector<3,float>& v,const tipl::pixel_index<3>& pos) { - image::vector<3> p(pos); + tipl::vector<3> p(pos); T(p); v = p; p.round(); - bf.get_displacement(image::vector<3,int>(p[0],p[1],p[2]),p); + bf.get_displacement(tipl::vector<3,int>(p[0],p[1],p[2]),p); v += p; fa_template_imp.to_mni(v); }); @@ -812,7 +812,7 @@ void fib_data::run_normalization(bool background) } } -void fib_data::subject2mni(image::vector<3>& pos) +void fib_data::subject2mni(tipl::vector<3>& pos) { if(!is_human_data) return; @@ -821,11 +821,11 @@ void fib_data::subject2mni(image::vector<3>& pos) pos.to(trans_to_mni); return; } - image::vector<3> p; - image::estimate(mni_position,pos,p); + tipl::vector<3> p; + tipl::estimate(mni_position,pos,p); pos = p; } -void fib_data::subject2mni(image::pixel_index<3>& index,image::vector<3>& pos) +void fib_data::subject2mni(tipl::pixel_index<3>& index,tipl::vector<3>& pos) { if(!is_human_data) return; @@ -840,21 +840,21 @@ void fib_data::subject2mni(image::pixel_index<3>& index,image::vector<3>& pos) return; } -void fib_data::get_atlas_roi(int atlas_index,int roi_index,std::vector >& points,float& r) +void fib_data::get_atlas_roi(int atlas_index,int roi_index,std::vector >& points,float& r) { if(get_mni_mapping().empty()) return; // this will load the files from storage to prevent GUI multishread crash - atlas_list[atlas_index].is_labeled_as(image::vector<3>(0,0,0), roi_index); + atlas_list[atlas_index].is_labeled_as(tipl::vector<3>(0,0,0), roi_index); unsigned int thread_count = std::thread::hardware_concurrency(); - std::vector > > buf(thread_count); + std::vector > > buf(thread_count); r = 1.0; - mni_position.for_each_mt2([&](const image::vector<3>& mni,const image::pixel_index<3>& index,int id) + mni_position.for_each_mt2([&](const tipl::vector<3>& mni,const tipl::pixel_index<3>& index,int id) { - image::vector<3> rmni(mni); + tipl::vector<3> rmni(mni); rmni.round(); if (atlas_list[atlas_index].is_labeled_as(rmni, roi_index)) - buf[id].push_back(image::vector<3,short>(index.begin())); + buf[id].push_back(tipl::vector<3,short>(index.begin())); }); points.clear(); for(int i = 0;i < buf.size();++i) @@ -862,14 +862,14 @@ void fib_data::get_atlas_roi(int atlas_index,int roi_index,std::vector,3 >& fib_data::get_mni_mapping(void) +const tipl::image,3 >& fib_data::get_mni_mapping(void) { if(!mni_position.empty()) return mni_position; if(is_qsdr) { mni_position.resize(dim); - mni_position.for_each_mt([&](image::vector<3>& mni,const image::pixel_index<3>& index) + mni_position.for_each_mt([&](tipl::vector<3>& mni,const tipl::pixel_index<3>& index) { mni = index.begin(); mni.to(trans_to_mni); @@ -893,7 +893,7 @@ bool fib_data::get_profile(const std::vector& tract, std::vector tract_in_mni; for(int j = 0;j < tract.size();j += 3) { - image::vector<3> v(&(tract[j])); + tipl::vector<3> v(&(tract[j])); subject2mni(v); tract_in_mni.push_back(v[0]); tract_in_mni.push_back(v[1]); @@ -903,15 +903,15 @@ bool fib_data::get_profile(const std::vector& tract, resample_tracks(smoothed_track_in_mni,tract_data,0.5); } - image::geometry<3> dim(60,75,3); + tipl::geometry<3> dim(60,75,3); profile_.resize(dim.size()); - auto profile = image::make_image(&profile_[0],dim); + auto profile = tipl::make_image(&profile_[0],dim); std::fill(profile.begin(),profile.end(),0); float length_2 = tract_data.size() >> 1; bool has_point = false; for(int j = 0;j < tract_data.size();j += 3) { - image::vector<3> v(&(tract_data[j])); + tipl::vector<3> v(&(tract_data[j])); // x = -60 ~ 60 total 120 // y = -90 ~ 60 total 150 // z = -50 ~ 70 total 120 diff --git a/libs/tracking/fib_data.hpp b/libs/tracking/fib_data.hpp index a0e583e9c..6bcf97ef8 100644 --- a/libs/tracking/fib_data.hpp +++ b/libs/tracking/fib_data.hpp @@ -4,7 +4,7 @@ #include #include #include "prog_interface_static_link.h" -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "gzip_interface.hpp" #include "connectometry_db.hpp" @@ -13,11 +13,11 @@ struct odf_data{ const float* odfs; unsigned int odfs_size; private: - image::basic_image voxel_index_map; + tipl::image voxel_index_map; std::vector odf_blocks; std::vector odf_block_size; - image::basic_image odf_block_map1; - image::basic_image odf_block_map2; + tipl::image odf_block_map1; + tipl::image odf_block_map2; unsigned int half_odf_size; public: odf_data(void):odfs(0){} @@ -40,8 +40,8 @@ class fiber_directions std::vector > index_data; public: std::vector fa; - std::vector > odf_table; - std::vector > odf_faces; + std::vector > odf_table; + std::vector > odf_faces; unsigned int num_fiber; unsigned int half_odf_size; std::string error_msg; @@ -59,32 +59,32 @@ class fiber_directions class fib_data; class tracking_data{ public: - image::geometry<3> dim; - image::vector<3> vs; + tipl::geometry<3> dim; + tipl::vector<3> vs; unsigned char fib_num; std::vector dir; std::vector fa; std::vector findex; std::vector > other_index; - std::vector > odf_table; + std::vector > odf_table; public: bool get_nearest_dir_fib(unsigned int space_index, - const image::vector<3,float>& ref_dir, // reference direction, should be unit vector + const tipl::vector<3,float>& ref_dir, // reference direction, should be unit vector unsigned char& fib_order_, unsigned char& reverse_, float threshold, float cull_cos_angle) const; void read(const fib_data& fib); bool get_dir(unsigned int space_index, - const image::vector<3,float>& dir, // reference direction, should be unit vector - image::vector<3,float>& main_dir, + const tipl::vector<3,float>& dir, // reference direction, should be unit vector + tipl::vector<3,float>& main_dir, float threshold, float cull_cos_angle) const; const float* get_dir(unsigned int space_index,unsigned char fib_order) const; - float cos_angle(const image::vector<3>& cur_dir,unsigned int space_index,unsigned char fib_order) const; + float cos_angle(const tipl::vector<3>& cur_dir,unsigned int space_index,unsigned char fib_order) const; float get_track_specific_index(unsigned int space_index,unsigned int index_num, - const image::vector<3,float>& dir) const; - bool is_white_matter(const image::vector<3,float>& pos,float t) const; + const tipl::vector<3,float>& dir) const; + bool is_white_matter(const tipl::vector<3,float>& pos,float t) const; }; @@ -93,8 +93,8 @@ class tracking_data{ struct item { std::string name; - image::const_pointer_image image_data; - image::matrix<4,4,float> T,iT;// T: image->diffusion iT: diffusion->image + tipl::const_pointer_image image_data; + tipl::matrix<4,4,float> T,iT;// T: image->diffusion iT: diffusion->image float max_value; float min_value; float contrast_max; @@ -102,9 +102,9 @@ struct item unsigned int max_color = 0x00FFFFFF; unsigned int min_color = 0; // used in QSDR - image::basic_image color_map_buf; - image::const_pointer_image mx,my,mz; - image::geometry<3> native_geo; + tipl::image color_map_buf; + tipl::const_pointer_image mx,my,mz; + tipl::geometry<3> native_geo; template @@ -128,8 +128,8 @@ class fib_data std::string report; gz_mat_read mat_reader; public: - image::geometry<3> dim; - image::vector<3> vs; + tipl::geometry<3> dim; + tipl::vector<3> vs; bool is_human_data = true; bool is_qsdr = false; public: @@ -138,17 +138,17 @@ class fib_data connectometry_db db; std::vector view_item; public: - image::thread thread; + tipl::thread thread; int prog; std::vector trans_to_mni; - image::basic_image,3 > mni_position; - image::basic_image,3 > native_position; + tipl::image,3 > mni_position; + tipl::image,3 > native_position; public: void run_normalization(bool background); - void subject2mni(image::vector<3>& pos); - void subject2mni(image::pixel_index<3>& index,image::vector<3>& pos); - void get_atlas_roi(int atlas_index,int roi_index,std::vector >& points,float& r); - const image::basic_image,3 >& get_mni_mapping(void); + void subject2mni(tipl::vector<3>& pos); + void subject2mni(tipl::pixel_index<3>& index,tipl::vector<3>& pos); + void get_atlas_roi(int atlas_index,int roi_index,std::vector >& points,float& r); + const tipl::image,3 >& get_mni_mapping(void); bool has_reg(void)const{return thread.has_started();} bool get_profile(const std::vector& tract_data, std::vector& profile); @@ -158,7 +158,7 @@ class fib_data { vs[0] = vs[1] = vs[2] = 1.0; } - fib_data(image::geometry<3> dim_,image::vector<3> vs_):dim(dim_),vs(vs_){} + fib_data(tipl::geometry<3> dim_,tipl::vector<3> vs_):dim(dim_),vs(vs_){} public: bool load_from_file(const char* file_name); bool load_from_mat(void); @@ -171,7 +171,7 @@ class fib_data std::pair get_value_range(const std::string& view_name) const; void get_slice(unsigned int view_index, unsigned char d_index,unsigned int pos, - image::color_image& show_image,const image::value_to_color& v2c); + tipl::color_image& show_image,const tipl::value_to_color& v2c); void get_voxel_info2(unsigned int x,unsigned int y,unsigned int z,std::vector& buf) const; void get_voxel_information(int x,int y,int z,std::vector& buf) const; void get_index_titles(std::vector& titles); @@ -180,12 +180,12 @@ class fib_data class track_recognition{ - image::uniform_dist dist; + tipl::uniform_dist dist; public: - image::thread thread; + tipl::thread thread; public: - image::ml::network cnn; - image::ml::network_data cnn_data; + tipl::ml::network cnn; + tipl::ml::network_data cnn_data; std::vector cnn_name; std::string err_msg,msg; diff --git a/libs/tracking/interpolation_process.cpp b/libs/tracking/interpolation_process.cpp index 8856f8ae7..bf1f8f323 100644 --- a/libs/tracking/interpolation_process.cpp +++ b/libs/tracking/interpolation_process.cpp @@ -6,17 +6,17 @@ char fib_dx[80] = {0,0,1,0,0,1,1,1,1,1,1,1,1,0,0,2,0,0,0,0,1,1,1,1,2,2,2,2,1,1,1 char fib_dy[80] = {1,0,0,1,1,1,0,0,-1,1,1,-1,-1,2,0,0,2,2,1,1,2,0,0,-2,1,0,0,-1,2,2,1,1,-1,-1,-2,-2,1,1,-1,-1,-1,0,0,-1,-1,-1,0,0,1,-1,-1,1,1,-2,0,0,-2,-2,-1,-1,-2,0,0,2,-1,0,0,1,-2,-2,-1,-1,1,1,2,2,-1,-1,1,1}; char fib_dz[80] = {0,1,0,1,-1,0,1,-1,0,1,-1,1,-1,0,2,0,1,-1,2,-2,0,2,-2,0,0,1,-1,0,1,-1,2,-2,2,-2,1,-1,1,-1,1,-1,0,-1,0,-1,1,0,-1,1,0,-1,1,-1,1,0,-2,0,-1,1,-2,2,0,-2,2,0,0,-1,1,0,-1,1,-2,2,-2,2,-1,1,-1,1,-1,1}; bool trilinear_interpolation_with_gaussian_basis::evaluate(const tracking_data& fib, - const image::vector<3,float>& position, - const image::vector<3,float>& ref_dir, - image::vector<3,float>& result, + const tipl::vector<3,float>& position, + const tipl::vector<3,float>& ref_dir, + tipl::vector<3,float>& result, float threshold, float angle) { - image::interpolation tri_interpo; + tipl::interpolation tri_interpo; tri_interpo.weighting.sd = 0.5; if (!tri_interpo.get_location(fib.dim,position)) return false; - image::vector<3,float> new_dir,main_dir; + tipl::vector<3,float> new_dir,main_dir; float total_weighting = 0.0; float ww = std::accumulate(tri_interpo.ratio,tri_interpo.ratio+8,0.0)*0.5; for (unsigned int index = 0;index < 8;++index) @@ -38,16 +38,16 @@ bool trilinear_interpolation_with_gaussian_basis::evaluate(const tracking_data& bool trilinear_interpolation::evaluate(const tracking_data& fib, - const image::vector<3,float>& position, - const image::vector<3,float>& ref_dir, - image::vector<3,float>& result, + const tipl::vector<3,float>& position, + const tipl::vector<3,float>& ref_dir, + tipl::vector<3,float>& result, float threshold, float angle) { - image::interpolation tri_interpo; + tipl::interpolation tri_interpo; if (!tri_interpo.get_location(fib.dim,position)) return false; - image::vector<3,float> new_dir,main_dir; + tipl::vector<3,float> new_dir,main_dir; float total_weighting = 0.0; for (unsigned int index = 0;index < 8;++index) { @@ -67,9 +67,9 @@ bool trilinear_interpolation::evaluate(const tracking_data& fib, } bool nearest_direction::evaluate(const tracking_data& fib, - const image::vector<3,float>& position, - const image::vector<3,float>& ref_dir, - image::vector<3,float>& result, + const tipl::vector<3,float>& position, + const tipl::vector<3,float>& ref_dir, + tipl::vector<3,float>& result, float threshold, float angle) { @@ -78,7 +78,7 @@ bool nearest_direction::evaluate(const tracking_data& fib, int z = std::round(position[2]); if(!fib.dim.is_valid(x,y,z)) return false; - if(!fib.get_dir(image::pixel_index<3>(x,y,z,fib.dim).index(),ref_dir,result,threshold,angle)) + if(!fib.get_dir(tipl::pixel_index<3>(x,y,z,fib.dim).index(),ref_dir,result,threshold,angle)) return false; return true; } diff --git a/libs/tracking/interpolation_process.hpp b/libs/tracking/interpolation_process.hpp index 89c868a98..a8666a1f4 100644 --- a/libs/tracking/interpolation_process.hpp +++ b/libs/tracking/interpolation_process.hpp @@ -1,15 +1,15 @@ #ifndef INTERPOLATION_PROCESS_HPP #define INTERPOLATION_PROCESS_HPP #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" class tracking_data; class basic_interpolation { public: virtual bool evaluate(const tracking_data& fib, - const image::vector<3,float>& position, - const image::vector<3,float>& ref_dir, - image::vector<3,float>& result, + const tipl::vector<3,float>& position, + const tipl::vector<3,float>& ref_dir, + tipl::vector<3,float>& result, float threshold, float cull_cos_angle) = 0; }; @@ -18,9 +18,9 @@ class trilinear_interpolation_with_gaussian_basis : public basic_interpolation { public: virtual bool evaluate(const tracking_data& fib, - const image::vector<3,float>& position, - const image::vector<3,float>& ref_dir, - image::vector<3,float>& result, + const tipl::vector<3,float>& position, + const tipl::vector<3,float>& ref_dir, + tipl::vector<3,float>& result, float threshold, float cull_cos_angle); }; @@ -30,9 +30,9 @@ class trilinear_interpolation : public basic_interpolation { public: virtual bool evaluate(const tracking_data& fib, - const image::vector<3,float>& position, - const image::vector<3,float>& ref_dir, - image::vector<3,float>& result, + const tipl::vector<3,float>& position, + const tipl::vector<3,float>& ref_dir, + tipl::vector<3,float>& result, float threshold, float cull_cos_angle); }; @@ -42,9 +42,9 @@ class nearest_direction : public basic_interpolation { public: virtual bool evaluate(const tracking_data& fib, - const image::vector<3,float>& position, - const image::vector<3,float>& ref_dir, - image::vector<3,float>& result, + const tipl::vector<3,float>& position, + const tipl::vector<3,float>& ref_dir, + tipl::vector<3,float>& result, float threshold, float cull_cos_angle); }; diff --git a/libs/tracking/roi.hpp b/libs/tracking/roi.hpp index a756c0c89..c84445c2f 100644 --- a/libs/tracking/roi.hpp +++ b/libs/tracking/roi.hpp @@ -1,24 +1,24 @@ #ifndef ROI_HPP #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" class Roi { private: float ratio; - image::geometry<3> dim; + tipl::geometry<3> dim; std::vector > > roi_filter; bool in_range(int x,int y,int z) const { return dim.is_valid(x,y,z); } public: - Roi(const image::geometry<3>& geo,float r):ratio(r) + Roi(const tipl::geometry<3>& geo,float r):ratio(r) { if(r == 1.0) dim = geo; else - dim = image::geometry<3>(geo[0]*r,geo[1]*r,geo[2]*r); + dim = tipl::geometry<3>(geo[0]*r,geo[1]*r,geo[2]*r); roi_filter.resize(dim[0]); } void clear(void) @@ -26,7 +26,7 @@ class Roi { roi_filter.clear(); roi_filter.resize(dim[0]); } - void addPoint(const image::vector<3,short>& new_point) + void addPoint(const tipl::vector<3,short>& new_point) { if(in_range(new_point.x(),new_point.y(),new_point.z())) { @@ -60,7 +60,7 @@ class Roi { return false; return roi_filter[x][y][z] != 0; } - bool havePoint(const image::vector<3,float>& point) const + bool havePoint(const tipl::vector<3,float>& point) const { return havePoint(point[0],point[1],point[2]); } @@ -76,7 +76,7 @@ class Roi { class RoiMgr { public: std::string report; - std::vector > seeds; + std::vector > seeds; std::vector seeds_r; std::vector > inclusive; std::vector > end; @@ -92,14 +92,14 @@ class RoiMgr { report.clear(); } - bool is_excluded_point(const image::vector<3,float>& point) const + bool is_excluded_point(const tipl::vector<3,float>& point) const { for(unsigned int index = 0; index < exclusive.size(); ++index) if(exclusive[index]->havePoint(point[0],point[1],point[2])) return true; return false; } - bool is_terminate_point(const image::vector<3,float>& point) const + bool is_terminate_point(const tipl::vector<3,float>& point) const { for(unsigned int index = 0; index < terminate.size(); ++index) if(terminate[index]->havePoint(point[0],point[1],point[2])) @@ -108,8 +108,8 @@ class RoiMgr { } - bool fulfill_end_point(const image::vector<3,float>& point1, - const image::vector<3,float>& point2) const + bool fulfill_end_point(const tipl::vector<3,float>& point1, + const tipl::vector<3,float>& point2) const { if(end.empty()) return true; @@ -140,14 +140,14 @@ class RoiMgr { return false; return true; } - void setRegions(image::geometry<3> geo, - const std::vector >& points, + void setRegions(tipl::geometry<3> geo, + const std::vector >& points, float r, unsigned char type, const char* roi_name, - image::vector<3> voxel_size) + tipl::vector<3> voxel_size) { - image::vector<3,float> center; + tipl::vector<3,float> center; for(int i = 0;i < points.size();++i) center += points[i]; center /= points.size(); diff --git a/libs/tracking/tracking_method.hpp b/libs/tracking/tracking_method.hpp index e1f333c3d..e8b196593 100644 --- a/libs/tracking/tracking_method.hpp +++ b/libs/tracking/tracking_method.hpp @@ -6,7 +6,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "interpolation_process.hpp" #include "basic_process.hpp" #include "roi.hpp" @@ -151,9 +151,9 @@ class TrackingMethod{ private: std::auto_ptr interpolation; public:// Parameters - image::vector<3,float> position; - image::vector<3,float> dir; - image::vector<3,float> next_dir; + tipl::vector<3,float> position; + tipl::vector<3,float> dir; + tipl::vector<3,float> next_dir; bool terminated; bool forward; public: @@ -164,7 +164,7 @@ class TrackingMethod{ float current_step_size_in_voxel[3]; int current_min_steps3; int current_max_steps3; - void scaling_in_voxel(image::vector<3,float>& dir) const + void scaling_in_voxel(tipl::vector<3,float>& dir) const { dir[0] *= current_step_size_in_voxel[0]; dir[1] *= current_step_size_in_voxel[1]; @@ -188,9 +188,9 @@ class TrackingMethod{ { return (buffer_back_pos-buffer_front_pos)/3; } - bool get_dir(const image::vector<3,float>& position, - const image::vector<3,float>& ref_dir, - image::vector<3,float>& result_dir) + bool get_dir(const tipl::vector<3,float>& position, + const tipl::vector<3,float>& ref_dir, + tipl::vector<3,float>& result_dir) { return interpolation->evaluate(trk,position,ref_dir,result_dir,current_fa_threshold,current_tracking_angle); } @@ -222,14 +222,14 @@ class TrackingMethod{ template bool start_tracking(bool smoothing) { - image::vector<3,float> seed_pos(position); - image::vector<3,float> begin_dir(dir); + tipl::vector<3,float> seed_pos(position); + tipl::vector<3,float> begin_dir(dir); // floatd for full backward or full forward track_buffer.resize(current_max_steps3 << 1); reverse_buffer.resize(current_max_steps3 << 1); buffer_front_pos = current_max_steps3; buffer_back_pos = current_max_steps3; - image::vector<3,float> end_point1; + tipl::vector<3,float> end_point1; terminated = false; do { @@ -301,14 +301,14 @@ class TrackingMethod{ } bool init(unsigned char initial_direction, - const image::vector<3,float>& position_, + const tipl::vector<3,float>& position_, std::mt19937& seed) { std::uniform_real_distribution gen(0,1); position = position_; terminated = false; forward = true; - image::pixel_index<3> pindex(std::round(position[0]), + tipl::pixel_index<3> pindex(std::round(position[0]), std::round(position[1]), std::round(position[2]),trk.dim); if (!trk.dim.is_valid(pindex)) @@ -331,7 +331,7 @@ class TrackingMethod{ float x = std::sin(txy)*std::sin(tz); float y = std::cos(txy)*std::sin(tz); float z = std::cos(tz); - if (get_dir(position,image::vector<3,float>(x,y,z),dir)) + if (get_dir(position,tipl::vector<3,float>(x,y,z),dir)) return true; } return false; @@ -381,10 +381,10 @@ class TrackingMethod{ const float* get_result(void) const { - image::vector<3,float> head(&*(track_buffer.begin() + buffer_front_pos)); - image::vector<3,float> tail(&*(track_buffer.begin() + buffer_back_pos-3)); + tipl::vector<3,float> head(&*(track_buffer.begin() + buffer_front_pos)); + tipl::vector<3,float> tail(&*(track_buffer.begin() + buffer_back_pos-3)); tail -= head; - image::vector<3,float> abs_dis(std::abs(tail[0]),std::abs(tail[1]),std::abs(tail[2])); + tipl::vector<3,float> abs_dis(std::abs(tail[0]),std::abs(tail[1]),std::abs(tail[2])); if((abs_dis[0] > abs_dis[1] && abs_dis[0] > abs_dis[2] && tail[0] < 0) || (abs_dis[1] > abs_dis[0] && abs_dis[1] > abs_dis[2] && tail[1] < 0) || diff --git a/libs/tracking/tracking_thread.cpp b/libs/tracking/tracking_thread.cpp index 2cba749cc..cb97bdd36 100644 --- a/libs/tracking/tracking_thread.cpp +++ b/libs/tracking/tracking_thread.cpp @@ -73,7 +73,7 @@ void ThreadData::run_thread(TrackingMethod* method_ptr, if(param.center_seed) { if(!method->init(param.initial_direction, - image::vector<3,float>(roi_mgr.seeds[iteration].x()/roi_mgr.seeds_r[iteration], + tipl::vector<3,float>(roi_mgr.seeds[iteration].x()/roi_mgr.seeds_r[iteration], roi_mgr.seeds[iteration].y()/roi_mgr.seeds_r[iteration], roi_mgr.seeds[iteration].z()/roi_mgr.seeds_r[iteration]), seed)) @@ -90,7 +90,7 @@ void ThreadData::run_thread(TrackingMethod* method_ptr, std::lock_guard lock(lock_seed_function); iteration+=thread_count; unsigned int i = rand_gen(seed)*((float)roi_mgr.seeds.size()-1.0f); - image::vector<3,float> pos; + tipl::vector<3,float> pos; pos[0] = (float)roi_mgr.seeds[i].x() + rand_gen(seed)-0.5f; pos[1] = (float)roi_mgr.seeds[i].y() + rand_gen(seed)-0.5f; pos[2] = (float)roi_mgr.seeds[i].z() + rand_gen(seed)-0.5f; @@ -110,13 +110,13 @@ void ThreadData::run_thread(TrackingMethod* method_ptr, continue; if(result[2] > 0) // not the bottom slice { - image::vector<3> p0(result),p1(result+3); + tipl::vector<3> p0(result),p1(result+3); p1 -= p0; p0 -= p1; if(method->trk.is_white_matter(p0,white_matter_t)) continue; } - image::vector<3> p2(end-6),p3(end-3); + tipl::vector<3> p2(end-6),p3(end-3); if(*(end-1) > 0) // not the bottom slice { p2 -= p3; @@ -188,7 +188,7 @@ void ThreadData::run(const tracking_data& trk, return; if(param.threshold == 0.0f) { - float otsu = image::segmentation::otsu_threshold(image::make_image(trk.fa[0],trk.dim)); + float otsu = tipl::segmentation::otsu_threshold(tipl::make_image(trk.fa[0],trk.dim)); fa_threshold1 = (param.default_otsu-0.1f)*otsu; fa_threshold2 = (param.default_otsu+0.1f)*otsu; } diff --git a/libs/tracking/tract_cluster.cpp b/libs/tracking/tract_cluster.cpp index b3ae83fc4..7f3bbfe6d 100644 --- a/libs/tracking/tract_cluster.cpp +++ b/libs/tracking/tract_cluster.cpp @@ -1,6 +1,6 @@ #include #include "tract_cluster.hpp" -#include "image/image.hpp" +#include "tipl/tipl.hpp" struct compare_cluster { @@ -22,7 +22,7 @@ void BasicCluster::sort_cluster(void) TractCluster::TractCluster(const float* param):error_distance(param[3]) { - image::vector<3,float> fdim(param); + tipl::vector<3,float> fdim(param); fdim /= error_distance; fdim += 1.0; fdim.floor(); @@ -125,7 +125,7 @@ void TractCluster::add_tracts(const std::vector >& tracks) tract_length[tract_index] = tracks[tract_index].size(); // build passing points and ranged points - image::par_for(tracks.size(),[&](unsigned int tract_index) + tipl::par_for(tracks.size(),[&](unsigned int tract_index) { if(tracks[tract_index].empty()) return; @@ -137,15 +137,15 @@ void TractCluster::add_tracts(const std::vector >& tracks) for (;points_end != points;points += 3) { - image::vector<3,float> cur_point(points); + tipl::vector<3,float> cur_point(points); cur_point /= error_distance; cur_point.round(); if(!dim.is_valid(cur_point)) continue; - image::pixel_index<3> center(cur_point[0],cur_point[1],cur_point[2],dim); + tipl::pixel_index<3> center(cur_point[0],cur_point[1],cur_point[2],dim); passed_points.push_back(center.index() & 0xFFFF); - std::vector > iterations; - image::get_neighbors(center,dim,iterations); + std::vector > iterations; + tipl::get_neighbors(center,dim,iterations); for(unsigned int index = 0;index < iterations.size();++index) if (dim.is_valid(iterations[index])) ranged_points.push_back(iterations[index].index() & 0xFFFF); @@ -167,7 +167,7 @@ void TractCluster::add_tracts(const std::vector >& tracks) voxel_connection[tract_passed_voxels[tract_index].back()].push_back(tract_index); } - image::par_for(tracks.size(),[&](unsigned int tract_index) + tipl::par_for(tracks.size(),[&](unsigned int tract_index) { if(tracks[tract_index].empty()) return; diff --git a/libs/tracking/tract_cluster.hpp b/libs/tracking/tract_cluster.hpp index af523d35e..4988acb29 100644 --- a/libs/tracking/tract_cluster.hpp +++ b/libs/tracking/tract_cluster.hpp @@ -1,7 +1,7 @@ #ifndef TRACT_CLUSTER_HPP #define TRACT_CLUSTER_HPP #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include struct Cluster @@ -86,7 +86,7 @@ class FeatureBasedClutering : public BasicCluster class TractCluster : public BasicCluster { - image::geometry<3> dim; + tipl::geometry<3> dim; unsigned int w,wh; float error_distance; std::mutex lock_merge; diff --git a/libs/tracking/tract_model.cpp b/libs/tracking/tract_model.cpp index 69c72138b..f9fb3f765 100644 --- a/libs/tracking/tract_model.cpp +++ b/libs/tracking/tract_model.cpp @@ -42,11 +42,11 @@ void resample_tracks(const std::vector& track,std::vector& new_tra { if(track.size() < 6) return; - float step_size = image::vector<3>(track[0]-track[3],track[1]-track[4],track[2]-track[5]).length(); + float step_size = tipl::vector<3>(track[0]-track[3],track[1]-track[4],track[2]-track[5]).length(); if(std::fabs(step_size - interval)/interval < 0.1) return; float dis = interval; - image::vector<3> v1(&track[0]),v2,v3; + tipl::vector<3> v1(&track[0]),v2,v3; new_track.push_back(track[0]); new_track.push_back(track[1]); new_track.push_back(track[2]); @@ -56,7 +56,7 @@ void resample_tracks(const std::vector& track,std::vector& new_tra { if(new_step) { - v2 = image::vector<3>(&(track[i])); + v2 = tipl::vector<3>(&(track[i])); v3[0] = v2[0]-v1[0]; v3[1] = v2[1]-v1[1]; v3[2] = v2[2]-v1[2]; @@ -110,7 +110,7 @@ struct TrackVis int n_count;//Number of tract stored in this track file. 0 means the number was NOT stored. int version;//Version number. Current version is 1. int hdr_size;//Size of the header. Used to determine byte swap. Should be 1000. - void init(image::geometry<3> geometry_,const image::vector<3>& voxel_size_) + void init(tipl::geometry<3> geometry_,const tipl::vector<3>& voxel_size_) { id_string[0] = 'T'; id_string[1] = 'R'; @@ -318,7 +318,7 @@ bool TractModel::load_from_file(const char* file_name_,bool append) std::copy((const float*)&*buf.begin() + index, (const float*)&*buf.begin() + end, loaded_tract_data.back().begin()); - image::divide_constant(loaded_tract_data.back().begin(),loaded_tract_data.back().end(),handle->vs[0]); + tipl::divide_constant(loaded_tract_data.back().begin(),loaded_tract_data.back().end(),handle->vs[0]); index = end+3; } @@ -373,7 +373,7 @@ bool TractModel::save_data_to_file(const char* file_name,const std::string& inde } if (ext == std::string(".mat")) { - image::io::mat_write out(file_name); + tipl::io::mat_write out(file_name); if(!out) return false; std::vector buf; @@ -391,15 +391,15 @@ bool TractModel::save_data_to_file(const char* file_name,const std::string& inde return false; } //--------------------------------------------------------------------------- -bool TractModel::save_tracts_in_native_space(const char* file_name,image::basic_image,3 > native_position) +bool TractModel::save_tracts_in_native_space(const char* file_name,tipl::image,3 > native_position) { std::vector > keep_tract_data(tract_data); - image::par_for(tract_data.size(),[&](int i) + tipl::par_for(tract_data.size(),[&](int i) { for(int j = 0;j < tract_data[i].size();j += 3) { - image::vector<3> pos(&tract_data[i][0]+j),new_pos; - image::estimate(native_position,pos,new_pos); + tipl::vector<3> pos(&tract_data[i][0]+j),new_pos; + tipl::estimate(native_position,pos,new_pos); tract_data[i][j] = new_pos[0]; tract_data[i][j+1] = new_pos[1]; tract_data[i][j+2] = new_pos[2]; @@ -466,7 +466,7 @@ bool TractModel::save_tracts_to_file(const char* file_name_) } if (ext == std::string(".mat")) { - image::io::mat_write out(file_name.c_str()); + tipl::io::mat_write out(file_name.c_str()); if(!out) return false; std::vector buf; @@ -482,7 +482,7 @@ bool TractModel::save_tracts_to_file(const char* file_name_) } if (ext == std::string(".nii") || ext == std::string("i.gz")) { - std::vector >points; + std::vector >points; get_tract_points(points); ROIRegion region(handle); region.add_points(points,false); @@ -506,9 +506,9 @@ void TractModel::save_vrml(const char* file_name, - std::vector > points(8),previous_points(8); - image::rgb_color paint_color; - image::vector<3,float> paint_color_f; + std::vector > points(8),previous_points(8); + tipl::rgb paint_color; + tipl::vector<3,float> paint_color_f; const float detail_option[] = {1.0,0.5,0.25,0.0,0.0}; float tube_detail = tube_diameter*detail_option[tract_tube_detail]*4.0; @@ -528,19 +528,19 @@ void TractModel::save_vrml(const char* file_name, { case 1: paint_color = get_tract_color(data_index); - paint_color_f = image::vector<3,float>(paint_color.r,paint_color.g,paint_color.b); + paint_color_f = tipl::vector<3,float>(paint_color.r,paint_color.g,paint_color.b); paint_color_f /= 255.0; break; break; } unsigned int prev_coordinate_count = vrml_coordinate_count; - image::vector<3,float> last_pos(data_iter), + tipl::vector<3,float> last_pos(data_iter), vec_a(1,0,0),vec_b(0,1,0), vec_n,prev_vec_n,vec_ab,vec_ba,cur_color; for (unsigned int j = 0, index = 0; index < vertex_count;j += 3, data_iter += 3, ++index) { - image::vector<3,float> pos(data_iter); + tipl::vector<3,float> pos(data_iter); if (index + 1 < vertex_count) { vec_n[0] = data_iter[3] - data_iter[0]; @@ -563,7 +563,7 @@ void TractModel::save_vrml(const char* file_name, if (index != 0 && index+1 != vertex_count) { - image::vector<3,float> displacement(data_iter+3); + tipl::vector<3,float> displacement(data_iter+3); displacement -= last_pos; displacement -= prev_vec_n*(prev_vec_n*displacement); if (displacement.length() < tube_detail) @@ -771,7 +771,7 @@ bool TractModel::save_all(const char* file_name_,const std::vector& if (ext == std::string(".mat")) { - image::io::mat_write out(file_name.c_str()); + tipl::io::mat_write out(file_name.c_str()); if(!out) return false; std::vector buf; @@ -797,8 +797,8 @@ bool TractModel::save_transformed_tracts_to_file(const char* file_name,const flo std::vector > new_tract_data(tract_data); for(unsigned int i = 0;i < tract_data.size();++i) for(unsigned int j = 0;j < tract_data[i].size();j += 3) - image::vector_transformation(&(new_tract_data[i][j]), - &(tract_data[i][j]),transform,image::vdim<3>()); + tipl::vector_transformation(&(new_tract_data[i][j]), + &(tract_data[i][j]),transform,tipl::vdim<3>()); bool result = true; if(end_point) save_end_points(file_name); @@ -821,7 +821,7 @@ bool TractModel::load_tracts_color_from_file(const char* file_name) std::copy(colors.begin(),colors.begin()+colors.size(),tract_color.begin()); if(colors.size()/3 <= tract_color.size()) for(unsigned int index = 0,pos = 0;pos+2 < colors.size();++index,pos += 3) - tract_color[index] = image::rgb_color(std::min(colors[pos],255), + tract_color[index] = tipl::rgb(std::min(colors[pos],255), std::min(colors[pos+1],255), std::min(colors[pos+2],255)); return true; @@ -834,7 +834,7 @@ bool TractModel::save_tracts_color_to_file(const char* file_name) return false; for(unsigned int index = 0;index < tract_color.size();++index) { - image::rgb_color color; + tipl::rgb color; color.color = tract_color[index]; out << (int)color.r << " " << (int)color.g << " " << (int)color.b << std::endl; } @@ -891,7 +891,7 @@ void TractModel::save_end_points(const char* file_name_) const } if (file_name.find(".mat") != std::string::npos) { - image::io::mat_write out(file_name_); + tipl::io::mat_write out(file_name_); if(!out) return; out.write("end_points",(const float*)&*buffer.begin(),3,buffer.size()/3); @@ -899,38 +899,38 @@ void TractModel::save_end_points(const char* file_name_) const } //--------------------------------------------------------------------------- -void TractModel::get_end_points(std::vector >& points) +void TractModel::get_end_points(std::vector >& points) { for (unsigned int index = 0;index < tract_data.size();++index) { if (tract_data[index].size() < 3) return; - points.push_back(image::vector<3,float>(&tract_data[index][0])); - points.push_back(image::vector<3,float>(&tract_data[index][tract_data[index].size()-3])); + points.push_back(tipl::vector<3,float>(&tract_data[index][0])); + points.push_back(tipl::vector<3,float>(&tract_data[index][tract_data[index].size()-3])); } } //--------------------------------------------------------------------------- -void TractModel::get_tract_points(std::vector >& points) +void TractModel::get_tract_points(std::vector >& points) { for (unsigned int index = 0;index < tract_data.size();++index) for (unsigned int j = 0;j < tract_data[index].size();j += 3) { - image::vector<3,float> point(&tract_data[index][j]); + tipl::vector<3,float> point(&tract_data[index][j]); points.push_back(point); } } //--------------------------------------------------------------------------- void TractModel::select(float select_angle, - const std::vector >& dirs, - const image::vector<3,float>& from_pos,std::vector& selected) + const std::vector >& dirs, + const tipl::vector<3,float>& from_pos,std::vector& selected) { selected.resize(tract_data.size()); std::fill(selected.begin(),selected.end(),0); for(int i = 1;i < dirs.size();++i) { - image::vector<3,float> from_dir = dirs[i-1]; - image::vector<3,float> to_dir = (i+1 < dirs.size() ? dirs[i+1] : dirs[i]); - image::vector<3,float> z_axis = from_dir.cross_product(to_dir); + tipl::vector<3,float> from_dir = dirs[i-1]; + tipl::vector<3,float> to_dir = (i+1 < dirs.size() ? dirs[i+1] : dirs[i]); + tipl::vector<3,float> z_axis = from_dir.cross_product(to_dir); z_axis.normalize(); float view_angle = from_dir*to_dir; @@ -943,7 +943,7 @@ void TractModel::select(float select_angle, const float* end = ptr + tract_data[index].size(); for (;ptr < end;ptr += 3) { - image::vector<3,float> p(ptr); + tipl::vector<3,float> p(ptr); p -= from_pos; float next_angle = z_axis*p; if ((angle < 0.0 && next_angle >= 0.0) || @@ -956,7 +956,7 @@ void TractModel::select(float select_angle, { if(select_angle != 0.0) { - image::vector<3,float> p1(ptr),p2(ptr-3); + tipl::vector<3,float> p1(ptr),p2(ptr-3); p1 -= p2; p1.normalize(); if(std::abs(p1*z_axis) < select_angle_cos) @@ -1034,7 +1034,7 @@ void TractModel::delete_repeated(double d) { auto norm1 = [](const float* v1,const float* v2){return std::fabs(v1[0]-v2[0])+std::fabs(v1[1]-v2[1])+std::fabs(v1[2]-v2[2]);}; std::vector repeated(tract_data.size()); - image::par_for(tract_data.size(),[&](int i) + tipl::par_for(tract_data.size(),[&](int i) { if(!repeated[i]) { @@ -1092,7 +1092,7 @@ void TractModel::delete_by_length(float length) track_to_delete.push_back(i); continue; } - image::vector<3> v1(&tract_data[i][0]),v2(&tract_data[i][3]); + tipl::vector<3> v1(&tract_data[i][0]),v2(&tract_data[i][3]); v1 -= v2; if((((tract_data[i].size()/3)-1)*v1.length()) < length) track_to_delete.push_back(i); @@ -1100,8 +1100,8 @@ void TractModel::delete_by_length(float length) delete_tracts(track_to_delete); } //--------------------------------------------------------------------------- -void TractModel::cut(float select_angle,const std::vector >& dirs, - const image::vector<3,float>& from_pos) +void TractModel::cut(float select_angle,const std::vector >& dirs, + const tipl::vector<3,float>& from_pos) { std::vector selected; select(select_angle,dirs,from_pos,selected); @@ -1178,10 +1178,10 @@ void TractModel::filter_by_roi(RoiMgr& roi_mgr) if(tract_data[index].size() >= 6) { if(!roi_mgr.have_include(&(tract_data[index][0]),tract_data[index].size()) || - !roi_mgr.fulfill_end_point(image::vector<3,float>(tract_data[index][0], + !roi_mgr.fulfill_end_point(tipl::vector<3,float>(tract_data[index][0], tract_data[index][1], tract_data[index][2]), - image::vector<3,float>(tract_data[index][tract_data[index].size()-3], + tipl::vector<3,float>(tract_data[index][tract_data[index].size()-3], tract_data[index][tract_data[index].size()-2], tract_data[index][tract_data[index].size()-1]))) { @@ -1191,7 +1191,7 @@ void TractModel::filter_by_roi(RoiMgr& roi_mgr) if(!roi_mgr.exclusive.empty()) { for(unsigned int i = 0;i < tract_data[index].size();i+=3) - if(roi_mgr.is_excluded_point(image::vector<3,float>(tract_data[index][i], + if(roi_mgr.is_excluded_point(tipl::vector<3,float>(tract_data[index][i], tract_data[index][i+1], tract_data[index][i+2]))) { @@ -1204,8 +1204,8 @@ void TractModel::filter_by_roi(RoiMgr& roi_mgr) } //--------------------------------------------------------------------------- void TractModel::cull(float select_angle, - const std::vector >& dirs, - const image::vector<3,float>& from_pos, + const std::vector >& dirs, + const tipl::vector<3,float>& from_pos, bool delete_track) { std::vector selected; @@ -1219,8 +1219,8 @@ void TractModel::cull(float select_angle, } //--------------------------------------------------------------------------- void TractModel::paint(float select_angle, - const std::vector >& dirs, - const image::vector<3,float>& from_pos, + const std::vector >& dirs, + const tipl::vector<3,float>& from_pos, unsigned int color) { std::vector selected; @@ -1237,9 +1237,9 @@ void TractModel::cut_by_mask(const char*) std::ifstream in(file_name,std::ios::in); if(!in) return; - std::set > mask( - (std::istream_iterator > (in)), - (std::istream_iterator > ())); + std::set > mask( + (std::istream_iterator > (in)), + (std::istream_iterator > ())); std::vector > new_data; for (unsigned int index = 0;check_prog(index,tract_data.size());++index) { @@ -1248,7 +1248,7 @@ void TractModel::cut_by_mask(const char*) std::vector::const_iterator end = tract_data[index].end(); for (;iter < end;iter += 3) { - image::vector<3,short> p(std::round(iter[0]), + tipl::vector<3,short> p(std::round(iter[0]), std::round(iter[1]),std::round(iter[2])); if (mask.find(p) == mask.end()) @@ -1282,7 +1282,7 @@ bool TractModel::trim(void) /* std::vector continuous(tract_data.size()); float epsilon = 2.0f; - image::par_for(tract_data.size(),[&](int i) + tipl::par_for(tract_data.size(),[&](int i) { if(tract_data[i].empty() || continuous[i]) return; @@ -1295,12 +1295,12 @@ bool TractModel::trim(void) const float* t2 = &tract_data[j][0]; const float* t2_end = &tract_data[j][tract_data[j].size()-3]; if(std::min( - image::vector<3>(t1[0]-t2[0],t1[1]-t2[1],t1[2]-t2[2]).length(), - image::vector<3>(t1[0]-t2_end[0],t1[1]-t2_end[1],t1[2]-t2_end[2]).length()) > epsilon) + tipl::vector<3>(t1[0]-t2[0],t1[1]-t2[1],t1[2]-t2[2]).length(), + tipl::vector<3>(t1[0]-t2_end[0],t1[1]-t2_end[1],t1[2]-t2_end[2]).length()) > epsilon) continue; if(std::min( - image::vector<3>(t1_end[0]-t2[0],t1_end[1]-t2[1],t1_end[2]-t2[2]).length(), - image::vector<3>(t1_end[0]-t2_end[0],t1_end[1]-t2_end[1],t1_end[2]-t2_end[2]).length()) > epsilon) + tipl::vector<3>(t1_end[0]-t2[0],t1_end[1]-t2[1],t1_end[2]-t2[2]).length(), + tipl::vector<3>(t1_end[0]-t2_end[0],t1_end[1]-t2_end[1],t1_end[2]-t2_end[2]).length()) > epsilon) continue; unsigned int length1 = tract_data[i].size()-3; unsigned int length2 = tract_data[j].size()-3; @@ -1310,7 +1310,7 @@ bool TractModel::trim(void) { bool has_c = false; for(int n = 3;n < length2;n += 3) - if(image::vector<3>(t1[m]-t2[n],t1[m+1]-t2[n+1],t1[m+2]-t2[n+2]).length() < epsilon) + if(tipl::vector<3>(t1[m]-t2[n],t1[m+1]-t2[n+1],t1[m+2]-t2[n+2]).length() < epsilon) { has_c = true; break; @@ -1337,7 +1337,7 @@ bool TractModel::trim(void) delete_tracts(tracts_to_delete); */ - image::basic_image label(geometry); + tipl::image label(geometry); int total_track_number = tract_data.size(); @@ -1350,7 +1350,7 @@ bool TractModel::trim(void) int wh = width*height; std::fill(label.begin(),label.end(),no_fiber_label); int shift[8] = {0,1,width,wh,1+width,1+wh,width+wh,1+width+wh}; - image::par_for(total_track_number,[&](int index) + tipl::par_for(total_track_number,[&](int index) { const float* ptr = &*tract_data[index].begin(); const float* end = ptr + tract_data[index].size(); @@ -1449,10 +1449,10 @@ void TractModel::redo(void) //--------------------------------------------------------------------------- void TractModel::add_tracts(std::vector >& new_tracks) { - add_tracts(new_tracks,tract_color.empty() ? image::rgb_color(255,160,60) : image::rgb_color(tract_color.back())); + add_tracts(new_tracks,tract_color.empty() ? tipl::rgb(255,160,60) : tipl::rgb(tract_color.back())); } //--------------------------------------------------------------------------- -void TractModel::add_tracts(std::vector >& new_tract,image::rgb_color color) +void TractModel::add_tracts(std::vector >& new_tract,tipl::rgb color) { tract_data.reserve(tract_data.size()+new_tract.size()); @@ -1469,7 +1469,7 @@ void TractModel::add_tracts(std::vector >& new_tract,image::r void TractModel::add_tracts(std::vector >& new_tract, unsigned int length_threshold) { tract_data.reserve(tract_data.size()+new_tract.size()/2.0); - image::rgb_color def_color(200,100,30); + tipl::rgb def_color(200,100,30); for (unsigned int index = 0;index < new_tract.size();++index) { if (new_tract[index].size()/3-1 < length_threshold) @@ -1480,10 +1480,10 @@ void TractModel::add_tracts(std::vector >& new_tract, unsigne } } //--------------------------------------------------------------------------- -void TractModel::get_density_map(image::basic_image& mapping, - const image::matrix<4,4,float>& transformation,bool endpoint) +void TractModel::get_density_map(tipl::image& mapping, + const tipl::matrix<4,4,float>& transformation,bool endpoint) { - image::geometry<3> geometry = mapping.geometry(); + tipl::geometry<3> geometry = mapping.geometry(); begin_prog("calculating"); for (unsigned int i = 0;check_prog(i,tract_data.size());++i) { @@ -1492,9 +1492,9 @@ void TractModel::get_density_map(image::basic_image& mapping, { if(j && endpoint) j = tract_data[i].size()-3; - image::vector<3,float> tmp; - image::vector_transformation(tract_data[i].begin()+j, tmp.begin(), - transformation.begin(), image::vdim<3>()); + tipl::vector<3,float> tmp; + tipl::vector_transformation(tract_data[i].begin()+j, tmp.begin(), + transformation.begin(), tipl::vdim<3>()); int x = std::round(tmp[0]); int y = std::round(tmp[1]); @@ -1511,11 +1511,11 @@ void TractModel::get_density_map(image::basic_image& mapping, } //--------------------------------------------------------------------------- void TractModel::get_density_map( - image::basic_image& mapping, - const image::matrix<4,4,float>& transformation,bool endpoint) + tipl::image& mapping, + const tipl::matrix<4,4,float>& transformation,bool endpoint) { - image::geometry<3> geometry = mapping.geometry(); - image::basic_image map_r(geometry), + tipl::geometry<3> geometry = mapping.geometry(); + tipl::image map_r(geometry), map_g(geometry),map_b(geometry); for (unsigned int i = 0;i < tract_data.size();++i) { @@ -1524,11 +1524,11 @@ void TractModel::get_density_map( { if(j > 3 && endpoint) j = tract_data[i].size()-3; - image::vector<3,float> tmp,dir; - image::vector_transformation(buf+j-3, dir.begin(), - transformation.begin(), image::vdim<3>()); - image::vector_transformation(buf+j, tmp.begin(), - transformation.begin(), image::vdim<3>()); + tipl::vector<3,float> tmp,dir; + tipl::vector_transformation(buf+j-3, dir.begin(), + transformation.begin(), tipl::vdim<3>()); + tipl::vector_transformation(buf+j, tmp.begin(), + transformation.begin(), tipl::vdim<3>()); dir -= tmp; dir.normalize(); int x = std::round(tmp[0]); @@ -1551,10 +1551,10 @@ void TractModel::get_density_map( float sum = map_r[index]+map_g[index]+map_b[index]; if(sum == 0.0f) continue; - image::vector<3> v(map_r[index],map_g[index],map_b[index]); + tipl::vector<3> v(map_r[index],map_g[index],map_b[index]); sum = v.normalize(); v*=255.0*std::log(200.0f*sum/max_value+1)/2.303f; - mapping[index] = image::rgb_color( + mapping[index] = tipl::rgb( (unsigned char)std::min(255,v[0]), (unsigned char)std::min(255,v[1]), (unsigned char)std::min(255,v[2])); @@ -1563,16 +1563,16 @@ void TractModel::get_density_map( void TractModel::save_tdi(const char* file_name,bool sub_voxel,bool endpoint,const std::vector& trans) { - image::matrix<4,4,float> tr; + tipl::matrix<4,4,float> tr; tr.zero(); tr[0] = tr[5] = tr[10] = tr[15] = (sub_voxel ? 4.0:1.0); - image::vector<3,float> new_vs(vs); + tipl::vector<3,float> new_vs(vs); if(sub_voxel) new_vs /= 4.0; - image::basic_image tdi; + tipl::image tdi; if(sub_voxel) - tdi.resize(image::geometry<3>(geometry[0]*4,geometry[1]*4,geometry[2]*4)); + tdi.resize(tipl::geometry<3>(geometry[0]*4,geometry[1]*4,geometry[2]*4)); else tdi.resize(geometry); @@ -1592,7 +1592,7 @@ void TractModel::save_tdi(const char* file_name,bool sub_voxel,bool endpoint,con else nii_header.set_LPS_transformation(trans.begin(),tdi.geometry()); } - image::flip_xy(tdi); + tipl::flip_xy(tdi); nii_header << tdi; nii_header.save_to_file(file_name); @@ -1616,7 +1616,7 @@ void TractModel::get_quantitative_data(std::vector& data) float length = 0.0; for (unsigned int j = 3;j < tract_data[i].size();j += 3) { - length += image::vector<3,float>( + length += tipl::vector<3,float>( vs[0]*(tract_data[i][j]-tract_data[i][j-3]), vs[1]*(tract_data[i][j+1]-tract_data[i][j-2]), vs[2]*(tract_data[i][j+2]-tract_data[i][j-1])).length(); @@ -1634,10 +1634,10 @@ void TractModel::get_quantitative_data(std::vector& data) // tract volume { - std::set > pass_map; + std::set > pass_map; for (unsigned int i = 0;i < tract_data.size();++i) for (unsigned int j = 0;j < tract_data[i].size();j += 3) - pass_map.insert(image::vector<3,int>(std::round(tract_data[i][j]), + pass_map.insert(tipl::vector<3,int>(std::round(tract_data[i][j]), std::round(tract_data[i][j+1]), std::round(tract_data[i][j+2]))); @@ -1700,17 +1700,17 @@ bool TractModel::recognize(std::map >& res if(!track_network.can_recognize()) return false; std::vector accu_input(track_network.cnn.get_output_size()); - image::par_for(tract_data.size(),[&](int i) + tipl::par_for(tract_data.size(),[&](int i) { std::vector input; if(!handle->get_profile(tract_data[i],input)) return; track_network.cnn.predict(input); - image::minus_constant(input,*std::min_element(input.begin(),input.end())); - image::multiply_constant(input,1.0f/std::accumulate(input.begin(),input.end(),0.0f)); - image::add(accu_input,input); + tipl::minus_constant(input,*std::min_element(input.begin(),input.end())); + tipl::multiply_constant(input,1.0f/std::accumulate(input.begin(),input.end(),0.0f)); + tipl::add(accu_input,input); }); - image::multiply_constant(accu_input,1.0f/std::accumulate(accu_input.begin(),accu_input.end(),0.0f)); + tipl::multiply_constant(accu_input,1.0f/std::accumulate(accu_input.begin(),accu_input.end(),0.0f)); for(int i = 0;i < accu_input.size();++i) result[accu_input[i]] = track_network.track_name[i]; return true; @@ -1721,15 +1721,15 @@ void TractModel::recognize_report(std::string& report) /* if(track_atlas) { - image::vector<3> dummy; + tipl::vector<3> dummy; track_atlas->is_labeled_as(dummy,0);// invoke loading file std::vector recog_count(track_atlas->get_list().size()); - image::par_for(tract_data.size(),[&](int i) + tipl::par_for(tract_data.size(),[&](int i) { - std::vector > points; + std::vector > points; for(int j = 0;j < tract_data[i].size();j += 3) { - points.push_back(image::vector<3>(&(tract_data[i][j]))); + points.push_back(tipl::vector<3>(&(tract_data[i][j]))); handle->subject2mni(points.back()); } int result = track_atlas->get_track_label(points); @@ -1763,7 +1763,7 @@ void TractModel::recognize_report(std::string& report) if(!handle->is_human_data || !track_network.can_recognize()) return; std::vector recog_count(track_network.cnn.get_output_size()); - image::par_for(tract_data.size(),[&](int i) + tipl::par_for(tract_data.size(),[&](int i) { std::vector input; if(!handle->get_profile(tract_data[i],input)) @@ -1833,7 +1833,7 @@ void TractModel::get_report(unsigned int profile_dir,float band_width,const std: data_profile_w.resize(data.size()); for(unsigned int index = 0;index < data_profile.size();++index) { - data_profile[index] = image::mean(data[index].begin(),data[index].end()); + data_profile[index] = tipl::mean(data[index].begin(),data[index].end()); data_profile_w[index] = 1.0; } } @@ -1919,14 +1919,14 @@ void TractModel::get_tract_data(unsigned int fiber_index,unsigned int index_num, // track specific index if(index_num < fib->other_index.size()) { - auto base_image = image::make_image(fib->other_index[index_num][0],fib->dim); - std::vector > gradient(count); + auto base_image = tipl::make_image(fib->other_index[index_num][0],fib->dim); + std::vector > gradient(count); const float (*tract_ptr)[3] = (const float (*)[3])&(tract_data[fiber_index][0]); ::gradient(tract_ptr,tract_ptr+count,gradient.begin()); for (unsigned int point_index = 0,tract_index = 0; point_index < count;++point_index,tract_index += 3) { - image::interpolation tri_interpo; + tipl::interpolation tri_interpo; gradient[point_index].normalize(); if (tri_interpo.get_location(fib->dim,&(tract_data[fiber_index][tract_index]))) { @@ -1942,10 +1942,10 @@ void TractModel::get_tract_data(unsigned int fiber_index,unsigned int index_num, if (sum_value > 0.5) data[point_index] = average_value/sum_value; else - image::estimate(base_image,&(tract_data[fiber_index][tract_index]),data[point_index],image::linear); + tipl::estimate(base_image,&(tract_data[fiber_index][tract_index]),data[point_index],tipl::linear); } else - image::estimate(base_image,&(tract_data[fiber_index][tract_index]),data[point_index],image::linear); + tipl::estimate(base_image,&(tract_data[fiber_index][tract_index]),data[point_index],tipl::linear); } } else @@ -1955,14 +1955,14 @@ void TractModel::get_tract_data(unsigned int fiber_index,unsigned int index_num, { for (unsigned int data_index = 0,index = 0;index < tract_data[fiber_index].size();index += 3,++data_index) { - image::vector<3> pos(&(tract_data[fiber_index][index])); + tipl::vector<3> pos(&(tract_data[fiber_index][index])); pos.to(handle->view_item[index_num].iT); - image::estimate(handle->view_item[index_num].image_data,pos,data[data_index],image::linear); + tipl::estimate(handle->view_item[index_num].image_data,pos,data[data_index],tipl::linear); } } else for (unsigned int data_index = 0,index = 0;index < tract_data[fiber_index].size();index += 3,++data_index) - image::estimate(handle->view_item[index_num].image_data,&(tract_data[fiber_index][index]),data[data_index],image::linear); + tipl::estimate(handle->view_item[index_num].image_data,&(tract_data[fiber_index][index]),data[data_index],tipl::linear); } } @@ -2002,8 +2002,8 @@ void TractModel::get_tracts_data(unsigned int data_index,float& mean, float& sd) } // return region overlapped ratio -float create_region_map(const image::geometry<3>& geometry, - const std::vector > >& regions, +float create_region_map(const tipl::geometry<3>& geometry, + const std::vector > >& regions, std::vector >& region_map) { std::vector > regions_set(geometry.size()); @@ -2012,9 +2012,9 @@ float create_region_map(const image::geometry<3>& geometry, { for(unsigned int index = 0;index < regions[roi].size();++index) { - image::vector<3,short> pos = regions[roi][index]; + tipl::vector<3,short> pos = regions[roi][index]; if(geometry.is_valid(pos)) - regions_set[image::pixel_index<3>(pos[0],pos[1],pos[2],geometry).index()].insert(roi); + regions_set[tipl::pixel_index<3>(pos[0],pos[1],pos[2],geometry).index()].insert(roi); } } @@ -2031,7 +2031,7 @@ float create_region_map(const image::geometry<3>& geometry, return (float)overlap_count/(float)total_count; } -void TractModel::get_passing_list(const std::vector > >& regions, +void TractModel::get_passing_list(const std::vector > >& regions, std::vector >& passing_list1, std::vector >& passing_list2, float& overlap_ratio) const @@ -2052,7 +2052,7 @@ void TractModel::get_passing_list(const std::vector pos(std::round(tract_data[index][ptr]), + tipl::pixel_index<3> pos(std::round(tract_data[index][ptr]), std::round(tract_data[index][ptr+1]), std::round(tract_data[index][ptr+2]),geometry); if(!geometry.is_valid(pos)) @@ -2071,7 +2071,7 @@ void TractModel::get_passing_list(const std::vector > >& regions, +void TractModel::get_end_list(const std::vector > >& regions, std::vector >& end_pair1, std::vector >& end_pair2, float& overlap_ratio) const @@ -2088,10 +2088,10 @@ void TractModel::get_end_list(const std::vector end1(std::round(tract_data[index][0]), + tipl::pixel_index<3> end1(std::round(tract_data[index][0]), std::round(tract_data[index][1]), std::round(tract_data[index][2]),geometry); - image::pixel_index<3> end2(std::round(tract_data[index][tract_data[index].size()-3]), + tipl::pixel_index<3> end2(std::round(tract_data[index][tract_data[index].size()-3]), std::round(tract_data[index][tract_data[index].size()-2]), std::round(tract_data[index][tract_data[index].size()-1]),geometry); if(!geometry.is_valid(end1) || !geometry.is_valid(end2)) @@ -2120,10 +2120,10 @@ void TractModel::run_clustering(unsigned char method_id,unsigned int cluster_cou c.reset(new TractCluster(param)); break; case 1: - c.reset(new FeatureBasedClutering >(param)); + c.reset(new FeatureBasedClutering >(param)); break; case 2: - c.reset(new FeatureBasedClutering >(param)); + c.reset(new FeatureBasedClutering >(param)); break; case 3: { @@ -2131,7 +2131,7 @@ void TractModel::run_clustering(unsigned char method_id,unsigned int cluster_cou std::fill(tract_cluster.begin(),tract_cluster.end(),80); if(!track_network.can_recognize()) return; - image::par_for(tract_data.size(),[&](int i) + tipl::par_for(tract_data.size(),[&](int i) { std::vector input; if(!handle->get_profile(tract_data[i],input)) @@ -2158,23 +2158,23 @@ void TractModel::run_clustering(unsigned char method_id,unsigned int cluster_cou } } -void ConnectivityMatrix::save_to_image(image::color_image& cm) +void ConnectivityMatrix::save_to_image(tipl::color_image& cm) { if(matrix_value.empty()) return; cm.resize(matrix_value.geometry()); std::vector values(matrix_value.size()); std::copy(matrix_value.begin(),matrix_value.end(),values.begin()); - image::normalize(values,255.99f); + tipl::normalize(values,255.99f); for(unsigned int index = 0;index < values.size();++index) { - cm[index] = image::rgb_color((unsigned char)values[index],(unsigned char)values[index],(unsigned char)values[index]); + cm[index] = tipl::rgb((unsigned char)values[index],(unsigned char)values[index],(unsigned char)values[index]); } } void ConnectivityMatrix::save_to_file(const char* file_name) { - image::io::mat_write mat_header(file_name); + tipl::io::mat_write mat_header(file_name); mat_header.write("connectivity",&*matrix_value.begin(),matrix_value.width(),matrix_value.height()); std::ostringstream out; std::copy(region_name.begin(),region_name.end(),std::ostream_iterator(out,"\n")); @@ -2223,20 +2223,20 @@ void ConnectivityMatrix::save_to_connectogram(const char* file_name) } } -void ConnectivityMatrix::set_atlas(atlas& data,const image::basic_image,3 >& mni_position) +void ConnectivityMatrix::set_atlas(atlas& data,const tipl::image,3 >& mni_position) { if(mni_position.empty()) return; - image::geometry<3> geo(mni_position.geometry()); - image::vector<3> null; + tipl::geometry<3> geo(mni_position.geometry()); + tipl::vector<3> null; regions.clear(); region_name.clear(); for (unsigned int label_index = 0; label_index < data.get_list().size(); ++label_index) { - std::vector > cur_region; - for (image::pixel_index<3> index(geo); index < geo.size();++index) + std::vector > cur_region; + for (tipl::pixel_index<3> index(geo); index < geo.size();++index) if(mni_position[index.index()] != null && data.is_labeled_as(mni_position[index.index()],label_index)) - cur_region.push_back(image::vector<3,short>(index.begin())); + cur_region.push_back(tipl::vector<3,short>(index.begin())); regions.push_back(cur_region); region_name.push_back(data.get_list()[label_index]); } @@ -2310,7 +2310,7 @@ bool ConnectivityMatrix::calculate(TractModel& tract_model,std::string matrix_va return true; } matrix_value.clear(); - matrix_value.resize(image::geometry<2>(regions.size(),regions.size())); + matrix_value.resize(tipl::geometry<2>(regions.size(),regions.size())); std::vector > count; init_matrix(count,regions.size()); @@ -2349,7 +2349,7 @@ bool ConnectivityMatrix::calculate(TractModel& tract_model,std::string matrix_va { float length = 0.0; if(matrix_value_type == "ncount") - length = 1.0f/image::median(length_matrix[i][j].begin(),length_matrix[i][j].end()); + length = 1.0f/tipl::median(length_matrix[i][j].begin(),length_matrix[i][j].end()); else { for(int k = 0;k < length_matrix[i][j].size();++k) @@ -2394,7 +2394,7 @@ bool ConnectivityMatrix::calculate(TractModel& tract_model,std::string matrix_va std::vector m(data.size()); for(unsigned int index = 0;index < data.size();++index) - m[index] = image::mean(data[index].begin(),data[index].end()); + m[index] = tipl::mean(data[index].begin(),data[index].end()); for_each_connectivity(end_list1,end_list2, [&](unsigned int index,short i,short j){ @@ -2409,17 +2409,17 @@ bool ConnectivityMatrix::calculate(TractModel& tract_model,std::string matrix_va } template -void distance_bin(const matrix_type& bin,image::basic_image& D) +void distance_bin(const matrix_type& bin,tipl::image& D) { unsigned int n = bin.width(); - image::basic_image A,Lpath; + tipl::image A,Lpath; A = bin; Lpath = bin; D = bin; for(unsigned int l = 2;1;++l) { - image::basic_image t(A.geometry()); - image::mat::product(Lpath.begin(),A.begin(),t.begin(),image::dyndim(n,n),image::dyndim(n,n)); + tipl::image t(A.geometry()); + tipl::mat::product(Lpath.begin(),A.begin(),t.begin(),tipl::dyndim(n,n),tipl::dyndim(n,n)); std::swap(Lpath,t); bool con = false; for(unsigned int i = 0;i < D.size();++i) @@ -2434,9 +2434,9 @@ void distance_bin(const matrix_type& bin,image::basic_image& D) std::replace(D.begin(),D.end(),(float)0,std::numeric_limits::max()); } template -void distance_wei(const matrix_type& W_,image::basic_image& D) +void distance_wei(const matrix_type& W_,tipl::image& D) { - image::basic_image W(W_); + tipl::image W(W_); for(unsigned int i = 0;i < W.size();++i) W[i] = (W[i] != 0) ? 1.0/W[i]:0; unsigned int n = W.width(); @@ -2448,7 +2448,7 @@ void distance_wei(const matrix_type& W_,image::basic_image& D) for(unsigned int i = 0,in = 0;i < n;++i,in += n) { std::vector S(n); - image::basic_image W1(W); + tipl::image W1(W); std::vector V; V.push_back(i); @@ -2507,8 +2507,8 @@ void ConnectivityMatrix::network_property(std::string& report) { std::ostringstream out; size_t n = matrix_value.width(); - image::basic_image binary_matrix(matrix_value.geometry()); - image::basic_image norm_matrix(matrix_value.geometry()); + tipl::image binary_matrix(matrix_value.geometry()); + tipl::image norm_matrix(matrix_value.geometry()); float max_value = *std::max_element(matrix_value.begin(),matrix_value.end()); for(unsigned int i = 0;i < binary_matrix.size();++i) @@ -2540,21 +2540,21 @@ void ConnectivityMatrix::network_property(std::string& report) float d = degree[i]; cluster_co[i] /= (d*d-d); } - float cc_bin = image::mean(cluster_co.begin(),cluster_co.end()); + float cc_bin = tipl::mean(cluster_co.begin(),cluster_co.end()); out << "clustering_coeff_average(binary)\t" << cc_bin << std::endl; // calculate weighted clustering coefficient - image::basic_image cyc3(norm_matrix.geometry()); + tipl::image cyc3(norm_matrix.geometry()); std::vector wcluster_co(n); { - image::basic_image root(norm_matrix); + tipl::image root(norm_matrix); // root = W.^ 1/3 for(unsigned int j = 0;j < root.size();++j) root[j] = std::pow(root[j],(float)(1.0/3.0)); // cyc3 = (W.^1/3)^3 - image::basic_image t(root.geometry()); - image::mat::product(root.begin(),root.begin(),t.begin(),image::dyndim(n,n),image::dyndim(n,n)); - image::mat::product(t.begin(),root.begin(),cyc3.begin(),image::dyndim(n,n),image::dyndim(n,n)); + tipl::image t(root.geometry()); + tipl::mat::product(root.begin(),root.begin(),t.begin(),tipl::dyndim(n,n),tipl::dyndim(n,n)); + tipl::mat::product(t.begin(),root.begin(),cyc3.begin(),tipl::dyndim(n,n),tipl::dyndim(n,n)); // wcc = diag(cyc3)/(K.*(K-1)); for(unsigned int i = 0;i < n;++i) if(degree[i] >= 2) @@ -2563,28 +2563,28 @@ void ConnectivityMatrix::network_property(std::string& report) wcluster_co[i] = cyc3[i*(n+1)]/(d*d-d); } } - float cc_wei = image::mean(wcluster_co.begin(),wcluster_co.end()); + float cc_wei = tipl::mean(wcluster_co.begin(),wcluster_co.end()); out << "clustering_coeff_average(weighted)\t" << cc_wei << std::endl; // transitivity { - image::basic_image norm_matrix2(norm_matrix.geometry()); - image::basic_image norm_matrix3(norm_matrix.geometry()); - image::mat::product(norm_matrix.begin(),norm_matrix.begin(),norm_matrix2.begin(),image::dyndim(n,n),image::dyndim(n,n)); - image::mat::product(norm_matrix2.begin(),norm_matrix.begin(),norm_matrix3.begin(),image::dyndim(n,n),image::dyndim(n,n)); - out << "transitivity(binary)\t" << image::mat::trace(norm_matrix3.begin(),image::dyndim(n,n)) / - (std::accumulate(norm_matrix2.begin(),norm_matrix2.end(),0.0) - image::mat::trace(norm_matrix2.begin(),image::dyndim(n,n))) << std::endl; + tipl::image norm_matrix2(norm_matrix.geometry()); + tipl::image norm_matrix3(norm_matrix.geometry()); + tipl::mat::product(norm_matrix.begin(),norm_matrix.begin(),norm_matrix2.begin(),tipl::dyndim(n,n),tipl::dyndim(n,n)); + tipl::mat::product(norm_matrix2.begin(),norm_matrix.begin(),norm_matrix3.begin(),tipl::dyndim(n,n),tipl::dyndim(n,n)); + out << "transitivity(binary)\t" << tipl::mat::trace(norm_matrix3.begin(),tipl::dyndim(n,n)) / + (std::accumulate(norm_matrix2.begin(),norm_matrix2.end(),0.0) - tipl::mat::trace(norm_matrix2.begin(),tipl::dyndim(n,n))) << std::endl; float k = 0; for(unsigned int i = 0;i < n;++i) k += degree[i]*(degree[i]-1); - out << "transitivity(weighted)\t" << (k == 0 ? 0 : image::mat::trace(cyc3.begin(),image::dyndim(n,n))/k) << std::endl; + out << "transitivity(weighted)\t" << (k == 0 ? 0 : tipl::mat::trace(cyc3.begin(),tipl::dyndim(n,n))/k) << std::endl; } std::vector eccentricity_bin(n),eccentricity_wei(n); { - image::basic_image dis_bin,dis_wei; + tipl::image dis_bin,dis_wei; distance_bin(binary_matrix,dis_bin); distance_wei(norm_matrix,dis_wei); unsigned int inf_count_bin = std::count(dis_bin.begin(),dis_bin.end(),std::numeric_limits::max()); @@ -2597,7 +2597,7 @@ void ConnectivityMatrix::network_property(std::string& report) out << "network_characteristic_path_length(weighted)\t" << ncpl_wei << std::endl; out << "small-worldness(binary)\t" << (ncpl_bin == 0.0 ? 0.0:cc_bin/ncpl_bin) << std::endl; out << "small-worldness(weighted)\t" << (ncpl_wei == 0.0 ? 0.0:cc_wei/ncpl_wei) << std::endl; - image::basic_image invD; + tipl::image invD; inv_dis(dis_bin,invD); out << "global_efficiency(binary)\t" << std::accumulate(invD.begin(),invD.end(),0.0)/(n*n-inf_count_bin) << std::endl; inv_dis(dis_wei,invD); @@ -2632,7 +2632,7 @@ void ConnectivityMatrix::network_property(std::string& report) binary_matrix.begin()+ipos+n,0); if(new_n < 2) continue; - image::basic_image newA(image::geometry<2>(new_n,new_n)); + tipl::image newA(tipl::geometry<2>(new_n,new_n)); unsigned int pos = 0; for(unsigned int j = 0,index = 0;j < n;++j) for(unsigned int k = 0;k < n;++k,++index) @@ -2642,7 +2642,7 @@ void ConnectivityMatrix::network_property(std::string& report) newA[pos] = binary_matrix[index]; ++pos; } - image::basic_image invD; + tipl::image invD; distance_bin(newA,invD); inv_dis(invD,invD); local_efficiency_bin[i] = std::accumulate(invD.begin(),invD.end(),0.0)/(new_n*new_n-new_n); @@ -2660,7 +2660,7 @@ void ConnectivityMatrix::network_property(std::string& report) binary_matrix.begin()+ipos+n,0); if(new_n < 2) continue; - image::basic_image newA(image::geometry<2>(new_n,new_n)); + tipl::image newA(tipl::geometry<2>(new_n,new_n)); unsigned int pos = 0; for(unsigned int j = 0,index = 0;j < n;++j) for(unsigned int k = 0;k < n;++k,++index) @@ -2674,7 +2674,7 @@ void ConnectivityMatrix::network_property(std::string& report) for(unsigned int j = 0;j < n;++j) if(binary_matrix[ipos+j]) sw.push_back(std::pow(norm_matrix[ipos+j],(float)(1.0/3.0))); - image::basic_image invD; + tipl::image invD; distance_wei(newA,invD); inv_dis(invD,invD); float numer = 0.0; @@ -2700,9 +2700,9 @@ void ConnectivityMatrix::network_property(std::string& report) } float a = (std::accumulate(degi.begin(),degi.end(),0.0)+ std::accumulate(degj.begin(),degj.end(),0.0))/2.0/degi.size(); - float sum = image::vec::dot(degi.begin(),degi.end(),degj.begin())/degi.size(); - image::square(degi); - image::square(degj); + float sum = tipl::vec::dot(degi.begin(),degi.end(),degj.begin())/degi.size(); + tipl::square(degi); + tipl::square(degj); float b = (std::accumulate(degi.begin(),degi.end(),0.0)+ std::accumulate(degj.begin(),degj.end(),0.0))/2.0/degi.size(); a = a*a; @@ -2722,9 +2722,9 @@ void ConnectivityMatrix::network_property(std::string& report) } float a = (std::accumulate(degi.begin(),degi.end(),0.0)+ std::accumulate(degj.begin(),degj.end(),0.0))/2.0/degi.size(); - float sum = image::vec::dot(degi.begin(),degi.end(),degj.begin())/degi.size(); - image::square(degi); - image::square(degj); + float sum = tipl::vec::dot(degi.begin(),degi.end(),degj.begin())/degi.size(); + tipl::square(degi); + tipl::square(degj); float b = (std::accumulate(degi.begin(),degi.end(),0.0)+ std::accumulate(degj.begin(),degj.end(),0.0))/2.0/degi.size(); out << "assortativity_coefficient(weighted)\t" << ( sum - a*a)/ ( b - a*a ) << std::endl; @@ -2733,15 +2733,15 @@ void ConnectivityMatrix::network_property(std::string& report) std::vector betweenness_bin(n); { - image::basic_image NPd(binary_matrix),NSPd(binary_matrix),NSP(binary_matrix); + tipl::image NPd(binary_matrix),NSPd(binary_matrix),NSP(binary_matrix); for(unsigned int i = 0,dg = 0;i < n;++i,dg += n+1) NSP[dg] = 1; - image::basic_image L(NSP); + tipl::image L(NSP); unsigned int d = 2; for(;std::find(NSPd.begin(),NSPd.end(),1) != NSPd.end();++d) { - image::basic_image t(binary_matrix.geometry()); - image::mat::product(NPd.begin(),binary_matrix.begin(),t.begin(),image::dyndim(n,n),image::dyndim(n,n)); + tipl::image t(binary_matrix.geometry()); + tipl::mat::product(NPd.begin(),binary_matrix.begin(),t.begin(),tipl::dyndim(n,n),tipl::dyndim(n,n)); t.swap(NPd); for(unsigned int i = 0;i < L.size();++i) { @@ -2754,17 +2754,17 @@ void ConnectivityMatrix::network_property(std::string& report) for(unsigned int i = 0,dg = 0;i < n;++i,dg += n+1) L[dg] = 0; std::replace(NSP.begin(),NSP.end(),0,1); - image::basic_image DP(binary_matrix.geometry()); + tipl::image DP(binary_matrix.geometry()); for(--d;d >= 2;--d) { - image::basic_image t(DP),DPd1(binary_matrix.geometry()); + tipl::image t(DP),DPd1(binary_matrix.geometry()); t += 1.0; for(unsigned int i = 0;i < t.size();++i) if(L[i] != d) t[i] = 0; else t[i] /= NSP[i]; - image::mat::product(t.begin(),binary_matrix.begin(),DPd1.begin(),image::dyndim(n,n),image::dyndim(n,n)); + tipl::mat::product(t.begin(),binary_matrix.begin(),DPd1.begin(),tipl::dyndim(n,n),tipl::dyndim(n,n)); for(unsigned int i = 0;i < DPd1.size();++i) if(L[i] != d-1) DPd1[i] = 0; @@ -2789,8 +2789,8 @@ void ConnectivityMatrix::network_property(std::string& report) std::vector S(n),Q(n); int q = n-1; std::fill(S.begin(),S.end(),1); - image::basic_image P(binary_matrix.geometry()); - image::basic_image G1(norm_matrix); + tipl::image P(binary_matrix.geometry()); + tipl::image G1(norm_matrix); std::vector V; V.push_back(i); while(1) @@ -2858,12 +2858,12 @@ void ConnectivityMatrix::network_property(std::string& report) std::vector eigenvector_centrality_bin(n),eigenvector_centrality_wei(n); { - image::basic_image bin; + tipl::image bin; bin = binary_matrix; std::vector V(binary_matrix.size()),d(n); - image::mat::eigen_decomposition_sym(bin.begin(),V.begin(),d.begin(),image::dyndim(n,n)); + tipl::mat::eigen_decomposition_sym(bin.begin(),V.begin(),d.begin(),tipl::dyndim(n,n)); std::copy(V.begin(),V.begin()+n,eigenvector_centrality_bin.begin()); - image::mat::eigen_decomposition_sym(norm_matrix.begin(),V.begin(),d.begin(),image::dyndim(n,n)); + tipl::mat::eigen_decomposition_sym(norm_matrix.begin(),V.begin(),d.begin(),tipl::dyndim(n,n)); std::copy(V.begin(),V.begin()+n,eigenvector_centrality_wei.begin()); } @@ -2874,7 +2874,7 @@ void ConnectivityMatrix::network_property(std::string& report) std::replace(deg_bin.begin(),deg_bin.end(),0.0f,1.0f); std::replace(deg_wei.begin(),deg_wei.end(),0.0f,1.0f); - image::basic_image B_bin(binary_matrix.geometry()),B_wei(binary_matrix.geometry()); + tipl::image B_bin(binary_matrix.geometry()),B_wei(binary_matrix.geometry()); for(unsigned int i = 0,index = 0;i < n;++i) for(unsigned int j = 0;j < n;++j,++index) { @@ -2889,18 +2889,18 @@ void ConnectivityMatrix::network_property(std::string& report) std::vector pivot(n); std::vector b(n); std::fill(b.begin(),b.end(),(1.0-d)/n); - image::mat::lu_decomposition(B_bin.begin(),pivot.begin(),image::dyndim(n,n)); - image::mat::lu_solve(B_bin.begin(),pivot.begin(),b.begin(),pagerank_centrality_bin.begin(),image::dyndim(n,n)); - image::mat::lu_decomposition(B_wei.begin(),pivot.begin(),image::dyndim(n,n)); - image::mat::lu_solve(B_wei.begin(),pivot.begin(),b.begin(),pagerank_centrality_wei.begin(),image::dyndim(n,n)); + tipl::mat::lu_decomposition(B_bin.begin(),pivot.begin(),tipl::dyndim(n,n)); + tipl::mat::lu_solve(B_bin.begin(),pivot.begin(),b.begin(),pagerank_centrality_bin.begin(),tipl::dyndim(n,n)); + tipl::mat::lu_decomposition(B_wei.begin(),pivot.begin(),tipl::dyndim(n,n)); + tipl::mat::lu_solve(B_wei.begin(),pivot.begin(),b.begin(),pagerank_centrality_wei.begin(),tipl::dyndim(n,n)); float sum_bin = std::accumulate(pagerank_centrality_bin.begin(),pagerank_centrality_bin.end(),0.0); float sum_wei = std::accumulate(pagerank_centrality_wei.begin(),pagerank_centrality_wei.end(),0.0); if(sum_bin != 0) - image::divide_constant(pagerank_centrality_bin,sum_bin); + tipl::divide_constant(pagerank_centrality_bin,sum_bin); if(sum_wei != 0) - image::divide_constant(pagerank_centrality_wei,sum_wei); + tipl::divide_constant(pagerank_centrality_wei,sum_wei); } output_node_measures(out,"network_measures",region_name); output_node_measures(out,"degree(binary)",degree); diff --git a/libs/tracking/tract_model.hpp b/libs/tracking/tract_model.hpp index 1d1a609aa..35b65b7d6 100644 --- a/libs/tracking/tract_model.hpp +++ b/libs/tracking/tract_model.hpp @@ -2,7 +2,7 @@ #define TRACT_MODEL_HPP #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "fib_data.hpp" class RoiMgr; @@ -11,8 +11,8 @@ class TractModel{ std::string report; private: std::shared_ptr handle; - image::geometry<3> geometry; - image::vector<3> vs; + tipl::geometry<3> geometry; + tipl::vector<3> vs; std::auto_ptr fib; private: std::vector > tract_data; @@ -31,8 +31,8 @@ class TractModel{ const std::vector& get_cluster_info(void) const{return tract_cluster;} std::vector& get_cluster_info(void) {return tract_cluster;} void select(float select_angle, - const std::vector >& dirs, - const image::vector<3,float>& from_pos,std::vector& selected); + const std::vector >& dirs, + const tipl::vector<3,float>& from_pos,std::vector& selected); // selection void delete_tracts(const std::vector& tracts_to_delete); void select_tracts(const std::vector& tracts_to_select); @@ -57,7 +57,7 @@ class TractModel{ void add(const TractModel& rhs); bool load_from_file(const char* file_name,bool append = false); - bool save_tracts_in_native_space(const char* file_name,image::basic_image,3 > native_position); + bool save_tracts_in_native_space(const char* file_name,tipl::image,3 > native_position); bool save_tracts_to_file(const char* file_name); void save_vrml(const char* file_name, unsigned char tract_style, @@ -75,18 +75,18 @@ class TractModel{ void release_tracts(std::vector >& released_tracks); void add_tracts(std::vector >& new_tracks); - void add_tracts(std::vector >& new_tracks,image::rgb_color color); + void add_tracts(std::vector >& new_tracks,tipl::rgb color); void add_tracts(std::vector >& new_tracks,unsigned int length_threshold); void filter_by_roi(RoiMgr& roi_mgr); void cull(float select_angle, - const std::vector > & dirs, - const image::vector<3,float>& from_pos, + const std::vector > & dirs, + const tipl::vector<3,float>& from_pos, bool delete_track); - void cut(float select_angle,const std::vector > & dirs, - const image::vector<3,float>& from_pos); + void cut(float select_angle,const std::vector > & dirs, + const tipl::vector<3,float>& from_pos); void cut_by_slice(unsigned int dim, unsigned int pos,bool greater); - void paint(float select_angle,const std::vector > & dirs, - const image::vector<3,float>& from_pos, + void paint(float select_angle,const std::vector > & dirs, + const tipl::vector<3,float>& from_pos, unsigned int color); void set_color(unsigned int color){std::fill(tract_color.begin(),tract_color.end(),color);} void set_tract_color(unsigned int index,unsigned int color){tract_color[index] = color;} @@ -98,8 +98,8 @@ class TractModel{ bool trim(void); - void get_end_points(std::vector >& points); - void get_tract_points(std::vector >& points); + void get_end_points(std::vector >& points); + void get_tract_points(std::vector >& points); size_t get_deleted_track_count(void) const{return deleted_tract_data.size();} size_t get_visible_track_count(void) const{return tract_data.size();} @@ -110,10 +110,10 @@ class TractModel{ std::vector >& get_tracts(void) {return tract_data;} unsigned int get_tract_color(unsigned int index) const{return tract_color[index];} size_t get_tract_length(unsigned int index) const{return tract_data[index].size();} - void get_density_map(image::basic_image& mapping, - const image::matrix<4,4,float>& transformation,bool endpoint); - void get_density_map(image::basic_image& mapping, - const image::matrix<4,4,float>& transformation,bool endpoint); + void get_density_map(tipl::image& mapping, + const tipl::matrix<4,4,float>& transformation,bool endpoint); + void get_density_map(tipl::image& mapping, + const tipl::matrix<4,4,float>& transformation,bool endpoint); void save_tdi(const char* file_name,bool sub_voxel,bool endpoint,const std::vector& tran); void get_quantitative_data(std::vector& data); @@ -134,11 +134,11 @@ class TractModel{ void get_tracts_data(unsigned int index_num,float& mean, float& sd) const; public: - void get_passing_list(const std::vector > >& regions, + void get_passing_list(const std::vector > >& regions, std::vector >& passing_list1, std::vector >& passing_list2, float& overlap_ratio) const; - void get_end_list(const std::vector > >& regions, + void get_end_list(const std::vector > >& regions, std::vector >& end_list1, std::vector >& end_list2, float& overlap_ratio) const; @@ -153,15 +153,15 @@ class atlas; class ConnectivityMatrix{ public: - image::basic_image matrix_value; + tipl::image matrix_value; public: - std::vector > > regions; + std::vector > > regions; std::vector region_name; std::string error_msg; float overlap_ratio; - void set_atlas(atlas& data,const image::basic_image,3 >& mni_position); + void set_atlas(atlas& data,const tipl::image,3 >& mni_position); public: - void save_to_image(image::color_image& cm); + void save_to_image(tipl::color_image& cm); void save_to_file(const char* file_name); void save_to_connectogram(const char* file_name); void save_to_text(std::string& text); diff --git a/libs/vbc/vbc_database.cpp b/libs/vbc/vbc_database.cpp index b31e70890..422a851de 100644 --- a/libs/vbc/vbc_database.cpp +++ b/libs/vbc/vbc_database.cpp @@ -19,7 +19,7 @@ bool vbc_database::create_database(const char* template_name) error_msg = handle->error_msg; return false; } - fiber_threshold = 0.6*image::segmentation::otsu_threshold(image::make_image(handle->dir.fa[0],handle->dim)); + fiber_threshold = 0.6*tipl::segmentation::otsu_threshold(tipl::make_image(handle->dir.fa[0],handle->dim)); handle->db.calculate_si2vi(); return true; } @@ -32,7 +32,7 @@ bool vbc_database::load_database(const char* database_name) error_msg += handle->error_msg; return false; } - fiber_threshold = 0.6*image::segmentation::otsu_threshold(image::make_image(handle->dir.fa[0],handle->dim)); + fiber_threshold = 0.6*tipl::segmentation::otsu_threshold(tipl::make_image(handle->dir.fa[0],handle->dim)); voxels_in_threshold = 0; for(int i = 0;i < handle->dim.size();++i) if(handle->dir.fa[0][i] > fiber_threshold) @@ -43,10 +43,10 @@ bool vbc_database::load_database(const char* database_name) int vbc_database::run_track(const tracking_data& fib,std::vector >& tracks,float seed_ratio, unsigned int thread_count) { - std::vector > seed; - for(image::pixel_index<3> index(handle->dim);index < handle->dim.size();++index) + std::vector > seed; + for(tipl::pixel_index<3> index(handle->dim);index < handle->dim.size();++index) if(fib.fa[0][index.index()] > tracking_threshold) - seed.push_back(image::vector<3,short>(index.x(),index.y(),index.z())); + seed.push_back(tipl::vector<3,short>(index.x(),index.y(),index.z())); unsigned int count = seed.size()*seed_ratio*10000.0f/(float)voxels_in_threshold; if(!count) { @@ -69,7 +69,7 @@ int vbc_database::run_track(const tracking_data& fib,std::vector()); + tracking_thread.roi_mgr.setRegions(fib.dim,seed,1.0,3,"whole brain",tipl::vector<3>()); if(!roi_list.empty()) { for(unsigned int index = 0;index < roi_list.size();++index) diff --git a/libs/vbc/vbc_database.h b/libs/vbc/vbc_database.h index 0b0dcca7e..7e9fbc1d8 100644 --- a/libs/vbc/vbc_database.h +++ b/libs/vbc/vbc_database.h @@ -2,7 +2,7 @@ #define VBC_DATABASE_H #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "gzip_interface.hpp" #include "prog_interface_static_link.h" #include "libs/tracking/tract_model.hpp" @@ -55,7 +55,7 @@ class vbc_database unsigned int progress;// 0~100 bool terminated = false; public: - std::vector > > roi_list; + std::vector > > roi_list; std::vector roi_r_list; std::vector roi_type; public: diff --git a/main.cpp b/main.cpp index 056db7930..f7249bf82 100644 --- a/main.cpp +++ b/main.cpp @@ -7,7 +7,7 @@ #include #include #include "mainwindow.h" -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "mapping/fa_template.hpp" #include "mapping/atlas.hpp" #include diff --git a/mainwindow.cpp b/mainwindow.cpp index 88afb45e6..3a3514abc 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,6 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include #include #include @@ -287,7 +287,7 @@ void MainWindow::on_OpenDICOM_clicked() add_work_dir(QFileInfo(filenames[0]).absolutePath()); if(QFileInfo(filenames[0]).completeBaseName() == "subject") { - image::io::bruker_info subject_file; + tipl::io::bruker_info subject_file; if(!subject_file.load_from_file(filenames[0].toLocal8Bit().begin())) return; QString dir = QFileInfo(filenames[0]).absolutePath(); @@ -298,7 +298,7 @@ void MainWindow::on_OpenDICOM_clicked() bool is_dwi =false; // has dif info in the method file { - image::io::bruker_info method_file; + tipl::io::bruker_info method_file; QString method_name = dir + "/" +QString::number(i)+"/method"; if(method_file.load_from_file(method_name.toLocal8Bit().begin()) && method_file["PVM_DwEffBval"].length()) @@ -306,7 +306,7 @@ void MainWindow::on_OpenDICOM_clicked() } // has dif info in the imnd file { - image::io::bruker_info imnd_file; + tipl::io::bruker_info imnd_file; QString imnd_name = dir + "/" +QString::number(i)+"/imnd"; if(imnd_file.load_from_file(imnd_name.toLocal8Bit().begin()) && imnd_file["IMND_diff_b_value"].length()) @@ -393,7 +393,7 @@ bool RenameDICOMToDir(QString FileName, QString ToDir) { std::string person, sequence, imagename; { - image::io::dicom header; + tipl::io::dicom header; if (!header.load_from_file(FileName.toLocal8Bit().begin())) return false; @@ -632,20 +632,20 @@ void MainWindow::on_batch_src_clicked() if(dwi_files.size() == 1) //MPRAGE or T2W { std::sort(dicom_file_list.begin(),dicom_file_list.end(),compare_qstring()); - image::io::volume v; - image::io::dicom header; + tipl::io::volume v; + tipl::io::dicom header; std::vector file_list; for(unsigned int index = 0;index < dicom_file_list.size();++index) file_list.push_back(dicom_file_list[index].toLocal8Bit().begin()); if(!v.load_from_files(file_list,file_list.size()) || !header.load_from_file(dicom_file_list[0].toLocal8Bit().begin())) continue; - image::basic_image I; - image::vector<3> vs; + tipl::image I; + tipl::vector<3> vs; v >> I; v.get_voxel_size(vs.begin()); gz_nifti nii_out; - image::flip_xy(I); + tipl::flip_xy(I); nii_out << I; nii_out.set_voxel_size(vs); @@ -876,7 +876,7 @@ void MainWindow::on_set_dir_clicked() QDir::setCurrent(dir); } -bool load_image_from_files(QStringList filenames,image::basic_image& ref,image::vector<3>& vs); +bool load_image_from_files(QStringList filenames,tipl::image& ref,tipl::vector<3>& vs); void MainWindow::on_linear_reg_clicked() { @@ -894,14 +894,14 @@ void MainWindow::on_linear_reg_clicked() return; - image::basic_image ref1,ref2; - image::vector<3> vs1,vs2; + tipl::image ref1,ref2; + tipl::vector<3> vs1,vs2; if(!load_image_from_files(filename1,ref1,vs1) || !load_image_from_files(filename2,ref2,vs2)) return; - std::shared_ptr manual(new manual_alignment(this,ref1,vs1,ref2,vs2,image::reg::affine,image::reg::mutual_info)); + std::shared_ptr manual(new manual_alignment(this,ref1,vs1,ref2,vs2,tipl::reg::affine,tipl::reg::mutual_info)); manual->on_rerun_clicked(); if(manual->exec() != QDialog::Accepted) return; diff --git a/manual_alignment.cpp b/manual_alignment.cpp index 462589161..dd336572c 100644 --- a/manual_alignment.cpp +++ b/manual_alignment.cpp @@ -9,24 +9,24 @@ void show_view(QGraphicsScene& scene,QImage I); manual_alignment::manual_alignment(QWidget *parent, - image::basic_image from_, - const image::vector<3>& from_vs_, - image::basic_image to_, - const image::vector<3>& to_vs_, - image::reg::reg_type reg_type, - image::reg::cost_type cost_function) : + tipl::image from_, + const tipl::vector<3>& from_vs_, + tipl::image to_, + const tipl::vector<3>& to_vs_, + tipl::reg::reg_type reg_type, + tipl::reg::cost_type cost_function) : QDialog(parent),ui(new Ui::manual_alignment),from_vs(from_vs_),to_vs(to_vs_),timer(0) { from_original = from_; from.swap(from_); to.swap(to_); - image::normalize(from,1.0); - image::normalize(to,1.0); - image::reg::get_bound(from,arg,b_upper,b_lower,reg_type); + tipl::normalize(from,1.0); + tipl::normalize(to,1.0); + tipl::reg::get_bound(from,arg,b_upper,b_lower,reg_type); ui->setupUi(this); - ui->reg_type->setCurrentIndex(reg_type == image::reg::rigid_body? 0: 1); - ui->cost_type->setCurrentIndex(cost_function == image::reg::mutual_info ? 1 : 0); + ui->reg_type->setCurrentIndex(reg_type == tipl::reg::rigid_body? 0: 1); + ui->cost_type->setCurrentIndex(cost_function == tipl::reg::mutual_info ? 1 : 0); ui->sag_view->setScene(&scene[0]); @@ -153,12 +153,12 @@ void manual_alignment::load_param(void) void manual_alignment::update_image(void) { - T = image::transformation_matrix(arg,from.geometry(),from_vs,to.geometry(),to_vs); + T = tipl::transformation_matrix(arg,from.geometry(),from_vs,to.geometry(),to_vs); iT = T; iT.inverse(); warped_from.clear(); warped_from.resize(to.geometry()); - image::resample(from,warped_from,iT,image::linear); + tipl::resample(from,warped_from,iT,tipl::linear); } void manual_alignment::param_changed() { @@ -201,14 +201,14 @@ void manual_alignment::slice_pos_moved() w2 *= 255.0; for(unsigned char dim = 0;dim < 3;++dim) { - image::basic_image slice,slice2; - image::reslicing(warped_from,slice,dim,slice_pos[dim]); - image::reslicing(to,slice2,dim,slice_pos[dim]); + tipl::image slice,slice2; + tipl::reslicing(warped_from,slice,dim,slice_pos[dim]); + tipl::reslicing(to,slice2,dim,slice_pos[dim]); buffer[dim].resize(slice.geometry()); for (unsigned int index = 0; index < slice.size(); ++index) { float value = slice[index]*w2+slice2[index]*w1; - buffer[dim][index] = image::rgb_color(value,value,value); + buffer[dim][index] = tipl::rgb(value,value,value); } slice_image[dim] = QImage((unsigned char*)&*buffer[dim].begin(),buffer[dim].width(),buffer[dim].height(),QImage::Format_RGB32). scaled(buffer[dim].width()*ratio,buffer[dim].height()*ratio); @@ -258,21 +258,21 @@ void manual_alignment::on_buttonBox_rejected() void manual_alignment::on_rerun_clicked() { - auto cost = ui->cost_type->currentIndex() == 0 ? image::reg::corr : image::reg::mutual_info; - auto reg = ui->reg_type->currentIndex() == 0 ? image::reg::rigid_body : image::reg::affine; + auto cost = ui->cost_type->currentIndex() == 0 ? tipl::reg::corr : tipl::reg::mutual_info; + auto reg = ui->reg_type->currentIndex() == 0 ? tipl::reg::rigid_body : tipl::reg::affine; thread.run([this,cost,reg]() { - if(cost == image::reg::mutual_info) + if(cost == tipl::reg::mutual_info) { - image::reg::linear_mr(from,from_vs,to,to_vs,arg,reg,image::reg::mutual_information(),thread.terminated,0.1); - image::reg::linear_mr(from,from_vs,to,to_vs,arg,reg,image::reg::mutual_information(),thread.terminated,0.01); + tipl::reg::linear_mr(from,from_vs,to,to_vs,arg,reg,tipl::reg::mutual_information(),thread.terminated,0.1); + tipl::reg::linear_mr(from,from_vs,to,to_vs,arg,reg,tipl::reg::mutual_information(),thread.terminated,0.01); } else { - image::reg::linear_mr(from,from_vs,to,to_vs,arg,reg,image::reg::mt_correlation, - image::transformation_matrix >(0),thread.terminated,0.1); - image::reg::linear_mr(from,from_vs,to,to_vs,arg,reg,image::reg::mt_correlation, - image::transformation_matrix >(0),thread.terminated,0.01); + tipl::reg::linear_mr(from,from_vs,to,to_vs,arg,reg,tipl::reg::mt_correlation, + tipl::transformation_matrix >(0),thread.terminated,0.1); + tipl::reg::linear_mr(from,from_vs,to,to_vs,arg,reg,tipl::reg::mt_correlation, + tipl::transformation_matrix >(0),thread.terminated,0.01); } }); @@ -293,19 +293,19 @@ void manual_alignment::on_save_warpped_clicked() if(filename.isEmpty()) return; - image::basic_image I(to.geometry()); - image::resample(from_original,I,iT,image::cubic); + tipl::image I(to.geometry()); + tipl::resample(from_original,I,iT,tipl::cubic); gz_nifti nii; nii.set_voxel_size(to_vs.begin()); - image::flip_xy(I); + tipl::flip_xy(I); nii << I; nii.save_to_file(filename.toStdString().c_str()); } void manual_alignment::on_reg_type_currentIndexChanged(int index) { - image::reg::get_bound(from,arg,b_upper,b_lower, - ui->reg_type->currentIndex() == 0 ? image::reg::rigid_body : image::reg::affine); + tipl::reg::get_bound(from,arg,b_upper,b_lower, + ui->reg_type->currentIndex() == 0 ? tipl::reg::rigid_body : tipl::reg::affine); if(index == 0) // rigid body { ui->scaling_group->hide(); diff --git a/manual_alignment.h b/manual_alignment.h index 8b4486547..bfaa44bcf 100644 --- a/manual_alignment.h +++ b/manual_alignment.h @@ -4,7 +4,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "fib_data.hpp" namespace Ui { class manual_alignment; @@ -15,29 +15,29 @@ class manual_alignment : public QDialog { Q_OBJECT public: - image::basic_image from_original; - image::basic_image from,to,warped_from; - image::affine_transform arg,b_upper,b_lower; - image::vector<3> from_vs,to_vs; + tipl::image from_original; + tipl::image from,to,warped_from; + tipl::affine_transform arg,b_upper,b_lower; + tipl::vector<3> from_vs,to_vs; QGraphicsScene scene[3]; - image::color_image buffer[3]; + tipl::color_image buffer[3]; QImage slice_image[3]; private: - image::thread thread; + tipl::thread thread; private: void load_param(void); public: - image::transformation_matrix T,iT; + tipl::transformation_matrix T,iT; public: QTimer* timer; explicit manual_alignment(QWidget *parent, - image::basic_image from_, - const image::vector<3>& from_vs, - image::basic_image to_, - const image::vector<3>& to_vs, - image::reg::reg_type reg_type, - image::reg::cost_type cost_function); + tipl::image from_, + const tipl::vector<3>& from_vs, + tipl::image to_, + const tipl::vector<3>& to_vs, + tipl::reg::reg_type reg_type, + tipl::reg::cost_type cost_function); ~manual_alignment(); void connect_arg_update(); void disconnect_arg_update(); diff --git a/opengl/glwidget.cpp b/opengl/glwidget.cpp index 4fce0587c..1f5e6647a 100644 --- a/opengl/glwidget.cpp +++ b/opengl/glwidget.cpp @@ -138,7 +138,7 @@ void GLWidget::set_view(unsigned char view_option) transformation_matrix[10] = cur_tracking_window.handle->vs[2] / cur_tracking_window.handle->vs[0]; } - image::vector<3,float> center_point(cur_tracking_window.handle->dim[0]/2.0-0.5, + tipl::vector<3,float> center_point(cur_tracking_window.handle->dim[0]/2.0-0.5, cur_tracking_window.handle->dim[1]/2.0-0.5, cur_tracking_window.handle->dim[2]/2.0-0.5); transformation_matrix[0] *= scale; @@ -147,7 +147,7 @@ void GLWidget::set_view(unsigned char view_option) transformation_matrix[12] = -transformation_matrix[0]*center_point[0]; transformation_matrix[13] = -transformation_matrix[5]*center_point[1]; transformation_matrix[14] = -transformation_matrix[10]*center_point[2]; - image::matrix<4,4,float> m; + tipl::matrix<4,4,float> m; if(view_option != 2) { m.zero(); @@ -250,24 +250,24 @@ void setupMaterial(float emission,float specular,int shininess) check_error(__FUNCTION__); } -unsigned char getCurView(const image::matrix<4,4,float>& m) +unsigned char getCurView(const tipl::matrix<4,4,float>& m) { unsigned char cur_view = 0; { const float view_dirs[6][3] = {{1,0,0},{0,1,0},{0,0,1},{-1,0,0},{0,-1,0},{0,0,-1}}; - image::matrix<4,4,float> mat = image::inverse(m); - image::vector<3,float> dir(mat.begin()+8); + tipl::matrix<4,4,float> mat = tipl::inverse(m); + tipl::vector<3,float> dir(mat.begin()+8); float max_cos = 0; for (unsigned int index = 0;index < 6;++index) - if (dir*image::vector<3,float>(view_dirs[index]) < max_cos) + if (dir*tipl::vector<3,float>(view_dirs[index]) < max_cos) { - max_cos = dir*image::vector<3,float>(view_dirs[index]); + max_cos = dir*tipl::vector<3,float>(view_dirs[index]); cur_view = index; } } return cur_view; } -void handleAlpha(image::rgb_color color, +void handleAlpha(tipl::rgb color, float alpha,int blend1,int blend2) { if(alpha != 1.0) @@ -305,7 +305,7 @@ void my_gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz) { - image::vector<3,float> forward, side, up; + tipl::vector<3,float> forward, side, up; GLfloat m[4][4]; forward[0] = centerx - eyex; @@ -459,7 +459,7 @@ void GLWidget::paintGL() case view_mode_type::stereo: glViewport(0,0, cur_width/2, cur_height); renderLR(); - image::matrix<4,4,float> T(transformation_matrix); + tipl::matrix<4,4,float> T(transformation_matrix); // add a rotation to the transofrmation matrix glPushMatrix(); glLoadIdentity(); @@ -513,16 +513,16 @@ void GLWidget::renderLR() case 0: { - image::geometry<2> geo2(slice->geometry[odf_dim==0?1:0], + tipl::geometry<2> geo2(slice->geometry[odf_dim==0?1:0], slice->geometry[odf_dim==2?1:2]); - for(image::pixel_index<2> index(geo2);index < geo2.size();++index) + for(tipl::pixel_index<2> index(geo2);index < geo2.size();++index) { if((index[0] & mask) | (index[1] & mask)) continue; int x,y,z; if (!slice->to3DSpace(cur_tracking_window.cur_dim,index[0],index[1],x,y,z)) continue; - image::pixel_index<3> pos(x,y,z,geo); + tipl::pixel_index<3> pos(x,y,z,geo); if (handle->dir.get_fa(pos.index(),0) <= fa_threshold) continue; add_odf(pos); @@ -530,11 +530,11 @@ void GLWidget::renderLR() } break; case 1: // intersection - add_odf(image::pixel_index<3>(slice->slice_pos[0],slice->slice_pos[1],slice->slice_pos[2], + add_odf(tipl::pixel_index<3>(slice->slice_pos[0],slice->slice_pos[1],slice->slice_pos[2], geo)); break; case 2: //all - for(image::pixel_index<3> index(geo);index < geo.size();++index) + for(tipl::pixel_index<3> index(geo);index < geo.size();++index) { if(((index[0] & mask) | (index[1] & mask) | (index[2] & mask)) || handle->dir.get_fa(index.index(),0) <= fa_threshold) @@ -741,14 +741,14 @@ void GLWidget::renderLR() glEnable(GL_COLOR_MATERIAL); glDisable(GL_LIGHTING); float alpha = get_param_float("slice_alpha"); - handleAlpha(image::rgb_color(0,0,0,255), + handleAlpha(tipl::rgb(0,0,0,255), alpha,get_param("slice_bend1"),get_param("slice_bend2")); glDepthMask((alpha == 1.0)); glPushMatrix(); glMultMatrixf(transformation_matrix.begin()); - std::vector > points(4); + std::vector > points(4); @@ -766,7 +766,7 @@ void GLWidget::renderLR() { if(slice_texture[dim]) deleteTexture(slice_texture[dim]); - image::color_image texture; + tipl::color_image texture; current_slice->get_texture(dim,texture,cur_tracking_window.v2c, cur_tracking_window.overlay_slice.get(),cur_tracking_window.overlay_v2c); slice_texture[dim] = @@ -829,7 +829,7 @@ void GLWidget::renderLR() region_need_update.push_back(index); int smoothed = get_param("region_mesh_smoothed"); - image::par_for(region_need_update.size(),[&](unsigned int index){ + tipl::par_for(region_need_update.size(),[&](unsigned int index){ cur_tracking_window.regionWidget->regions[region_need_update[index]]->makeMeshes(smoothed); }); @@ -913,7 +913,7 @@ void GLWidget::renderLR() if(p[0] == 0.0 && p[1] == 0.0 && p[2] == 0.0) { const auto& p2 = cur_tracking_window.regionWidget->regions[i]->show_region.center; - image::vector<3> p3(p2); + tipl::vector<3> p3(p2); p3 /= cur_tracking_window.regionWidget->regions[i]->resolution_ratio; renderText(p3[0],p3[1],p3[2],cur_tracking_window.regionWidget->item(i,0)->text(),font); } @@ -982,7 +982,7 @@ void GLWidget::renderLR() } -void GLWidget::add_odf(image::pixel_index<3> pos) +void GLWidget::add_odf(tipl::pixel_index<3> pos) { std::shared_ptr handle = cur_tracking_window.handle; const float* odf_buffer = @@ -992,8 +992,8 @@ void GLWidget::add_odf(image::pixel_index<3> pos) unsigned int odf_dim = cur_tracking_window.odf_size; unsigned int half_odf = odf_dim >> 1; odf_points.resize(odf_points.size()+odf_dim); - std::vector >::iterator iter = odf_points.end()-odf_dim; - std::vector >::iterator end = odf_points.end(); + std::vector >::iterator iter = odf_points.end()-odf_dim; + std::vector >::iterator end = odf_points.end(); std::fill(iter,end,pos); float odf_min = *std::min_element(odf_buffer,odf_buffer+half_odf); @@ -1013,7 +1013,7 @@ void GLWidget::add_odf(image::pixel_index<3> pos) { new_odf_buffer.resize(half_odf); std::copy(odf_buffer,odf_buffer+half_odf,new_odf_buffer.begin()); - std::vector >& odf_faces = + std::vector >& odf_faces = handle->dir.odf_faces; for(int index = 0;index < odf_faces.size();++index) { @@ -1042,13 +1042,13 @@ void GLWidget::add_odf(image::pixel_index<3> pos) for(unsigned int index = 0;index < half_odf;++index,++iter) { - image::vector<3,float> displacement(handle->dir.odf_table[index]); + tipl::vector<3,float> displacement(handle->dir.odf_table[index]); displacement *= (odf_buffer[index]-odf_min)*scaling; *(iter) += displacement; *(iter+half_odf) -= displacement; } } -void myglColor(const image::vector<3,float>& color,float alpha) +void myglColor(const tipl::vector<3,float>& color,float alpha) { if(alpha == 1.0) glColor3fv(color.begin()); @@ -1111,10 +1111,10 @@ void GLWidget::makeTracts(void) } } - std::vector > points(8),previous_points(8), + std::vector > points(8),previous_points(8), normals(8),previous_normals(8); - image::rgb_color paint_color; - image::vector<3,float> paint_color_f; + tipl::rgb paint_color; + tipl::vector<3,float> paint_color_f; std::vector color; unsigned int visible_tracts = get_param("tract_visible_tract"); @@ -1136,7 +1136,7 @@ void GLWidget::makeTracts(void) if(total_tracts != 0) skip_rate = (float)visible_tracts/(float)total_tracts; } - image::uniform_dist uniform_gen(0.0f,1.0f),random_size(-0.5f,0.5f),random_color(-0.05f,0.05f); + tipl::uniform_dist uniform_gen(0.0f,1.0f),random_size(-0.5f,0.5f),random_color(-0.05f,0.05f); { for (unsigned int active_tract_index = 0; active_tract_index < cur_tracking_window.tractWidget->rowCount(); @@ -1169,7 +1169,7 @@ void GLWidget::makeTracts(void) { case 1: paint_color = active_tract_model->get_tract_color(data_index); - paint_color_f = image::vector<3,float>(paint_color.r,paint_color.g,paint_color.b); + paint_color_f = tipl::vector<3,float>(paint_color.r,paint_color.g,paint_color.b); paint_color_f /= 255.0; break; case 2:// local @@ -1180,7 +1180,7 @@ void GLWidget::makeTracts(void) paint_color_f = cur_tracking_window.color_bar->get_color(mean_fa[mean_fa_index++]); break; } - image::vector<3,float> last_pos(data_iter),pos, + tipl::vector<3,float> last_pos(data_iter),pos, vec_a(1,0,0),vec_b(0,1,0), vec_n,prev_vec_n,vec_ab,vec_ba,cur_color,previous_color; @@ -1229,7 +1229,7 @@ void GLWidget::makeTracts(void) { if (index != 0 && index+1 != vertex_count) { - image::vector<3,float> displacement(data_iter+3); + tipl::vector<3,float> displacement(data_iter+3); displacement -= last_pos; displacement -= prev_vec_n*(prev_vec_n*displacement); if (displacement.length() < tube_detail) @@ -1298,11 +1298,11 @@ void GLWidget::makeTracts(void) { myglColor(cur_color,alpha); glNormal3f(-vec_n[0],-vec_n[1],-vec_n[2]); - image::vector<3,float> shift(vec_n); + tipl::vector<3,float> shift(vec_n); shift *= -(int)end_point_shift; for (unsigned int k = 0;k < 8;++k) { - image::vector<3,float> cur_point = points[end_sequence[k]]; + tipl::vector<3,float> cur_point = points[end_sequence[k]]; cur_point += shift; glVertex3fv(cur_point.begin()); } @@ -1346,11 +1346,11 @@ void GLWidget::makeTracts(void) glBegin((tract_style) ? GL_TRIANGLE_STRIP : GL_LINE_STRIP); myglColor(cur_color,alpha); glNormal3fv(vec_n.begin()); - image::vector<3,float> shift(vec_n); + tipl::vector<3,float> shift(vec_n); shift *= (int)end_point_shift; for (int k = 7;k >= 0;--k) { - image::vector<3,float> cur_point = points[end_sequence[k]]; + tipl::vector<3,float> cur_point = points[end_sequence[k]]; cur_point += shift; glVertex3fv(cur_point.begin()); } @@ -1425,14 +1425,14 @@ void GLWidget::wheelEvent ( QWheelEvent * event ) } -void GLWidget::slice_location(unsigned char dim,std::vector >& points) +void GLWidget::slice_location(unsigned char dim,std::vector >& points) { cur_tracking_window.current_slice->get_slice_positions(dim,points); } -void GLWidget::get_view_dir(QPoint p,image::vector<3,float>& dir) +void GLWidget::get_view_dir(QPoint p,tipl::vector<3,float>& dir) { - image::matrix<4,4,float> m; + tipl::matrix<4,4,float> m; float v[3]; glGetFloatv(GL_PROJECTION_MATRIX,m.begin()); // Compute the vector of the pick ray in screen space @@ -1447,17 +1447,17 @@ void GLWidget::get_view_dir(QPoint p,image::vector<3,float>& dir) } float GLWidget::get_slice_projection_point(unsigned char dim, - const image::vector<3,float>& pos, - const image::vector<3,float>& dir, + const tipl::vector<3,float>& pos, + const tipl::vector<3,float>& dir, float& dx,float& dy) { - std::vector > slice_points(4); + std::vector > slice_points(4); slice_location(dim,slice_points); - image::vector<3,float> pos_offset(pos),v1(slice_points[1]),v2(slice_points[2]),v3(dir); + tipl::vector<3,float> pos_offset(pos),v1(slice_points[1]),v2(slice_points[2]),v3(dir); pos_offset -= slice_points[0]; v1 -= slice_points[0]; v2 -= slice_points[0]; - image::matrix<3,3,float> m; + tipl::matrix<3,3,float> m; m[0] = v1[0]; m[1] = v2[0]; m[2] = -v3[0]; @@ -1476,9 +1476,9 @@ float GLWidget::get_slice_projection_point(unsigned char dim, return pos_offset[2]; } -image::vector<3,float> get_norm(const std::vector >& slice_points) +tipl::vector<3,float> get_norm(const std::vector >& slice_points) { - image::vector<3,float> v1(slice_points[1]),v2(slice_points[2]),norm; + tipl::vector<3,float> v1(slice_points[1]),v2(slice_points[2]),norm; v1 -= slice_points[0]; v2 -= slice_points[0]; norm = v1.cross_product(v2); @@ -1493,10 +1493,10 @@ void GLWidget::select_object(void) // select object for(object_distance = 0;object_distance < 5000 && !object_selected;object_distance += 1.0) { - image::vector<3,float> cur_pos(dir1); + tipl::vector<3,float> cur_pos(dir1); cur_pos *= object_distance; cur_pos += pos; - image::vector<3,short> voxel(cur_pos); + tipl::vector<3,short> voxel(cur_pos); if(!cur_tracking_window.handle->dim.is_valid(voxel)) continue; for(int index = 0;index < cur_tracking_window.regionWidget->regions.size();++index) @@ -1541,8 +1541,8 @@ void GLWidget::get_pos(void) { //glMultMatrixf(transformation_matrix); glGetFloatv(GL_MODELVIEW_MATRIX,mat.begin()); - image::matrix<4,4,float> view = (edit_right) ? transformation_matrix2*mat : transformation_matrix*mat; - mat = image::inverse(view); + tipl::matrix<4,4,float> view = (edit_right) ? transformation_matrix2*mat : transformation_matrix*mat; + mat = tipl::inverse(view); pos[0] = mat[12]; pos[1] = mat[13]; pos[2] = mat[14]; @@ -1582,14 +1582,14 @@ void GLWidget::mouseDoubleClickEvent(QMouseEvent *event) emit region_edited(); } } -bool GLWidget::get_mouse_pos(QMouseEvent *event,image::vector<3,float>& position) +bool GLWidget::get_mouse_pos(QMouseEvent *event,tipl::vector<3,float>& position) { QPoint cur_pos = event->pos(); if(edit_right) cur_pos.setX(cur_pos.x() - cur_width / 2); get_pos(); - image::vector<3,float> cur_dir; + tipl::vector<3,float> cur_dir; get_view_dir(cur_pos,cur_dir); bool show_slice[3]; @@ -1612,7 +1612,7 @@ bool GLWidget::get_mouse_pos(QMouseEvent *event,image::vector<3,float>& position unsigned int min_index = std::min_element(d.begin(),d.end())-d.begin(); if(d[min_index] != 0.0 && d[min_index] != std::numeric_limits::max()) { - std::vector > points(4); + std::vector > points(4); slice_location(min_index,points); position = points[0] + (points[1]-points[0])*x[min_index] + (points[2]-points[0])*y[min_index]; return true; @@ -1642,7 +1642,7 @@ void GLWidget::mousePressEvent(QMouseEvent *event) { dirs.clear(); last_select_point = lastPos; - dirs.push_back(image::vector<3,float>()); + dirs.push_back(tipl::vector<3,float>()); get_view_dir(last_select_point,dirs.back()); } if(editing_option == moving) @@ -1676,7 +1676,7 @@ void GLWidget::mousePressEvent(QMouseEvent *event) for(unsigned char dim = 0;dim < 3;++dim) { - std::vector > points(4); + std::vector > points(4); slice_location(dim,points); angle[dim] = std::fabs(dir1*get_norm(points)) + (show_slice[dim] ? 1:0); } @@ -1687,7 +1687,7 @@ void GLWidget::mousePressEvent(QMouseEvent *event) setCursor(Qt::ArrowCursor); return; } - accumulated_dis = image::zero(); + accumulated_dis = tipl::zero(); } } void GLWidget::mouseReleaseEvent(QMouseEvent *event) @@ -1701,7 +1701,7 @@ void GLWidget::mouseReleaseEvent(QMouseEvent *event) return; last_select_point = convert_pos(event); - dirs.push_back(image::vector<3,float>()); + dirs.push_back(tipl::vector<3,float>()); get_view_dir(last_select_point,dirs.back()); angular_selection = event->button() == Qt::RightButton; @@ -1758,7 +1758,7 @@ void GLWidget::mouseMoveEvent(QMouseEvent *event) if(dis.manhattanLength() < 20) return; last_select_point = cur_pos; - dirs.push_back(image::vector<3,float>()); + dirs.push_back(tipl::vector<3,float>()); get_view_dir(last_select_point,dirs.back()); } return; @@ -1767,13 +1767,13 @@ void GLWidget::mouseMoveEvent(QMouseEvent *event) if(editing_option == moving) { - std::vector > points(4); + std::vector > points(4); slice_location(moving_at_slice_index,points); get_view_dir(cur_pos,dir2); float dx,dy; if(get_slice_projection_point(moving_at_slice_index,pos,dir2,dx,dy) == 0.0) return; - image::vector<3,float> v1(points[1]),v2(points[2]),dis; + tipl::vector<3,float> v1(points[1]),v2(points[2]),dis; v1 -= points[0]; v2 -= points[0]; dis = v1*(dx-slice_dx)+v2*(dy-slice_dy); @@ -1791,7 +1791,7 @@ void GLWidget::mouseMoveEvent(QMouseEvent *event) if(editing_option == dragging) { - std::vector > points(4); + std::vector > points(4); slice_location(moving_at_slice_index,points); get_view_dir(cur_pos,dir2); float move_dis = (dir2-dir1)*get_norm(points); @@ -1908,7 +1908,7 @@ void GLWidget::loadCamera(void) } void GLWidget::addSurface(void) { - float threshold = image::segmentation::otsu_threshold(cur_tracking_window.current_slice->get_source()); + float threshold = tipl::segmentation::otsu_threshold(cur_tracking_window.current_slice->get_source()); bool ok; threshold = QInputDialog::getDouble(this, "DSI Studio","Threshold:", threshold, @@ -2093,10 +2093,10 @@ bool GLWidget::command(QString cmd,QString param,QString param2) } if(cmd == "add_surface") { - float threshold = (param2.isEmpty()) ? image::segmentation::otsu_threshold(cur_tracking_window.current_slice->get_source()):param2.toFloat(); + float threshold = (param2.isEmpty()) ? tipl::segmentation::otsu_threshold(cur_tracking_window.current_slice->get_source()):param2.toFloat(); { surface.reset(new RegionModel); - image::basic_image crop_image(cur_tracking_window.current_slice->get_source()); + tipl::image crop_image(cur_tracking_window.current_slice->get_source()); if(!param.isEmpty()) switch(param.toInt()) { @@ -2140,11 +2140,11 @@ bool GLWidget::command(QString cmd,QString param,QString param2) switch(get_param("surface_mesh_smoothed")) { case 1: - image::filter::gaussian(crop_image); + tipl::filter::gaussian(crop_image); break; case 2: - image::filter::gaussian(crop_image); - image::filter::gaussian(crop_image); + tipl::filter::gaussian(crop_image); + tipl::filter::gaussian(crop_image); break; } if(!surface->load(crop_image,threshold)) @@ -2217,7 +2217,7 @@ bool GLWidget::command(QString cmd,QString param,QString param2) begin_prog("save video"); float angle = (param2.isEmpty()) ? 1 : param2.toFloat(); int ow = width(),oh = height(); - image::io::avi avi; + tipl::io::avi avi; #ifndef __APPLE__ resize(1980,1080); #endif diff --git a/opengl/glwidget.h b/opengl/glwidget.h index 94cf8f049..d6f084404 100644 --- a/opengl/glwidget.h +++ b/opengl/glwidget.h @@ -24,8 +24,8 @@ Q_OBJECT int s_mvp,s_mvp2,s_depthMap; public:// editing enum {none = 0,selecting = 1, moving = 2, dragging = 3} editing_option; - image::vector<3,float> pos,dir1,dir2; - std::vector > dirs; + tipl::vector<3,float> pos,dir1,dir2; + std::vector > dirs; bool angular_selection; void get_pos(void); void set_view(unsigned char view_option); @@ -33,15 +33,15 @@ Q_OBJECT void move_by(int x,int y); private: bool object_selected,slice_selected; - image::vector<3,float> accumulated_dis; + tipl::vector<3,float> accumulated_dis; float slice_distance; unsigned char moving_at_slice_index; float slice_dx,slice_dy; - void slice_location(unsigned char dim,std::vector >& points); + void slice_location(unsigned char dim,std::vector >& points); float get_slice_projection_point(unsigned char dim, - const image::vector<3,float>& pos,const image::vector<3,float>& dir, + const tipl::vector<3,float>& pos,const tipl::vector<3,float>& dir, float& dx,float& dy); - void get_view_dir(QPoint p,image::vector<3,float>& dir); + void get_view_dir(QPoint p,tipl::vector<3,float>& dir); void select_slice(void); private: int selected_index; @@ -50,18 +50,18 @@ Q_OBJECT public:// other slices QTime time; int last_time; - bool get_mouse_pos(QMouseEvent *mouseEvent,image::vector<3,float>& position); + bool get_mouse_pos(QMouseEvent *mouseEvent,tipl::vector<3,float>& position); void paintGL(); public://surface std::auto_ptr surface; private://odf - std::vector >odf_points; + std::vector >odf_points; std::vectorodf_colors; int odf_dim; int odf_slide_pos; - void add_odf(image::pixel_index<3> pos); + void add_odf(tipl::pixel_index<3> pos); private: void rotate_angle(float angle,float x,float y,float z); public slots: @@ -119,7 +119,7 @@ Q_OBJECT GLuint tracts,slice_texture[3]; int slice_pos[3]; QPoint lastPos,last_select_point; - image::matrix<4,4,float> mat,transformation_matrix,transformation_matrix2,rotation_matrix,rotation_matrix2; + tipl::matrix<4,4,float> mat,transformation_matrix,transformation_matrix2,rotation_matrix,rotation_matrix2; enum class view_mode_type { single, two, stereo} view_mode; bool set_view_flip; diff --git a/reconstruction/reconstruction_window.cpp b/reconstruction/reconstruction_window.cpp index e0fe85296..363f0b082 100644 --- a/reconstruction/reconstruction_window.cpp +++ b/reconstruction/reconstruction_window.cpp @@ -4,7 +4,7 @@ #include "ui_reconstruction_window.h" #include "dsi_interface_static_link.h" #include "mapping/fa_template.hpp" -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "mainwindow.h" #include #include @@ -32,7 +32,7 @@ bool reconstruction_window::load_src(int index) return false; } float m = (float)*std::max_element(handle->src_dwi_data[0],handle->src_dwi_data[0]+handle->voxel.dim.size()); - float otsu = image::segmentation::otsu_threshold(image::make_image(handle->src_dwi_data[0],handle->voxel.dim)); + float otsu = tipl::segmentation::otsu_threshold(tipl::make_image(handle->src_dwi_data[0],handle->voxel.dim)); ui->max_value->setMaximum(m*1.5f); ui->max_value->setMinimum(0.0f); ui->max_value->setSingleStep(m*0.05f); @@ -86,7 +86,7 @@ reconstruction_window::reconstruction_window(QStringList filenames_,QWidget *par ui->ODFSharpening->setEnabled(false); - v2c.two_color(image::rgb_color(0,0,0),image::rgb_color(255,255,255)); + v2c.two_color(tipl::rgb(0,0,0),tipl::rgb(255,255,255)); update_dimension(); absolute_path = QFileInfo(filenames[0]).absolutePath(); @@ -210,7 +210,7 @@ void reconstruction_window::load_b_table(void) void reconstruction_window::on_b_table_itemSelectionChanged() { v2c.set_range(ui->min_value->value(),ui->max_value->value()); - image::basic_image tmp(image::geometry<2>(handle->voxel.dim[0],handle->voxel.dim[1])); + tipl::image tmp(tipl::geometry<2>(handle->voxel.dim[0],handle->voxel.dim[1])); unsigned int b_index = ui->b_table->currentRow(); std::copy(handle->src_dwi_data[b_index] + ui->z_pos->value()*tmp.size(), handle->src_dwi_data[b_index] + ui->z_pos->value()*tmp.size() + tmp.size(),tmp.begin()); @@ -365,30 +365,30 @@ void reconstruction_window::doReconstruction(unsigned char method_id,bool prompt void reconstruction_window::on_erosion_clicked() { - image::morphology::erosion(handle->voxel.mask); + tipl::morphology::erosion(handle->voxel.mask); on_SlicePos_valueChanged(ui->SlicePos->value()); } void reconstruction_window::on_dilation_clicked() { - image::morphology::dilation(handle->voxel.mask); + tipl::morphology::dilation(handle->voxel.mask); on_SlicePos_valueChanged(ui->SlicePos->value()); } void reconstruction_window::on_defragment_clicked() { - image::morphology::defragment(handle->voxel.mask); + tipl::morphology::defragment(handle->voxel.mask); on_SlicePos_valueChanged(ui->SlicePos->value()); } void reconstruction_window::on_smoothing_clicked() { - image::morphology::smoothing(handle->voxel.mask); + tipl::morphology::smoothing(handle->voxel.mask); on_SlicePos_valueChanged(ui->SlicePos->value()); } void reconstruction_window::on_negate_clicked() { - image::morphology::negate(handle->voxel.mask); + tipl::morphology::negate(handle->voxel.mask); on_SlicePos_valueChanged(ui->SlicePos->value()); } @@ -397,12 +397,12 @@ void reconstruction_window::on_thresholding_clicked() { bool ok; int threshold = QInputDialog::getInt(this,"DSI Studio","Please assign the threshold", - (int)image::segmentation::otsu_threshold(dwi), + (int)tipl::segmentation::otsu_threshold(dwi), (int)*std::min_element(dwi.begin(),dwi.end()), (int)*std::max_element(dwi.begin(),dwi.end())+1,1,&ok); if (!ok) return; - image::threshold(dwi,handle->voxel.mask,threshold); + tipl::threshold(dwi,handle->voxel.mask,threshold); on_SlicePos_valueChanged(ui->SlicePos->value()); } @@ -654,7 +654,7 @@ void reconstruction_window::on_manual_reg_clicked() std::shared_ptr manual(new manual_alignment(this, dwi,handle->voxel.vs, fa_template_imp.I,fa_template_imp.vs, - image::reg::affine,image::reg::cost_type::corr)); + tipl::reg::affine,tipl::reg::cost_type::corr)); if(manual->exec() == QDialog::Accepted) handle->voxel.qsdr_trans = manual->T; } @@ -766,8 +766,8 @@ void reconstruction_window::on_actionSave_bvecs_triggered() void reconstruction_window::update_image(void) { dwi.resize(handle->voxel.dim); - float min = image::minimum(handle->dwi_sum); - float range = image::maximum(handle->dwi_sum)-min; + float min = tipl::minimum(handle->dwi_sum); + float range = tipl::maximum(handle->dwi_sum)-min; float r = range > 0.0 ? 255.9f/range:1.0f; for(unsigned int index = 0;index < dwi.size();++index) dwi[index] = (handle->dwi_sum[index]-min)*r; @@ -822,7 +822,7 @@ void reconstruction_window::on_actionFlip_xz_triggered() -bool load_image_from_files(QStringList filenames,image::basic_image& ref,image::vector<3>& vs); +bool load_image_from_files(QStringList filenames,tipl::image& ref,tipl::vector<3>& vs); void reconstruction_window::on_actionRotate_triggered() { QStringList filenames = QFileDialog::getOpenFileNames( @@ -831,22 +831,22 @@ void reconstruction_window::on_actionRotate_triggered() if( filenames.isEmpty()) return; - image::basic_image ref; - image::vector<3> vs; + tipl::image ref; + tipl::vector<3> vs; if(!load_image_from_files(filenames,ref,vs)) return; std::shared_ptr manual(new manual_alignment(this, dwi,handle->voxel.vs,ref,vs, - image::reg::rigid_body, - image::reg::cost_type::mutual_info)); + tipl::reg::rigid_body, + tipl::reg::cost_type::mutual_info)); manual->on_rerun_clicked(); if(manual->exec() != QDialog::Accepted) return; begin_prog("rotating"); - image::basic_image ref2(ref); - float m = image::median(ref2.begin(),ref2.end()); - image::multiply_constant_mt(ref,0.5f/m); + tipl::image ref2(ref); + float m = tipl::median(ref2.begin(),ref2.end()); + tipl::multiply_constant_mt(ref,0.5f/m); handle->rotate(ref,manual->iT); handle->voxel.vs = vs; handle->voxel.report += " The diffusion images were rotated and scaled to the space of "; @@ -891,24 +891,24 @@ void reconstruction_window::on_SlicePos_valueChanged(int position) { if (!dwi.size()) return; - buffer.resize(image::geometry<2>(dwi.width(),dwi.height())); + buffer.resize(tipl::geometry<2>(dwi.width(),dwi.height())); unsigned int offset = position*buffer.size(); std::copy(dwi.begin() + offset,dwi.begin()+ offset + buffer.size(),buffer.begin()); unsigned char* slice_image_ptr = &*dwi.begin() + buffer.size()* position; unsigned char* slice_mask = &*handle->voxel.mask.begin() + buffer.size()* position; - image::color_image buffer2(image::geometry<2>(dwi.width()*2,dwi.height())); - image::draw(buffer,buffer2,image::vector<2,int>()); + tipl::color_image buffer2(tipl::geometry<2>(dwi.width()*2,dwi.height())); + tipl::draw(buffer,buffer2,tipl::vector<2,int>()); for (unsigned int index = 0; index < buffer.size(); ++index) { unsigned char value = slice_image_ptr[index]; if (slice_mask[index]) - buffer[index] = image::rgb_color(255, value, value); + buffer[index] = tipl::rgb(255, value, value); else - buffer[index] = image::rgb_color(value, value, value); + buffer[index] = tipl::rgb(value, value, value); } - image::draw(buffer,buffer2,image::vector<2,int>(dwi.width(),0)); + tipl::draw(buffer,buffer2,tipl::vector<2,int>(dwi.width(),0)); buffer2.swap(buffer); double ratio = std::max(1.0, std::min(((double)ui->graphicsView->width()-5)/(double)buffer.width(), @@ -921,19 +921,19 @@ void reconstruction_window::on_SlicePos_valueChanged(int position) void rec_motion_correction(ImageModel* handle) { begin_prog("correcting"); - image::par_for2(handle->src_bvalues.size(),[&](int i,int id) + tipl::par_for2(handle->src_bvalues.size(),[&](int i,int id) { if(i == 0 || prog_aborted()) return; if(id == 0) check_prog(i*99/handle->src_bvalues.size(),100); - image::transformation_matrix arg; + tipl::transformation_matrix arg; bool terminated = false; - image::reg::two_way_linear_mr( - image::make_image(handle->src_dwi_data[0],handle->voxel.dim), + tipl::reg::two_way_linear_mr( + tipl::make_image(handle->src_dwi_data[0],handle->voxel.dim), handle->voxel.vs, - image::make_image(handle->src_dwi_data[i],handle->voxel.dim),handle->voxel.vs, - arg,image::reg::affine,image::reg::correlation(),terminated); + tipl::make_image(handle->src_dwi_data[i],handle->voxel.dim),handle->voxel.vs, + arg,tipl::reg::affine,tipl::reg::correlation(),terminated); handle->rotate_one_dwi(i,arg); }); check_prog(1,1); @@ -967,8 +967,8 @@ void reconstruction_window::on_half_sphere_toggled(bool checked) bool add_other_image(ImageModel* handle,QString name,QString filename,bool full_auto) { - image::basic_image ref; - image::vector<3> vs; + tipl::image ref; + tipl::vector<3> vs; gz_nifti in; if(!in.load_from_file(filename.toLocal8Bit().begin()) || !in.toLPS(ref)) { @@ -978,7 +978,7 @@ bool add_other_image(ImageModel* handle,QString name,QString filename,bool full_ QMessageBox::information(0,"Error","Not a valid nifti file",0); return false; } - image::transformation_matrix affine; + tipl::transformation_matrix affine; bool has_registered = false; for(unsigned int index = 0;index < handle->voxel.other_image.size();++index) if(ref.geometry() == handle->voxel.other_image[index].geometry()) @@ -992,19 +992,19 @@ bool add_other_image(ImageModel* handle,QString name,QString filename,bool full_ if(full_auto) { std::cout << "add " << filename.toStdString() << " as " << name.toStdString() << std::endl; - image::basic_image from(handle->dwi_sum),to(ref); - image::normalize(from,1.0); - image::normalize(to,1.0); + tipl::image from(handle->dwi_sum),to(ref); + tipl::normalize(from,1.0); + tipl::normalize(to,1.0); bool terminated = false; - image::affine_transform arg; - image::reg::linear_mr(from,handle->voxel.vs,to,vs,arg,image::reg::rigid_body,image::reg::mutual_information(),terminated,0.1); - image::reg::linear_mr(from,handle->voxel.vs,to,vs,arg,image::reg::rigid_body,image::reg::mutual_information(),terminated,0.01); - affine = image::transformation_matrix(arg,handle->voxel.dim,handle->voxel.vs,to.geometry(),vs); + tipl::affine_transform arg; + tipl::reg::linear_mr(from,handle->voxel.vs,to,vs,arg,tipl::reg::rigid_body,tipl::reg::mutual_information(),terminated,0.1); + tipl::reg::linear_mr(from,handle->voxel.vs,to,vs,arg,tipl::reg::rigid_body,tipl::reg::mutual_information(),terminated,0.01); + affine = tipl::transformation_matrix(arg,handle->voxel.dim,handle->voxel.vs,to.geometry(),vs); } else { std::shared_ptr manual(new manual_alignment(0, - handle->dwi_sum,handle->voxel.vs,ref,vs,image::reg::rigid_body,image::reg::cost_type::mutual_info)); + handle->dwi_sum,handle->voxel.vs,ref,vs,tipl::reg::rigid_body,tipl::reg::cost_type::mutual_info)); manual->on_rerun_clicked(); if(manual->exec() != QDialog::Accepted) return false; @@ -1031,7 +1031,7 @@ void reconstruction_window::on_add_t1t2_clicked() void reconstruction_window::on_actionManual_Rotation_triggered() { std::shared_ptr manual( - new manual_alignment(this,dwi,handle->voxel.vs,dwi,handle->voxel.vs,image::reg::rigid_body,image::reg::cost_type::mutual_info)); + new manual_alignment(this,dwi,handle->voxel.vs,dwi,handle->voxel.vs,tipl::reg::rigid_body,tipl::reg::cost_type::mutual_info)); if(manual->exec() != QDialog::Accepted) return; begin_prog("rotating"); @@ -1050,8 +1050,8 @@ void reconstruction_window::on_actionReplace_b0_by_T2W_image_triggered() "Images (*.nii *nii.gz);;All files (*)" ); if( filename.isEmpty()) return; - image::basic_image ref; - image::vector<3> vs; + tipl::image ref; + tipl::vector<3> vs; gz_nifti in; if(!in.load_from_file(filename.toLocal8Bit().begin()) || !in.toLPS(ref)) { @@ -1059,7 +1059,7 @@ void reconstruction_window::on_actionReplace_b0_by_T2W_image_triggered() return; } in.get_voxel_size(vs.begin()); - std::shared_ptr manual(new manual_alignment(this,dwi,handle->voxel.vs,ref,vs,image::reg::rigid_body,image::reg::cost_type::corr)); + std::shared_ptr manual(new manual_alignment(this,dwi,handle->voxel.vs,ref,vs,tipl::reg::rigid_body,tipl::reg::cost_type::corr)); manual->on_rerun_clicked(); if(manual->exec() != QDialog::Accepted) return; @@ -1067,7 +1067,7 @@ void reconstruction_window::on_actionReplace_b0_by_T2W_image_triggered() begin_prog("rotating"); handle->rotate(ref,manual->iT); handle->voxel.vs = vs; - image::pointer_image I = image::make_image((unsigned short*)handle->src_dwi_data[0],handle->voxel.dim); + tipl::pointer_image I = tipl::make_image((unsigned short*)handle->src_dwi_data[0],handle->voxel.dim); ref *= (float)(*std::max_element(I.begin(),I.end()))/(*std::max_element(ref.begin(),ref.end())); std::copy(ref.begin(),ref.end(),I.begin()); update_image(); @@ -1124,22 +1124,22 @@ void reconstruction_window::on_actionImage_upsample_to_T1W_TESTING_triggered() if( filenames.isEmpty()) return; - image::basic_image ref; - image::vector<3> vs; + tipl::image ref; + tipl::vector<3> vs; if(!load_image_from_files(filenames,ref,vs)) return; std::shared_ptr manual(new manual_alignment(this, dwi,handle->voxel.vs,ref,vs, - image::reg::rigid_body, - image::reg::cost_type::mutual_info)); + tipl::reg::rigid_body, + tipl::reg::cost_type::mutual_info)); manual->on_rerun_clicked(); if(manual->exec() != QDialog::Accepted) return; begin_prog("rotating"); - image::basic_image ref2(ref); - float m = image::median(ref2.begin(),ref2.end()); - image::multiply_constant_mt(ref,0.5f/m); + tipl::image ref2(ref); + float m = tipl::median(ref2.begin(),ref2.end()); + tipl::multiply_constant_mt(ref,0.5f/m); handle->rotate(ref,manual->iT,true); handle->voxel.vs = vs; handle->voxel.report += " The diffusion images were rotated and scaled to the space of "; diff --git a/reconstruction/reconstruction_window.h b/reconstruction/reconstruction_window.h index 9475182f9..780e324f3 100644 --- a/reconstruction/reconstruction_window.h +++ b/reconstruction/reconstruction_window.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include namespace Ui { @@ -28,21 +28,21 @@ class reconstruction_window : public QMainWindow void closeEvent(QCloseEvent *event); private: QGraphicsScene source; - image::color_image buffer_source; + tipl::color_image buffer_source; QImage source_image; float max_source_value,source_ratio; void load_b_table(void); private: QGraphicsScene scene; - image::color_image buffer; + tipl::color_image buffer; QImage slice_image; - image::value_to_color v2c; + tipl::value_to_color v2c; private: Ui::reconstruction_window *ui; std::auto_ptr handle; float params[5]; - image::basic_imagedwi; + tipl::imagedwi; bool load_src(int index); void update_dimension(void); void update_image(void); diff --git a/regtoolbox.h b/regtoolbox.h index d6b4dd5fc..c5ea4548e 100644 --- a/regtoolbox.h +++ b/regtoolbox.h @@ -5,7 +5,7 @@ #include #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" namespace Ui { class RegToolBox; } @@ -16,26 +16,26 @@ class RegToolBox : public QMainWindow Q_OBJECT public: - image::basic_image It,I,J,JJ; - image::basic_image,3> dis; - image::vector<3> Itvs,Ivs; + tipl::image It,I,J,JJ; + tipl::image,3> dis; + tipl::vector<3> Itvs,Ivs; float ItR[12]; public: - image::basic_image J_view,J_view2; - image::basic_image,3> dis_view; + tipl::image J_view,J_view2; + tipl::image,3> dis_view; public: - image::affine_transform arg; - image::thread thread; + tipl::affine_transform arg; + tipl::thread thread; std::shared_ptr timer; std::string status; public: - std::shared_ptr > bnorm_data; + std::shared_ptr > bnorm_data; int reg_type; bool reg_done; private: void clear(void); - void linear_reg(image::reg::reg_type reg_type); + void linear_reg(tipl::reg::reg_type reg_type); void nonlinear_reg(int method); public: @@ -73,7 +73,7 @@ private slots: Ui::RegToolBox *ui; QGraphicsScene It_scene,I_scene; private: - image::color_image cIt,cI,cJ; + tipl::color_image cIt,cI,cJ; }; diff --git a/simulation.cpp b/simulation.cpp index d6e6870d6..c39e9ce74 100644 --- a/simulation.cpp +++ b/simulation.cpp @@ -7,8 +7,8 @@ #include "racian_noise.hpp" #include "layout.hpp" -image::normal_dist RacianNoise::gen_normal; -image::uniform_dist RacianNoise::gen_uniform; +tipl::normal_dist RacianNoise::gen_normal; +tipl::uniform_dist RacianNoise::gen_uniform; std::string error_msg; diff --git a/tracking/color_bar_dialog.cpp b/tracking/color_bar_dialog.cpp index b6587fbdd..dd9b18c66 100644 --- a/tracking/color_bar_dialog.cpp +++ b/tracking/color_bar_dialog.cpp @@ -98,8 +98,8 @@ void color_bar_dialog::update_color_map(void) if(ui->color_bar_style->currentIndex() == 0) { - image::rgb_color from_color = ui->color_from->color().rgb(); - image::rgb_color to_color = ui->color_to->color().rgb(); + tipl::rgb from_color = ui->color_from->color().rgb(); + tipl::rgb to_color = ui->color_to->color().rgb(); bar.two_color(from_color,to_color); std::swap(from_color.r,from_color.b); std::swap(to_color.r,to_color.b); diff --git a/tracking/color_bar_dialog.hpp b/tracking/color_bar_dialog.hpp index 74fe14a83..5256b9433 100644 --- a/tracking/color_bar_dialog.hpp +++ b/tracking/color_bar_dialog.hpp @@ -1,6 +1,6 @@ #ifndef COLOR_BAR_DIALOG_HPP #define COLOR_BAR_DIALOG_HPP -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include #include @@ -14,9 +14,9 @@ class color_bar_dialog : public QDialog { Q_OBJECT public:// color_bar - image::color_map color_map; - image::color_map_rgb color_map_rgb; - image::color_bar bar; + tipl::color_map color_map; + tipl::color_map_rgb color_map_rgb; + tipl::color_bar bar; QGraphicsScene color_bar; float color_r,color_min; public: @@ -25,11 +25,11 @@ class color_bar_dialog : public QDialog explicit color_bar_dialog(QWidget *parent = 0); ~color_bar_dialog(); public: - const image::vector<3,float>& get_color(float value) const + const tipl::vector<3,float>& get_color(float value) const { return color_map[std::floor(std::min(1.0f,(std::max(value-color_min,0.0))/color_r)*255.0+0.49)]; } - const image::rgb_color& get_rgb(float value) const + const tipl::rgb& get_rgb(float value) const { return color_map_rgb[std::floor(std::min(1.0f,(std::max(value-color_min,0.0))/color_r)*255.0+0.49)]; } diff --git a/tracking/connectivity_matrix_dialog.cpp b/tracking/connectivity_matrix_dialog.cpp index ad255399d..0b13ca999 100644 --- a/tracking/connectivity_matrix_dialog.cpp +++ b/tracking/connectivity_matrix_dialog.cpp @@ -103,7 +103,7 @@ void connectivity_matrix_dialog::on_recalculate_clicked() for(unsigned int index = 0;index < cur_tracking_window->regionWidget->regions.size();++index) if(cur_tracking_window->regionWidget->item(index,0)->checkState() == Qt::Checked) { - data.regions.push_back(std::vector >()); + data.regions.push_back(std::vector >()); cur_tracking_window->regionWidget->regions[index]->get_region_voxels(data.regions.back()); data.region_name.push_back(std::string(cur_tracking_window->regionWidget->item(index,0)->text().toLocal8Bit().begin())); } diff --git a/tracking/connectivity_matrix_dialog.h b/tracking/connectivity_matrix_dialog.h index c25c4c92c..8cfbab80e 100644 --- a/tracking/connectivity_matrix_dialog.h +++ b/tracking/connectivity_matrix_dialog.h @@ -2,7 +2,7 @@ #define CONNECTIVITY_MATRIX_DIALOG_H #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "libs/tracking/tract_model.hpp" class TractModel; @@ -15,7 +15,7 @@ class tracking_window; class connectivity_matrix_dialog : public QDialog { Q_OBJECT - image::color_image cm; + tipl::color_image cm; QImage view_image; QGraphicsScene scene; QString method; diff --git a/tracking/region/RegionModel.cpp b/tracking/region/RegionModel.cpp index 29a9ecef4..cf3606b8b 100644 --- a/tracking/region/RegionModel.cpp +++ b/tracking/region/RegionModel.cpp @@ -52,21 +52,21 @@ void RegionModel::sortIndices(void) -bool RegionModel::load(const std::vector >& seeds, double scale,unsigned char smooth) +bool RegionModel::load(const std::vector >& seeds, double scale,unsigned char smooth) { if(seeds.empty()) return false; - image::vector<3,short> max_value(seeds[0]), min_value(seeds[0]); - image::bounding_box_mt(seeds,max_value,min_value); + tipl::vector<3,short> max_value(seeds[0]), min_value(seeds[0]); + tipl::bounding_box_mt(seeds,max_value,min_value); center = max_value; center += min_value; center *= 0.5; center /= scale; - max_value += image::vector<3,short>(5, 5, 5); - min_value -= image::vector<3,short>(5, 5, 5); - image::geometry<3> geo(max_value[0] - min_value[0], + max_value += tipl::vector<3,short>(5, 5, 5); + min_value -= tipl::vector<3,short>(5, 5, 5); + tipl::geometry<3> geo(max_value[0] - min_value[0], max_value[1] - min_value[1], max_value[2] - min_value[2]); float cur_scale = 1.0; while(geo.width() > 256 || geo.height() > 256 || geo.depth() > 256) @@ -78,36 +78,36 @@ bool RegionModel::load(const std::vector >& seeds, double } - image::basic_imagebuffer(geo); - image::par_for(seeds.size(),[&](unsigned int index) + tipl::imagebuffer(geo); + tipl::par_for(seeds.size(),[&](unsigned int index) { - image::vector<3,short> point(seeds[index]); + tipl::vector<3,short> point(seeds[index]); point -= min_value; point /= cur_scale; - buffer[image::pixel_index<3>(point[0], point[1], point[2], + buffer[tipl::pixel_index<3>(point[0], point[1], point[2], buffer.geometry()).index()] = 200; }); while(smooth) { - image::filter::mean(buffer); + tipl::filter::mean(buffer); --smooth; } - object.reset(new image::march_cube >(buffer, 20)); + object.reset(new tipl::march_cube >(buffer, 20)); if (object->point_list.empty()) { object.reset(0); return 0; } - image::vector<3,float>shift(min_value); + tipl::vector<3,float>shift(min_value); if (scale != 1.0) { cur_scale /= scale; shift /= scale; } - image::par_for(object->point_list.size(),[&](unsigned int index) + tipl::par_for(object->point_list.size(),[&](unsigned int index) { if (cur_scale != 1.0) object->point_list[index] *= cur_scale; @@ -117,16 +117,16 @@ bool RegionModel::load(const std::vector >& seeds, double return object.get(); } -bool RegionModel::load(const image::basic_image& image_, +bool RegionModel::load(const tipl::image& image_, float threshold) { - image::basic_image image_buffer(image_); + tipl::image image_buffer(image_); float scale = 1.0; while(image_buffer.width() > 256 || image_buffer.height() > 256 || image_buffer.depth() > 256) { scale *= 2.0; - image::downsampling(image_buffer); + tipl::downsampling(image_buffer); } if (threshold == 0.0) { @@ -147,7 +147,7 @@ bool RegionModel::load(const image::basic_image& image_, return false; threshold = sum / num * 0.85; } - object.reset(new image::march_cube >(image_buffer, + object.reset(new tipl::march_cube >(image_buffer, threshold)); if (scale != 1.0) for (unsigned int index = 0; index < object->point_list.size(); ++index) @@ -157,16 +157,16 @@ bool RegionModel::load(const image::basic_image& image_, } // --------------------------------------------------------------------------- -bool RegionModel::load(unsigned int* buffer, image::geometry<3>geo, +bool RegionModel::load(unsigned int* buffer, tipl::geometry<3>geo, unsigned int threshold) { - image::basic_imagere_buffer(geo); + tipl::imagere_buffer(geo); for (unsigned int index = 0; index < re_buffer.size(); ++index) re_buffer[index] = buffer[index] > threshold ? 200 : 0; - image::filter::mean(re_buffer); + tipl::filter::mean(re_buffer); - object.reset(new image::march_cube >(re_buffer, 50)); + object.reset(new tipl::march_cube >(re_buffer, 50)); if (object->point_list.empty()) object.reset(0); else @@ -174,10 +174,10 @@ bool RegionModel::load(unsigned int* buffer, image::geometry<3>geo, return object.get(); } -void RegionModel::move_object(const image::vector<3,float>& shift) +void RegionModel::move_object(const tipl::vector<3,float>& shift) { if(!object.get()) return; - image::add_constant(object->point_list,shift); + tipl::add_constant(object->point_list,shift); } diff --git a/tracking/region/RegionModel.h b/tracking/region/RegionModel.h index 29620e667..77b6b700e 100644 --- a/tracking/region/RegionModel.h +++ b/tracking/region/RegionModel.h @@ -4,18 +4,18 @@ #define RegionModelH #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" // --------------------------------------------------------------------------- class RegionModel { public: - typedef image::march_cube >mesh_type; + typedef tipl::march_cube >mesh_type; std::auto_ptr object; std::vector > sorted_index; - image::vector<3,float> center; + tipl::vector<3,float> center; void sortIndices(void); public: float alpha; - image::rgb_color color; + tipl::rgb color; RegionModel(void) { alpha = 0.6f; color = (unsigned int)0x00FFFFFF; @@ -28,15 +28,15 @@ class RegionModel { } const RegionModel& operator = (const RegionModel & rhs); // bool load_from_file(const char* file_name); - bool load(const image::basic_image& image_, float threshold_); - bool load(const std::vector >& region, double scale,unsigned char smooth); - //bool load(const image::basic_image& mask,unsigned char threshold); - bool load(unsigned int* buffer, image::geometry<3>geo, unsigned int threshold); + bool load(const tipl::image& image_, float threshold_); + bool load(const std::vector >& region, double scale,unsigned char smooth); + //bool load(const tipl::image& mask,unsigned char threshold); + bool load(unsigned int* buffer, tipl::geometry<3>geo, unsigned int threshold); mesh_type* get(void) {return object.get();} const std::vector& getSortedIndex(unsigned char view) const {return sorted_index[view];} - void move_object(const image::vector<3,float>& shift); + void move_object(const tipl::vector<3,float>& shift); }; #endif diff --git a/tracking/region/Regions.cpp b/tracking/region/Regions.cpp index fc9f4c3be..0656beee0 100644 --- a/tracking/region/Regions.cpp +++ b/tracking/region/Regions.cpp @@ -6,19 +6,19 @@ #include "SliceModel.h" #include "libs/gzip_interface.hpp" -image::geometry<3> ROIRegion::get_buffer_dim(void) const +tipl::geometry<3> ROIRegion::get_buffer_dim(void) const { - return image::geometry<3>(handle->dim[0]*resolution_ratio, + return tipl::geometry<3>(handle->dim[0]*resolution_ratio, handle->dim[1]*resolution_ratio, handle->dim[2]*resolution_ratio); } -void ROIRegion::add_points(std::vector >& points,bool del,float point_resolution) +void ROIRegion::add_points(std::vector >& points,bool del,float point_resolution) { if(resolution_ratio > 32.0f) return; change_resolution(points,point_resolution); - std::vector > new_points(points.size()); + std::vector > new_points(points.size()); for(int i = 0;i < points.size();++i) { points[i].round(); @@ -27,7 +27,7 @@ void ROIRegion::add_points(std::vector >& points,bool del add_points(new_points,del,resolution_ratio); } // --------------------------------------------------------------------------- -void ROIRegion::add_points(std::vector >& points, bool del,float point_resolution) +void ROIRegion::add_points(std::vector >& points, bool del,float point_resolution) { if(resolution_ratio > 32.0f) return; @@ -47,7 +47,7 @@ void ROIRegion::add_points(std::vector >& points, bool de } else { - image::geometry<3> new_geo = get_buffer_dim(); + tipl::geometry<3> new_geo = get_buffer_dim(); for(unsigned int index = 0; index < points.size();) if (!new_geo.is_valid(points[index][0], points[index][1], points[index][2])) { @@ -68,12 +68,12 @@ void ROIRegion::add_points(std::vector >& points, bool de region.insert(region.end(),points.begin(),points.end()); points.clear(); } - image::vector<3,short> min_value,max_value,geo_size; - image::bounding_box_mt(region,max_value,min_value); + tipl::vector<3,short> min_value,max_value,geo_size; + tipl::bounding_box_mt(region,max_value,min_value); geo_size = max_value-min_value; - image::geometry<3> mask_geo(geo_size[0]+1,geo_size[1]+1,geo_size[2]+1); - image::basic_image mask; + tipl::geometry<3> mask_geo(geo_size[0]+1,geo_size[1]+1,geo_size[2]+1); + tipl::image mask; try { @@ -86,7 +86,7 @@ void ROIRegion::add_points(std::vector >& points, bool de goto alternative; } - image::par_for (region.size(),[&](unsigned int index) + tipl::par_for (region.size(),[&](unsigned int index) { auto p = region[index]; p -= min_value; @@ -95,7 +95,7 @@ void ROIRegion::add_points(std::vector >& points, bool de }); if(points.size()) - image::par_for (points.size(),[&](unsigned int index) + tipl::par_for (points.size(),[&](unsigned int index) { auto p = points[index]; p -= min_value; @@ -105,9 +105,9 @@ void ROIRegion::add_points(std::vector >& points, bool de points.clear(); region.clear(); - for(image::pixel_index<3> index(mask.geometry());index.is_valid(mask.geometry());++index) + for(tipl::pixel_index<3> index(mask.geometry());index.is_valid(mask.geometry());++index) if(mask[index.index()]) - region.push_back(image::vector<3,short>(index[0]+min_value[0], + region.push_back(tipl::vector<3,short>(index[0]+min_value[0], index[1]+min_value[1], index[2]+min_value[2])); } @@ -121,8 +121,8 @@ void ROIRegion::add_points(std::vector >& points, bool de region.swap(points); else { - std::vector > union_points(region.size()+points.size()); - std::vector >::iterator it = + std::vector > union_points(region.size()+points.size()); + std::vector >::iterator it = std::set_union(region.begin(),region.end(), points.begin(),points.end(), union_points.begin()); @@ -133,14 +133,14 @@ void ROIRegion::add_points(std::vector >& points, bool de else { // find interset first - std::vector > intersect_points(std::max(region.size(),points.size())); - std::vector >::iterator it = + std::vector > intersect_points(std::max(region.size(),points.size())); + std::vector >::iterator it = std::set_intersection(region.begin(),region.end(), points.begin(),points.end(), intersect_points.begin()); intersect_points.resize(it-intersect_points.begin()); - std::vector > remain_points(region.size()); + std::vector > remain_points(region.size()); it = std::set_difference(region.begin(),region.end(), intersect_points.begin(),intersect_points.end(), remain_points.begin()); @@ -166,36 +166,36 @@ void ROIRegion::SaveToFile(const char* FileName) if (ext == std::string(".txt")) { std::ofstream out(FileName); - std::copy(region.begin(), region.end(),std::ostream_iterator >(out, "\n")); + std::copy(region.begin(), region.end(),std::ostream_iterator >(out, "\n")); if(resolution_ratio != 1.0) out << resolution_ratio << " -1 -1" << std::endl; } else if (ext == std::string(".mat")) { if(resolution_ratio > 32.0f) return; - image::basic_image mask(handle->dim); + tipl::image mask(handle->dim); if(resolution_ratio != 1.0) mask.resize(get_buffer_dim()); for (unsigned int index = 0; index < region.size(); ++index) { if (handle->dim.is_valid(region[index][0], region[index][1], region[index][2])) - mask[image::pixel_index<3>(region[index][0], region[index][1], + mask[tipl::pixel_index<3>(region[index][0], region[index][1], region[index][2], handle->dim).index()] = 255; } - image::io::mat_write header(FileName); + tipl::io::mat_write header(FileName); header << mask; } else if (ext == std::string(".nii") || ext == std::string("i.gz")) { unsigned int color = show_region.color.color & 0x00FFFFFF; - image::basic_imagemask; + tipl::imagemask; SaveToBuffer(mask,1); gz_nifti header; if(resolution_ratio == 1.0) header.set_voxel_size(handle->vs.begin()); else { - image::vector<3,float> rvs = handle->vs; + tipl::vector<3,float> rvs = handle->vs; rvs /= resolution_ratio; header.set_voxel_size(rvs.begin()); } @@ -211,15 +211,15 @@ void ROIRegion::SaveToFile(const char* FileName) if(resolution_ratio != 1.0) { std::vector T(trans); - image::multiply_constant(&T[0],&T[0]+3,1.0/resolution_ratio); - image::multiply_constant(&T[4],&T[0]+3,1.0/resolution_ratio); - image::multiply_constant(&T[8],&T[0]+3,1.0/resolution_ratio); + tipl::multiply_constant(&T[0],&T[0]+3,1.0/resolution_ratio); + tipl::multiply_constant(&T[4],&T[0]+3,1.0/resolution_ratio); + tipl::multiply_constant(&T[8],&T[0]+3,1.0/resolution_ratio); header.set_LPS_transformation(T.begin(),mask.geometry()); } else header.set_LPS_transformation(trans.begin(),mask.geometry()); } - image::flip_xy(mask); + tipl::flip_xy(mask); header << mask; header.save_to_file(FileName); } @@ -243,9 +243,9 @@ bool ROIRegion::LoadFromFile(const char* FileName) { if (ext == std::string(".txt")) { std::ifstream in(FileName,std::ios::binary); - std::vector > points; - std::copy(std::istream_iterator >(in), - std::istream_iterator >(), + std::vector > points; + std::copy(std::istream_iterator >(in), + std::istream_iterator >(), std::back_inserter(points)); if(!points.empty() && points.back()[1] == -1.0f && points.back()[2] == -1.0f) { @@ -257,10 +257,10 @@ bool ROIRegion::LoadFromFile(const char* FileName) { } if (ext == std::string(".mat")) { - image::io::mat_read header; + tipl::io::mat_read header; if(!header.load_from_file(FileName)) return false; - image::basic_imagefrom; + tipl::imagefrom; header >> from; if(from.geometry() != handle->dim) { @@ -271,10 +271,10 @@ bool ROIRegion::LoadFromFile(const char* FileName) { return false; resolution_ratio = r1; } - std::vector > points; - for (image::pixel_index<3> index(from.geometry());index < from.size();++index) + std::vector > points; + for (tipl::pixel_index<3> index(from.geometry());index < from.size();++index) if (from[index.index()]) - points.push_back(image::vector<3,short>((const unsigned int*)index.begin())); + points.push_back(tipl::vector<3,short>((const unsigned int*)index.begin())); add_points(points,false,resolution_ratio); return true; } @@ -285,8 +285,8 @@ bool ROIRegion::LoadFromFile(const char* FileName) { if (!header.load_from_file(FileName)) return false; // use unsigned int to avoid the nan background problem - image::basic_imagefrom; - image::geometry<3> nii_geo; + tipl::imagefrom; + tipl::geometry<3> nii_geo; header.get_image_dimension(nii_geo); if(nii_geo != handle->dim)// use transformation information { @@ -306,7 +306,7 @@ bool ROIRegion::LoadFromFile(const char* FileName) { if(trans.empty()) return false; header >> from; - image::matrix<4,4,float> t; + tipl::matrix<4,4,float> t; t.identity(); header.get_image_transformation(t.begin()); t.inv(); @@ -315,9 +315,9 @@ bool ROIRegion::LoadFromFile(const char* FileName) { return true; } { - image::basic_image tmp; + tipl::image tmp; header.toLPS(tmp); - image::add_constant(tmp,0.5); + tipl::add_constant(tmp,0.5); from = tmp; } LoadFromBuffer(from); @@ -335,14 +335,14 @@ void ROIRegion::makeMeshes(unsigned char smooth) show_region.load(region,resolution_ratio,smooth); } // --------------------------------------------------------------------------- -void ROIRegion::SaveToBuffer(image::basic_image& mask, +void ROIRegion::SaveToBuffer(tipl::image& mask, unsigned char value) { if(resolution_ratio != 1.0) mask.resize(get_buffer_dim()); else mask.resize(handle->dim); std::fill(mask.begin(), mask.end(), 0); - image::par_for (region.size(),[&](unsigned int index) + tipl::par_for (region.size(),[&](unsigned int index) { if (mask.geometry().is_valid(region[index])) mask.at(region[index][0], region[index][1],region[index][2]) = value; @@ -351,35 +351,35 @@ void ROIRegion::SaveToBuffer(image::basic_image& mask, // --------------------------------------------------------------------------- void ROIRegion::perform(const std::string& action) { - image::basic_imagemask; + tipl::imagemask; if(action == "smoothing") { SaveToBuffer(mask, 1); - image::morphology::smoothing(mask); + tipl::morphology::smoothing(mask); LoadFromBuffer(mask); } if(action == "erosion") { SaveToBuffer(mask, 1); - image::morphology::erosion(mask); + tipl::morphology::erosion(mask); LoadFromBuffer(mask); } if(action == "dilation") { SaveToBuffer(mask, 1); - image::morphology::dilation(mask); + tipl::morphology::dilation(mask); LoadFromBuffer(mask); } if(action == "defragment") { SaveToBuffer(mask, 1); - image::morphology::defragment(mask); + tipl::morphology::defragment(mask); LoadFromBuffer(mask); } if(action == "negate") { SaveToBuffer(mask, 1); - image::morphology::negate(mask); + tipl::morphology::negate(mask); LoadFromBuffer(mask); } if(action == "flipx") @@ -389,17 +389,17 @@ void ROIRegion::perform(const std::string& action) if(action == "flipz") Flip(2); if(action == "shiftx") - shift(image::vector<3,float>(1.0, 0, 0)); + shift(tipl::vector<3,float>(1.0, 0, 0)); if(action == "shiftnx") - shift(image::vector<3,float>(-1.0, 0, 0)); + shift(tipl::vector<3,float>(-1.0, 0, 0)); if(action == "shifty") - shift(image::vector<3,float>(0, 1.0, 0)); + shift(tipl::vector<3,float>(0, 1.0, 0)); if(action == "shiftny") - shift(image::vector<3,float>(0, -1.0, 0)); + shift(tipl::vector<3,float>(0, -1.0, 0)); if(action == "shiftz") - shift(image::vector<3,float>(0, 0, 1.0)); + shift(tipl::vector<3,float>(0, 0, 1.0)); if(action == "shiftnz") - shift(image::vector<3,float>(0, 0, -1.0)); + shift(tipl::vector<3,float>(0, 0, -1.0)); } // --------------------------------------------------------------------------- @@ -413,12 +413,12 @@ void ROIRegion::Flip(unsigned int dimension) { } // --------------------------------------------------------------------------- -void ROIRegion::shift(image::vector<3,float> dx) { +void ROIRegion::shift(tipl::vector<3,float> dx) { show_region.move_object(dx); if(resolution_ratio != 1.0) dx *= resolution_ratio; dx.round(); - image::par_for(region.size(),[&](unsigned int index) + tipl::par_for(region.size(),[&](unsigned int index) { region[index] += dx; }); @@ -432,10 +432,10 @@ void calculate_region_stat(const Image& I, const Points& p,float& mean,float& sd for(unsigned int index = 0; index < p.size(); ++index) { float value = 0.0; - image::vector<3> pos(p[index]); + tipl::vector<3> pos(p[index]); if(T) pos.to(T); - value = image::estimate(I,pos); + value = tipl::estimate(I,pos); if(value == 0.0) continue; sum += value; @@ -458,8 +458,8 @@ void ROIRegion::get_quantitative_data(std::shared_ptr handle,std::vect data.push_back(region.size()*handle->vs[0]*handle->vs[1]*handle->vs[2]/resolution_ratio); //volume (mm^3) if(region.empty()) return; - image::vector<3,float> cm; - image::vector<3,float> max(region[0]),min(region[0]); + tipl::vector<3,float> cm; + tipl::vector<3,float> max(region[0]),min(region[0]); for (unsigned int index = 0; index < region.size(); ++index) { cm += region[index]; @@ -487,9 +487,9 @@ void ROIRegion::get_quantitative_data(std::shared_ptr handle,std::vect std::copy(min.begin(),min.end(),std::back_inserter(data)); // bounding box handle->get_index_titles(titles); // other index - std::vector > points; + std::vector > points; for (unsigned int index = 0; index < region.size(); ++index) - points.push_back(image::vector<3>(region[index][0]/resolution_ratio, + points.push_back(tipl::vector<3>(region[index][0]/resolution_ratio, region[index][1]/resolution_ratio, region[index][2]/resolution_ratio)); @@ -499,7 +499,7 @@ void ROIRegion::get_quantitative_data(std::shared_ptr handle,std::vect if(handle->view_item[data_index].name == "color") continue; float mean,sd; - image::const_pointer_image I(handle->view_item[data_index].image_data); + tipl::const_pointer_image I(handle->view_item[data_index].image_data); if(handle->view_item[data_index].image_data.geometry() != handle->dim) calculate_region_stat(I,points,mean,sd,&handle->view_item[data_index].iT[0]); else @@ -515,7 +515,7 @@ void ROIRegion::get_quantitative_data(std::shared_ptr handle,std::vect std::vector > fa_data; handle->db.get_subject_fa(subject_index,fa_data); float mean,sd; - image::const_pointer_image I(&fa_data[0][0],handle->dim); + tipl::const_pointer_image I(&fa_data[0][0],handle->dim); calculate_region_stat(I,points,mean,sd); data.push_back(mean); data.push_back(sd); diff --git a/tracking/region/Regions.h b/tracking/region/Regions.h index 99a85bb1b..864d3555e 100644 --- a/tracking/region/Regions.h +++ b/tracking/region/Regions.h @@ -4,7 +4,7 @@ #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "RegionModel.h" #include "fib_data.hpp" // --------------------------------------------------------------------------- @@ -19,10 +19,10 @@ const unsigned int terminate_id = 4; class ROIRegion { public: std::shared_ptr handle; - std::vector > region; + std::vector > region; bool modified; - std::vector > > undo_backup; - std::vector > > redo_backup; + std::vector > > undo_backup; + std::vector > > redo_backup; public: bool super_resolution = false; float resolution_ratio = 1.0; @@ -64,10 +64,10 @@ class ROIRegion { ROIRegion(std::shared_ptr handle_) : handle(handle_),modified(false){} - image::geometry<3> get_buffer_dim(void) const; - image::vector<3,short> get_region_voxel(unsigned int index) const + tipl::geometry<3> get_buffer_dim(void) const; + tipl::vector<3,short> get_region_voxel(unsigned int index) const { - image::vector<3,short> result = region[index]; + tipl::vector<3,short> result = region[index]; if(resolution_ratio == 1.0) return result; result[0] = (float)result[0]/resolution_ratio; @@ -75,7 +75,7 @@ class ROIRegion { result[2] = (float)result[2]/resolution_ratio; return result; } - void get_region_voxels(std::vector >& output) const + void get_region_voxels(std::vector >& output) const { output = region; if(resolution_ratio == 1.0) @@ -87,8 +87,8 @@ class ROIRegion { output[i][2] = (float)region[i][2]/resolution_ratio; } } - const std::vector >& get_region_voxels_raw(void) const {return region;} - void assign(const std::vector >& region_,float r) + const std::vector >& get_region_voxels_raw(void) const {return region;} + void assign(const std::vector >& region_,float r) { region = region_; resolution_ratio = r; @@ -110,17 +110,17 @@ class ROIRegion { } unsigned int size(void) const {return (unsigned int)region.size();} - std::vector >::const_iterator + std::vector >::const_iterator begin(void) const {return region.begin();} public: void add(const ROIRegion & rhs) { - std::vector > tmp(rhs.region); + std::vector > tmp(rhs.region); add_points(tmp,false,rhs.resolution_ratio); } template - void change_resolution(std::vector >& points,float point_resolution) + void change_resolution(std::vector >& points,float point_resolution) { if(point_resolution == resolution_ratio) return; @@ -128,22 +128,22 @@ class ROIRegion { if(resolution_ratio > point_resolution) { short limit = std::ceil(ratio); - std::vector > new_points; + std::vector > new_points; for(short dz = -limit;dz <= limit;++dz) for(short dy = -limit;dy <= limit;++dy) for(short dx = -limit;dx <= limit;++dx) - new_points.push_back(image::vector<3,short>(dx,dy,dz)); + new_points.push_back(tipl::vector<3,short>(dx,dy,dz)); - std::vector > pp(points.size()*new_points.size()); - image::par_for(points.size(),[&](int i) + std::vector > pp(points.size()*new_points.size()); + tipl::par_for(points.size(),[&](int i) { points[i] *= ratio; points[i].round(); unsigned int pos = i*new_points.size(); for(int j = 0;j < new_points.size();++j)// 1 for skip 0 0 0 { - image::vector<3,short> p(new_points[j]); + tipl::vector<3,short> p(new_points[j]); p += points[i]; pp[pos + j] = p; } @@ -151,15 +151,15 @@ class ROIRegion { pp.swap(points); } else - image::multiply_constant(points,ratio); + tipl::multiply_constant(points,ratio); } - void add_points(std::vector >& points,bool del,float point_resolution = 1.0); - void add_points(std::vector >& points,bool del,float point_resolution = 1.0); + void add_points(std::vector >& points,bool del,float point_resolution = 1.0); + void add_points(std::vector >& points,bool del,float point_resolution = 1.0); void undo(void) { if(region.empty() && undo_backup.empty()) return; - redo_backup.push_back(std::vector >()); + redo_backup.push_back(std::vector >()); redo_backup.back().swap(region); if(!undo_backup.empty()) { @@ -173,7 +173,7 @@ class ROIRegion { { if(redo_backup.empty()) return; - undo_backup.push_back(std::vector >()); + undo_backup.push_back(std::vector >()); undo_backup.back().swap(region); region.swap(redo_backup.back()); redo_backup.pop_back(); @@ -183,38 +183,38 @@ class ROIRegion { void SaveToFile(const char* FileName); bool LoadFromFile(const char* FileName); void Flip(unsigned int dimension); - void shift(image::vector<3,float> dx); + void shift(tipl::vector<3,float> dx); template - void LoadFromBuffer(const image_type& from,const image::matrix<4,4,float>& trans) + void LoadFromBuffer(const image_type& from,const tipl::matrix<4,4,float>& trans) { - std::vector > points; + std::vector > points; float det = std::fabs(trans.det()); if(det < 8) // from a low resolution image - for (image::pixel_index<3> index(handle->dim);index < handle->dim.size();++index) + for (tipl::pixel_index<3> index(handle->dim);index < handle->dim.size();++index) { - image::vector<3> p(index.begin()); + tipl::vector<3> p(index.begin()); p.to(trans); if (from.geometry().is_valid(p) && from.at(p[0],p[1],p[2]) != 0) - points.push_back(image::vector<3>(index.begin())); + points.push_back(tipl::vector<3>(index.begin())); } else// from a high resolution image { - image::matrix<4,4,float> inv(trans); + tipl::matrix<4,4,float> inv(trans); if(!inv.inv()) return; - for (image::pixel_index<3> index(from.geometry()); + for (tipl::pixel_index<3> index(from.geometry()); index < from.geometry().size();++index) if(from[index.index()]) { - image::vector<3> p(index.begin()); + tipl::vector<3> p(index.begin()); p.to(inv); if (handle->dim.is_valid(p)) - points.push_back(image::vector<3,float>(p[0],p[1],p[2])); + points.push_back(tipl::vector<3,float>(p[0],p[1],p[2])); } } det = std::round(det); - image::multiply_constant(points,det); + tipl::multiply_constant(points,det); region.clear(); add_points(points,false,det); } @@ -226,34 +226,34 @@ class ROIRegion { if(!region.empty()) undo_backup.push_back(region); region.clear(); - std::vector > points; - for (image::pixel_index<3>index(mask.geometry());index < mask.size();++index) + std::vector > points; + for (tipl::pixel_index<3>index(mask.geometry());index < mask.size();++index) if (mask[index.index()] != 0) - points.push_back(image::vector<3,short>(index.x(), index.y(),index.z())); + points.push_back(tipl::vector<3,short>(index.x(), index.y(),index.z())); if(mask.width() != handle->dim[0]) resolution_ratio = (float)mask.width()/(float)handle->dim[0]; region.swap(points); } - void SaveToBuffer(image::basic_image& mask,unsigned char value=255); + void SaveToBuffer(tipl::image& mask,unsigned char value=255); void perform(const std::string& action); void makeMeshes(unsigned char smooth); template - bool has_point(const image::vector<3,value_type>& point) const + bool has_point(const tipl::vector<3,value_type>& point) const { if(resolution_ratio != 1.0) { - image::vector<3,short> p(std::round(point[0]*resolution_ratio), + tipl::vector<3,short> p(std::round(point[0]*resolution_ratio), std::round(point[1]*resolution_ratio), std::round(point[2]*resolution_ratio)); return std::binary_search(region.begin(),region.end(),p); } - image::vector<3,short> p(std::round(point[0]), + tipl::vector<3,short> p(std::round(point[0]), std::round(point[1]), std::round(point[2])); return std::binary_search(region.begin(),region.end(),p); } template - bool has_points(const std::vector >& points) const + bool has_points(const std::vector >& points) const { for(unsigned int index = 0; index < points.size(); ++index) if(has_point(points[index])) diff --git a/tracking/region/regiontablewidget.cpp b/tracking/region/regiontablewidget.cpp index 0ed27fbd3..983da22ac 100644 --- a/tracking/region/regiontablewidget.cpp +++ b/tracking/region/regiontablewidget.cpp @@ -63,7 +63,7 @@ void ImageDelegate::setEditorData(QWidget *editor, else if (index.column() == 2) { - image::rgb_color color((unsigned int)(index.data(Qt::UserRole).toInt())); + tipl::rgb color((unsigned int)(index.data(Qt::UserRole).toInt())); ((QColorToolButton*)editor)->setColor( QColor(color.r,color.g,color.b)); } @@ -144,7 +144,7 @@ QColor RegionTableWidget::currentRowColor(void) } void RegionTableWidget::add_region_from_atlas(unsigned int atlas,unsigned int label) { - std::vector > points; + std::vector > points; add_region(atlas_list[atlas].get_list()[label].c_str(),roi_id); float r; cur_tracking_window.handle->get_atlas_roi(atlas,label,points,r); @@ -157,7 +157,7 @@ void RegionTableWidget::add_region(QString name,unsigned char feature,int color) { if(color == 0x00FFFFFF || !color) { - image::rgb_color c; + tipl::rgb c; c.from_hsl(((color_gen++)*1.1-std::floor((color_gen++)*1.1/6)*6)*3.14159265358979323846/3.0,0.85,0.7); color = c.color; } @@ -211,7 +211,7 @@ void RegionTableWidget::check_check_status(int row, int col) } } -void RegionTableWidget::draw_region(image::color_image& I) +void RegionTableWidget::draw_region(tipl::color_image& I) { auto current_slice = cur_tracking_window.current_slice; int slice_pos = current_slice->slice_pos[cur_tracking_window.cur_dim]; @@ -230,14 +230,14 @@ void RegionTableWidget::draw_region(image::color_image& I) { float r = checked_regions[roi_index]->resolution_ratio; unsigned int cur_color = checked_regions[roi_index]->show_region.color; - image::par_for(checked_regions[roi_index]->size(),[&](unsigned int index) + tipl::par_for(checked_regions[roi_index]->size(),[&](unsigned int index) { - image::vector<3,float> p(checked_regions[roi_index]->region[index]); + tipl::vector<3,float> p(checked_regions[roi_index]->region[index]); if(r != 1.0) p /= r; p.round(); int X, Y, Z; - image::space2slice(cur_tracking_window.cur_dim,p[0],p[1],p[2],X,Y,Z); + tipl::space2slice(cur_tracking_window.cur_dim,p[0],p[1],p[2],X,Y,Z); if (slice_pos != Z || X < 0 || Y < 0 || X >= I.width() || Y >= I.height()) return; unsigned int pos = X+Y*I.width(); @@ -249,14 +249,14 @@ void RegionTableWidget::draw_region(image::color_image& I) { //handle resolution_ratio = 1 all together { - image::basic_image buf(cur_tracking_window.handle->dim); + tipl::image buf(cur_tracking_window.handle->dim); for(unsigned int roi_index = 0;roi_index < checked_regions.size();++roi_index) { unsigned int cur_color = checked_regions[roi_index]->show_region.color; if(checked_regions[roi_index]->resolution_ratio == 1) - image::par_for(regions[roi_index]->size(),[&](unsigned int index) + tipl::par_for(regions[roi_index]->size(),[&](unsigned int index) { - image::pixel_index<3> pindex(regions[roi_index]->region[index][0], + tipl::pixel_index<3> pindex(regions[roi_index]->region[index][0], regions[roi_index]->region[index][1], regions[roi_index]->region[index][2],buf.geometry()); if(pindex.index() >= buf.size()) @@ -271,7 +271,7 @@ void RegionTableWidget::draw_region(image::color_image& I) current_slice->toDiffusionSpace(cur_tracking_window.cur_dim,x,y,dx,dy,dz); if(!buf.geometry().is_valid(dx,dy,dz)) continue; - image::pixel_index<3> pindex(dx,dy,dz,buf.geometry()); + tipl::pixel_index<3> pindex(dx,dy,dz,buf.geometry()); if(buf[pindex.index()] != 0) I[index] = (unsigned int)I[index] | buf[pindex.index()]; @@ -279,13 +279,13 @@ void RegionTableWidget::draw_region(image::color_image& I) } // now the most time consuming part with high resolution regions - image::par_for(checked_regions.size(),[&](unsigned int roi_index) + tipl::par_for(checked_regions.size(),[&](unsigned int roi_index) { if(checked_regions[roi_index]->resolution_ratio == 1) return; unsigned int cur_color = checked_regions[roi_index]->show_region.color; float r = checked_regions[roi_index]->resolution_ratio; - image::geometry<3> geo(cur_tracking_window.handle->dim); + tipl::geometry<3> geo(cur_tracking_window.handle->dim); geo[0] *= r; geo[1] *= r; geo[2] *= r; @@ -303,10 +303,10 @@ void RegionTableWidget::draw_region(image::color_image& I) y_pos.resize(geo[2]); y_pos[p[2]] = cur_color; - image::vector<3> v(p),v2; + tipl::vector<3> v(p),v2; v /= r; v.to(current_slice->invT); - image::space2slice(cur_tracking_window.cur_dim,v[0],v[1],v[2],v2[0],v2[1],v2[2]); + tipl::space2slice(cur_tracking_window.cur_dim,v[0],v[1],v[2],v2[0],v2[1],v2[2]); v2.round(); if(v2[2] == slice_pos && I.geometry().is_valid(v2)) { @@ -319,8 +319,8 @@ void RegionTableWidget::draw_region(image::color_image& I) for(int x = 0;x < I.width();++x,++index) { - image::vector<3,float> v; - image::slice2space(cur_tracking_window.cur_dim, x, y, + tipl::vector<3,float> v; + tipl::slice2space(cur_tracking_window.cur_dim, x, y, slice_pos, v[0],v[1],v[2]); v.to(current_slice->T); v *= r; @@ -349,8 +349,8 @@ void RegionTableWidget::draw_edge(QImage&,QImage&) return; /* int X, Y, Z; - image::basic_image cur_image_mask; - cur_image_mask.resize(image::geometry<2>(qimage.width(),qimage.height())); + tipl::image cur_image_mask; + cur_image_mask.resize(tipl::geometry<2>(qimage.width(),qimage.height())); for (unsigned int index = 0;index < regions[currentRow()]->size();++index) { regions[currentRow()]->getSlicePosition(cur_tracking_window.cur_dim, index, X, Y, Z); @@ -388,7 +388,7 @@ void RegionTableWidget::draw_edge(QImage&,QImage&) void RegionTableWidget::draw_mosaic_region(QImage& qimage,unsigned int mosaic_size,unsigned int skip) { - image::geometry<3> geo = cur_tracking_window.handle->dim; + tipl::geometry<3> geo = cur_tracking_window.handle->dim; unsigned int slice_number = geo[2] / skip; std::vector shift_x(slice_number),shift_y(slice_number); for(unsigned int z = 0;z < slice_number;++z) @@ -404,7 +404,7 @@ void RegionTableWidget::draw_mosaic_region(QImage& qimage,unsigned int mosaic_si unsigned int cur_color = regions[roi_index]->show_region.color; for (unsigned int index = 0;index < regions[roi_index]->size();++index) { - image::vector<3,short> p = regions[roi_index]->get_region_voxel(index); + tipl::vector<3,short> p = regions[roi_index]->get_region_voxel(index); if(p[2] != ((p[2] / skip) * skip)) continue; p[0] += shift_x[p[2] / skip]; @@ -468,7 +468,7 @@ void load_nii_label(const char* filename,std::map& label_map) } } void get_roi_label(QString file_name,std::map& label_map, - std::map& label_color,bool mute_cmd = true) + std::map& label_color,bool mute_cmd = true) { label_map.clear(); label_color.clear(); @@ -491,7 +491,7 @@ void get_roi_label(QString file_name,std::map& label_map, std::string name; in >> value >> name >> r >> g >> b; label_map[value] = name; - label_color[value] = image::rgb_color(r,g,b); + label_color[value] = tipl::rgb(r,g,b); } return; } @@ -513,17 +513,17 @@ bool RegionTableWidget::load_multiple_roi_nii(QString file_name) if (!header.load_from_file(file_name.toLocal8Bit().begin())) return false; - image::basic_image from; + tipl::image from; { - image::basic_image tmp; + tipl::image tmp; header.toLPS(tmp); - image::add_constant(tmp,0.5); + tipl::add_constant(tmp,0.5); from = tmp; } std::vector value_map(std::numeric_limits::max()); unsigned int max_value = 0; - for (image::pixel_index<3>index(from.geometry());index < from.size();++index) + for (tipl::pixel_index<3>index(from.geometry());index < from.size();++index) { value_map[(unsigned short)from[index.index()]] = 1; max_value = std::max(from[index.index()],max_value); @@ -535,12 +535,12 @@ bool RegionTableWidget::load_multiple_roi_nii(QString file_name) std::map label_map; - std::map label_color; + std::map label_color; if(multiple_roi) get_roi_label(file_name,label_map,label_color); - image::matrix<4,4,float> convert; + tipl::matrix<4,4,float> convert; bool has_transform = false; // searching for T1/T2 mappings @@ -566,14 +566,14 @@ bool RegionTableWidget::load_multiple_roi_nii(QString file_name) if(cur_tracking_window.handle->is_qsdr && !has_transform)// use transformation information { // searching QSDR mappings - image::basic_image new_from; + tipl::image new_from; for(unsigned int index = 0;index < cur_tracking_window.handle->view_item.size();++index) if(cur_tracking_window.handle->view_item[index].native_geo == from.geometry()) { new_from.resize(cur_tracking_window.handle->dim); - for(image::pixel_index<3> pos(new_from.geometry());pos < new_from.size();++pos) + for(tipl::pixel_index<3> pos(new_from.geometry());pos < new_from.size();++pos) { - image::vector<3> new_pos(cur_tracking_window.handle->view_item[index].mx[pos.index()], + tipl::vector<3> new_pos(cur_tracking_window.handle->view_item[index].mx[pos.index()], cur_tracking_window.handle->view_item[index].my[pos.index()], cur_tracking_window.handle->view_item[index].mz[pos.index()]); new_pos.round(); @@ -636,7 +636,7 @@ bool RegionTableWidget::load_multiple_roi_nii(QString file_name) for(unsigned int value = 1;check_prog(value,value_map.size());++value) if(value_map[value]) { - image::basic_image mask(from.geometry()); + tipl::image mask(from.geometry()); for(unsigned int i = 0;i < mask.size();++i) if(from[i] == value) mask[i] = 1; @@ -836,16 +836,16 @@ void RegionTableWidget::save_all_regions(void) base_name = QFileInfo(base_name).completeBaseName(); QString label_file = QFileInfo(filename).absolutePath()+"/"+base_name+".txt"; std::ofstream out(label_file.toLocal8Bit().begin()); - image::geometry<3> geo = cur_tracking_window.handle->dim; - image::basic_image mask(geo); + tipl::geometry<3> geo = cur_tracking_window.handle->dim; + tipl::image mask(geo); for (unsigned int i = 0; i < regions.size(); ++i) if (item(i,0)->checkState() == Qt::Checked) { for (unsigned int j = 0; j < regions[i]->size(); ++j) { - image::vector<3,short> p = regions[i]->get_region_voxel(j); + tipl::vector<3,short> p = regions[i]->get_region_voxel(j); if (geo.is_valid(p)) - mask[image::pixel_index<3>(p[0],p[1],p[2], geo).index()] = i+1; + mask[tipl::pixel_index<3>(p[0],p[1],p[2], geo).index()] = i+1; } out << i+1 << " " << item(i,0)->text().toStdString() << std::endl; @@ -856,7 +856,7 @@ void RegionTableWidget::save_all_regions(void) header.set_LPS_transformation( cur_tracking_window.handle->trans_to_mni.begin(), mask.geometry()); - image::flip_xy(mask); + tipl::flip_xy(mask); header << mask; header.save_to_file(filename.toLocal8Bit().begin()); @@ -886,7 +886,7 @@ void RegionTableWidget::save_region_info(void) for(int index = 0;index < regions[currentRow()]->size();++index) { std::vector data; - image::vector<3,short> point = regions[currentRow()]->get_region_voxel(index); + tipl::vector<3,short> point = regions[currentRow()]->get_region_voxel(index); cur_tracking_window.handle->get_voxel_info2(point[0],point[1],point[2],data); cur_tracking_window.handle->get_voxel_information(point[0],point[1],point[2],data); std::copy(point.begin(),point.end(),std::ostream_iterator(out,"\t")); @@ -911,16 +911,16 @@ void RegionTableWidget::delete_all_region(void) emit need_update(); } -void RegionTableWidget::whole_brain_points(std::vector >& points) +void RegionTableWidget::whole_brain_points(std::vector >& points) { - image::geometry<3> geo = cur_tracking_window.handle->dim; + tipl::geometry<3> geo = cur_tracking_window.handle->dim; float threshold = cur_tracking_window["fa_threshold"].toFloat(); if(threshold == 0) threshold = cur_tracking_window["otsu_threshold"].toFloat() - *image::segmentation::otsu_threshold(image::make_image(cur_tracking_window.handle->dir.fa[0],cur_tracking_window.handle->dim)); - for (image::pixel_index<3>index(geo); index < geo.size();++index) + *tipl::segmentation::otsu_threshold(tipl::make_image(cur_tracking_window.handle->dir.fa[0],cur_tracking_window.handle->dim)); + for (tipl::pixel_index<3>index(geo); index < geo.size();++index) { - image::vector<3,short> pos(index); + tipl::vector<3,short> pos(index); if(cur_tracking_window.handle->dir.fa[0][index.index()] > threshold) points.push_back(pos); } @@ -928,7 +928,7 @@ void RegionTableWidget::whole_brain_points(std::vector >& void RegionTableWidget::whole_brain(void) { - std::vector > points; + std::vector > points; whole_brain_points(points); add_region("whole brain",seed_id); add_points(points,false,1.0); @@ -942,7 +942,7 @@ void get_regions_statistics(std::shared_ptr handle, { std::vector titles; std::vector > data(regions.size()); - image::par_for(regions.size(),[&](unsigned int index){ + tipl::par_for(regions.size(),[&](unsigned int index){ std::vector dummy; regions[index]->get_quantitative_data(handle,(index == 0) ? titles : dummy,data[index]); }); @@ -1005,7 +1005,7 @@ void RegionTableWidget::show_statistics(void) } extern std::vector mni_fa0_template_tran; -extern image::basic_image mni_fa0_template; +extern tipl::image mni_fa0_template; bool RegionTableWidget::has_seeding(void) { @@ -1018,9 +1018,9 @@ bool RegionTableWidget::has_seeding(void) } void RegionTableWidget::set_whole_brain(ThreadData* data) { - std::vector > points; + std::vector > points; whole_brain_points(points); - data->roi_mgr.setRegions(cur_tracking_window.handle->dim,points,1.0,seed_id,"whole brain",image::vector<3>()); + data->roi_mgr.setRegions(cur_tracking_window.handle->dim,points,1.0,seed_id,"whole brain",tipl::vector<3>()); } void RegionTableWidget::setROIs(ThreadData* data) @@ -1071,15 +1071,15 @@ void RegionTableWidget::do_action(QString action) cur_region.perform(action.toStdString()); if(action == "thresholding") { - image::basic_imagemask; - image::const_pointer_image I = cur_tracking_window.current_slice->get_source(); + tipl::imagemask; + tipl::const_pointer_image I = cur_tracking_window.current_slice->get_source(); if(I.empty()) return; mask.resize(I.geometry()); auto m = std::minmax_element(I.begin(),I.end()); bool ok; float threshold = QInputDialog::getDouble(this, - "DSI Studio","Threshold:", image::segmentation::otsu_threshold(I), + "DSI Studio","Threshold:", tipl::segmentation::otsu_threshold(I), *m.first, *m.second, 4, &ok); @@ -1092,12 +1092,12 @@ void RegionTableWidget::do_action(QString action) } if(action == "separate") { - image::basic_imagemask; + tipl::imagemask; cur_region.SaveToBuffer(mask, 1); QString name = item(currentRow(),0)->text(); - image::basic_image labels; + tipl::image labels; std::vector > r; - image::morphology::connected_component_labeling(mask,labels,r); + tipl::morphology::connected_component_labeling(mask,labels,r); for(unsigned int j = 0,total_count = 0;j < r.size() && total_count < 10;++j) if(!r[j].empty()) diff --git a/tracking/region/regiontablewidget.h b/tracking/region/regiontablewidget.h index cb73c847f..6fdd27e97 100644 --- a/tracking/region/regiontablewidget.h +++ b/tracking/region/regiontablewidget.h @@ -5,7 +5,7 @@ #include #include #include "Regions.h" -#include "image/image.hpp" +#include "tipl/tipl.hpp" struct ThreadData; class tracking_window; @@ -38,7 +38,7 @@ class RegionTableWidget : public QTableWidget private: tracking_window& cur_tracking_window; void do_action(QString action); - void whole_brain_points(std::vector >& points); + void whole_brain_points(std::vector >& points); bool load_multiple_roi_nii(QString file_name); signals: void need_update(void); @@ -57,7 +57,7 @@ class RegionTableWidget : public QTableWidget void setROIs(ThreadData* data); QString getROIname(void); template - void add_points(std::vector >& points,bool erase,float resolution = 1.0) + void add_points(std::vector >& points,bool erase,float resolution = 1.0) { if (currentRow() < 0 || currentRow() >= regions.size()) return; @@ -65,7 +65,7 @@ class RegionTableWidget : public QTableWidget } QString output_format(void); public slots: - void draw_region(image::color_image& I); + void draw_region(tipl::color_image& I); void draw_edge(QImage& image,QImage& scaledimage); void draw_mosaic_region(QImage& image,unsigned int mosaic_size,unsigned int skip); void updateRegions(QTableWidgetItem* item); diff --git a/tracking/slice_view_scene.cpp b/tracking/slice_view_scene.cpp index 22dcf0e3e..6427e2b5c 100644 --- a/tracking/slice_view_scene.cpp +++ b/tracking/slice_view_scene.cpp @@ -1,4 +1,4 @@ -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include "slice_view_scene.h" #include #include @@ -36,8 +36,8 @@ void slice_view_scene::show_ruler(QPainter& paint) float X = sel_point[index][0]; float Y = sel_point[index][1]; paint.drawLine(X, Y, tX, tY); - image::vector<2,float> from(X,Y); - image::vector<2,float> to(tX,tY); + tipl::vector<2,float> from(X,Y); + tipl::vector<2,float> to(tX,tY); from -= to; float pixel_length = from.length(); from /= cur_tracking_window.get_scene_zoom(); @@ -50,14 +50,14 @@ void slice_view_scene::show_ruler(QPainter& paint) if(tic_dis*pixel_length/length < 10) tic_dis *= 5.0; - image::vector<2,float> tic_dir(Y-tY,tX-X); + tipl::vector<2,float> tic_dir(Y-tY,tX-X); tic_dir.normalize(); tic_dir *= 5.0; for(double L = 0.0;1;L+=tic_dis) { if(L+tic_dis > length) L = length; - image::vector<2,float> npos(tX,tY); + tipl::vector<2,float> npos(tX,tY); npos[0] += ((float)X-npos[0])*L/length; npos[1] += ((float)Y-npos[1])*L/length; paint.drawLine(npos[0],npos[1],npos[0]+tic_dir[0],npos[1]+tic_dir[1]); @@ -113,7 +113,7 @@ void slice_view_scene::show_fiber(QPainter& painter) cur_tracking_window.current_slice->toDiffusionSpace(cur_tracking_window.cur_dim,x, y, X, Y, Z); if(!cur_tracking_window.handle->dim.is_valid(X,Y,Z)) continue; - image::pixel_index<3> pos(X,Y,Z,fib.dim); + tipl::pixel_index<3> pos(X,Y,Z,fib.dim); if (pos.index() >= fib.dim.size() || fib.dir.get_fa(pos.index(),0) == 0.0) continue; for (char fiber = max_fiber; fiber >= 0; --fiber) @@ -158,7 +158,7 @@ void slice_view_scene::get_view_image(QImage& new_view_image) cur_tracking_window.overlay_slice.get(),cur_tracking_window.overlay_v2c); // draw region colors on the image - image::color_image slice_image_with_region(slice_image); + tipl::color_image slice_image_with_region(slice_image); cur_tracking_window.regionWidget->draw_region(slice_image_with_region); QImage qimage((unsigned char*)&*slice_image_with_region.begin(),slice_image_with_region.width(),slice_image_with_region.height(),QImage::Format_RGB32); // make sure that qimage get a hard copy @@ -230,10 +230,10 @@ bool slice_view_scene::command(QString cmd,QString param,QString param2) if(param2 == "color") { - image::basic_image buf(cur_tracking_window.handle->dim); + tipl::image buf(cur_tracking_window.handle->dim); for(int z = 0;z < buf.depth();++z) { - image::color_image I; + tipl::color_image I; cur_tracking_window.handle->get_slice(index,2,z,I,cur_tracking_window.v2c); std::copy(I.begin(),I.end(),buf.begin()+z*buf.plane_size()); } @@ -241,7 +241,7 @@ bool slice_view_scene::command(QString cmd,QString param,QString param2) file.set_voxel_size(cur_tracking_window.current_slice->voxel_size.begin()); if(cur_tracking_window.handle->is_qsdr) //QSDR condition file.set_LPS_transformation(cur_tracking_window.handle->trans_to_mni.begin(),buf.geometry()); - image::flip_xy(buf); + tipl::flip_xy(buf); file << buf; file.save_to_file(param.toLocal8Bit().begin()); return true; @@ -249,19 +249,19 @@ bool slice_view_scene::command(QString cmd,QString param,QString param2) if(QFileInfo(param).completeSuffix().toLower() == "mat") { - image::io::mat_write file(param.toLocal8Bit().begin()); + tipl::io::mat_write file(param.toLocal8Bit().begin()); file << cur_tracking_window.handle->view_item[index].image_data; } else { - image::basic_image buf(cur_tracking_window.handle->view_item[index].image_data); + tipl::image buf(cur_tracking_window.handle->view_item[index].image_data); gz_nifti file; file.set_voxel_size(cur_tracking_window.current_slice->voxel_size.begin()); if(cur_tracking_window.handle->is_qsdr && cur_tracking_window.handle->view_item[index].image_data.geometry() == cur_tracking_window.handle->dim) //QSDR condition file.set_LPS_transformation(cur_tracking_window.handle->trans_to_mni.begin(),buf.geometry()); - image::flip_xy(buf); + tipl::flip_xy(buf); file << buf; file.save_to_file(param.toLocal8Bit().begin()); } @@ -270,9 +270,9 @@ bool slice_view_scene::command(QString cmd,QString param,QString param2) return false; } -bool slice_view_scene::to_3d_space_single_slice(float x,float y,image::vector<3,float>& pos) +bool slice_view_scene::to_3d_space_single_slice(float x,float y,tipl::vector<3,float>& pos) { - image::geometry<3> geo(cur_tracking_window.current_slice->geometry); + tipl::geometry<3> geo(cur_tracking_window.current_slice->geometry); if(cur_tracking_window["orientation_convention"].toInt()) x = (cur_tracking_window.cur_dim ? geo[0]:geo[1])-x; if(cur_tracking_window.cur_dim != 2) @@ -280,9 +280,9 @@ bool slice_view_scene::to_3d_space_single_slice(float x,float y,image::vector<3, return cur_tracking_window.current_slice->to3DSpace(cur_tracking_window.cur_dim,x - 0.5f,y - 0.5f,pos[0], pos[1], pos[2]); } -bool slice_view_scene::to_3d_space(float x,float y,image::vector<3,float>& pos) +bool slice_view_scene::to_3d_space(float x,float y,tipl::vector<3,float>& pos) { - image::geometry<3> geo(cur_tracking_window.current_slice->geometry); + tipl::geometry<3> geo(cur_tracking_window.current_slice->geometry); float display_ratio = cur_tracking_window.get_scene_zoom(); x /= display_ratio; y /= display_ratio; @@ -491,7 +491,7 @@ void slice_view_scene::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * mouseE return; float Y = mouseEvent->scenePos().y(); float X = mouseEvent->scenePos().x(); - image::vector<3,float> pos; + tipl::vector<3,float> pos; if(!to_3d_space(X,Y,pos)) return; pos.round(); @@ -503,7 +503,7 @@ void slice_view_scene::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * mouseE void slice_view_scene::adjust_xy_to_layout(float& X,float& Y) { - image::geometry<3> geo(cur_tracking_window.current_slice->geometry); + tipl::geometry<3> geo(cur_tracking_window.current_slice->geometry); float display_ratio = cur_tracking_window.get_scene_zoom(); if(cur_tracking_window["roi_layout"].toInt() == 1) { @@ -545,7 +545,7 @@ void slice_view_scene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ) sel_coord.clear(); } - image::vector<3,float> pos; + tipl::vector<3,float> pos; float Y = mouseEvent->scenePos().y(); float X = mouseEvent->scenePos().x(); if(!to_3d_space(X,Y,pos)) @@ -554,7 +554,7 @@ void slice_view_scene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ) if(sel_mode == 5)// move object { bool find_region = false; - image::vector<3,float> p(pos); + tipl::vector<3,float> p(pos); if(!cur_tracking_window.current_slice->is_diffusion_space) p.to(cur_tracking_window.current_slice->T); for(unsigned int index = 0;index < @@ -564,7 +564,7 @@ void slice_view_scene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ) { find_region = true; cur_tracking_window.regionWidget->selectRow(index); - std::vector > dummy; + std::vector > dummy; cur_tracking_window.regionWidget->add_points(dummy,true); // create a undo point break; } @@ -579,7 +579,7 @@ void slice_view_scene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ) sel_point.clear(); sel_coord.clear(); } - sel_point.push_back(image::vector<2,short>(X, Y)); + sel_point.push_back(tipl::vector<2,short>(X, Y)); sel_coord.push_back(pos); } @@ -591,7 +591,7 @@ void slice_view_scene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ) case 4: case 6: sel_coord.push_back(pos); - sel_point.push_back(image::vector<2,short>(X, Y)); + sel_point.push_back(tipl::vector<2,short>(X, Y)); break; default: break; @@ -600,7 +600,7 @@ void slice_view_scene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ) } void slice_view_scene::new_annotated_image(void) { - image::geometry<3> geo(cur_tracking_window.current_slice->geometry); + tipl::geometry<3> geo(cur_tracking_window.current_slice->geometry); float display_ratio = cur_tracking_window.get_scene_zoom(); if(cur_tracking_window["roi_layout"].toInt() == 0) annotated_image = view_image; @@ -627,7 +627,7 @@ void slice_view_scene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent ) { return; } - image::geometry<3> geo(cur_tracking_window.current_slice->geometry); + tipl::geometry<3> geo(cur_tracking_window.current_slice->geometry); float Y = mouseEvent->scenePos().y(); float X = mouseEvent->scenePos().x(); float display_ratio = cur_tracking_window.get_scene_zoom(); @@ -635,7 +635,7 @@ void slice_view_scene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent ) cX = X; cY = Y; - image::vector<3,float> pos; + tipl::vector<3,float> pos; if (!mouse_down || sel_mode == 4) return; to_3d_space(cX,cY,pos); @@ -645,7 +645,7 @@ void slice_view_scene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent ) { if(!sel_coord.empty() && pos != sel_coord.back()) { - image::vector<3,float> p1(pos),p2(sel_coord.back()); + tipl::vector<3,float> p1(pos),p2(sel_coord.back()); if(!cur_tracking_window.current_slice->is_diffusion_space) { p1.to(cur_tracking_window.current_slice->T); @@ -657,7 +657,7 @@ void slice_view_scene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent ) { cur_tracking_window.regionWidget->regions[cur_tracking_window.regionWidget->currentRow()]->shift(p1); p1.to(cur_tracking_window.current_slice->invT); - image::vector<3> zero; + tipl::vector<3> zero; zero.to(cur_tracking_window.current_slice->invT); sel_coord.back() += p1-zero; emit need_update(); @@ -673,7 +673,7 @@ void slice_view_scene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent ) if(sel_mode == 6) // ruler { sel_coord.back() = pos; - sel_point.back() = image::vector<2,short>(X, Y); + sel_point.back() = tipl::vector<2,short>(X, Y); QPainter paint(&annotated_image); show_ruler(paint); } @@ -688,11 +688,11 @@ void slice_view_scene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent ) case 0: // draw rectangle paint.drawRect(X, Y, sel_point.front()[0]-X,sel_point.front()[1]-Y); sel_coord.back() = pos; - sel_point.back() = image::vector<2,short>(X, Y); + sel_point.back() = tipl::vector<2,short>(X, Y); break; case 1: //free hand sel_coord.push_back(pos); - sel_point.push_back(image::vector<2,short>(X, Y)); + sel_point.push_back(tipl::vector<2,short>(X, Y)); for (unsigned int index = 1; index < sel_point.size(); ++index) paint.drawLine(sel_point[index-1][0], sel_point[index-1][1],sel_point[index][0], sel_point[index][1]); @@ -704,7 +704,7 @@ void slice_view_scene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent ) int dis = std::sqrt((double)(dx * dx + dy * dy)); paint.drawEllipse(QPoint(sel_point.front()[0],sel_point.front()[1]),dis,dis); sel_coord.back() = pos; - sel_point.back() = image::vector<2,short>(X, Y); + sel_point.back() = tipl::vector<2,short>(X, Y); } break; case 3: @@ -715,7 +715,7 @@ void slice_view_scene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent ) paint.drawRect(sel_point.front()[0] - dis, sel_point.front()[1] - dis, dis*2, dis*2); sel_coord.back() = pos; - sel_point.back() = image::vector<2,short>(X, Y); + sel_point.back() = tipl::vector<2,short>(X, Y); } break; default: @@ -754,18 +754,18 @@ void slice_view_scene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * mouseEvent return; } - image::geometry<3> geo(cur_tracking_window.current_slice->geometry); + tipl::geometry<3> geo(cur_tracking_window.current_slice->geometry); float display_ratio = cur_tracking_window.get_scene_zoom(); - std::vector >points; + std::vector >points; switch (sel_mode) { case 0: // rectangle { if (sel_coord.size() < 2) return; - image::vector<3,float> min_cood, max_cood; + tipl::vector<3,float> min_cood, max_cood; for (unsigned int i = 0; i < 3; ++i) if (sel_coord[0][i] > sel_coord[1][i]) { @@ -782,7 +782,7 @@ void slice_view_scene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * mouseEvent for (float y = min_cood[1]; y <= max_cood[1]; y += dis) for (float x = min_cood[0]; x <= max_cood[0]; x += dis) if (cur_tracking_window.current_slice->geometry.is_valid(x, y, z)) - points.push_back(image::vector<3,float>(x, y, z)); + points.push_back(tipl::vector<3,float>(x, y, z)); } break; case 1: //free hand @@ -802,10 +802,10 @@ void slice_view_scene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * mouseEvent for(unsigned int index = 0;index < sel_point.size();++index) qpoints[index] = QPoint(sel_point[index][0],sel_point[index][1]); paint.drawPolygon(&*qpoints.begin(),qpoints.size() - 1); - image::geometry<2> geo2(bitmap.width(),bitmap.height()); - for (image::pixel_index<2>index(geo2); index < geo2.size();++index) + tipl::geometry<2> geo2(bitmap.width(),bitmap.height()); + for (tipl::pixel_index<2>index(geo2); index < geo2.size();++index) { - image::vector<3,float> pos; + tipl::vector<3,float> pos; if (QColor(bitmap.pixel(index.x(),index.y())).red() < 64 || !to_3d_space_single_slice((float)index.x()/display_ratio,(float)index.y()/display_ratio,pos)) continue; @@ -832,7 +832,7 @@ void slice_view_scene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * mouseEvent if (cur_tracking_window.current_slice->geometry.is_valid(sel_coord[0][0] + x, sel_coord[0][1] + y, sel_coord[0][2] + z) && x*x + y*y + z*z <= distance2) - points.push_back(image::vector<3,float>(sel_coord[0][0] + x, + points.push_back(tipl::vector<3,float>(sel_coord[0][0] + x, sel_coord[0][1] + y, sel_coord[0][2] + z)); } break; @@ -849,7 +849,7 @@ void slice_view_scene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * mouseEvent for (float z = -dis; z <= dis; z += interval) for (float y = -dis; y <= dis; y += interval) for (float x = -dis; x <= dis; x += interval) - points.push_back(image::vector<3,float>(sel_coord[0][0] + x, + points.push_back(tipl::vector<3,float>(sel_coord[0][0] + x, sel_coord[0][1] + y, sel_coord[0][2] + z)); } @@ -895,7 +895,7 @@ void slice_view_scene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * mouseEvent { // resolution difference between DWI and current slices; resolution = std::min(16.0f,display_ratio*std::floor(cur_tracking_window.handle->vs[0]/cur_tracking_window.current_slice->voxel_size[0])); - image::par_for(points.size(),[&](int index) + tipl::par_for(points.size(),[&](int index) { points[index].to(cur_tracking_window.current_slice->T); points[index] *= resolution; @@ -903,7 +903,7 @@ void slice_view_scene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * mouseEvent } else { - image::par_for(points.size(),[&](int index) + tipl::par_for(points.size(),[&](int index) { points[index] *= resolution; }); diff --git a/tracking/slice_view_scene.h b/tracking/slice_view_scene.h index 0e3f7058d..46eb91803 100644 --- a/tracking/slice_view_scene.h +++ b/tracking/slice_view_scene.h @@ -2,7 +2,7 @@ #define SLICE_VIEW_SCENE_H #include #include -#include "image/image.hpp" +#include "tipl/tipl.hpp" #include class fib_data; class tracking_window; @@ -24,15 +24,15 @@ class slice_view_scene : public QGraphicsScene QStatusBar* statusbar; private: tracking_window& cur_tracking_window; - image::color_image slice_image,mosaic_image; + tipl::color_image slice_image,mosaic_image; public: unsigned int mosaic_size; void adjust_xy_to_layout(float& X,float& Y); - bool to_3d_space_single_slice(float x,float y,image::vector<3,float>& pos); - bool to_3d_space(float x,float y,image::vector<3,float>& pos); + bool to_3d_space_single_slice(float x,float y,tipl::vector<3,float>& pos); + bool to_3d_space(float x,float y,tipl::vector<3,float>& pos); public: // record the mouse press points - std::vector >sel_coord; - std::vector >sel_point; + std::vector >sel_coord; + std::vector >sel_point; int cur_region; bool mouse_down; bool mid_down; diff --git a/tracking/tracking_window.cpp b/tracking/tracking_window.cpp index e29633a2b..748a2bb17 100644 --- a/tracking/tracking_window.cpp +++ b/tracking/tracking_window.cpp @@ -487,7 +487,7 @@ void tracking_window::initialize_tracking_index(int p) bool tracking_window::eventFilter(QObject *obj, QEvent *event) { bool has_info = false; - image::vector<3,float> pos; + tipl::vector<3,float> pos; if (event->type() == QEvent::MouseMove) { if (obj == glWidget) @@ -512,7 +512,7 @@ bool tracking_window::eventFilter(QObject *obj, QEvent *event) if(!current_slice->is_diffusion_space) { - image::vector<3,float> pos_dwi(pos); + tipl::vector<3,float> pos_dwi(pos); pos_dwi.to(current_slice->T); status = QString("(%1,%2,%3) %4(%5,%6,%7)").arg(std::round(pos_dwi[0]*10.0)/10.0) .arg(std::round(pos_dwi[1]*10.0)/10.0) @@ -532,7 +532,7 @@ bool tracking_window::eventFilter(QObject *obj, QEvent *event) if(handle->is_qsdr || handle->has_reg()) { - image::vector<3,float> mni(pos); + tipl::vector<3,float> mni(pos); if(handle->has_reg()) handle->subject2mni(mni); else @@ -721,7 +721,7 @@ void tracking_window::on_SliceModality_currentIndexChanged(int index) if(index == -1 || !current_slice.get()) return; no_update = true; - image::vector<3,float> slice_position(current_slice->slice_pos); + tipl::vector<3,float> slice_position(current_slice->slice_pos); if(!current_slice->is_diffusion_space) slice_position.to(current_slice->T); @@ -798,7 +798,7 @@ void tracking_window::change_contrast() void tracking_window::on_actionEndpoints_to_seeding_triggered() { - std::vector >points; + std::vector >points; if(tractWidget->tract_models.empty()) return; @@ -813,7 +813,7 @@ void tracking_window::on_actionEndpoints_to_seeding_triggered() void tracking_window::on_actionTracts_to_seeds_triggered() { - std::vector >points; + std::vector >points; if(tractWidget->tract_models.empty()) return; tractWidget->tract_models[tractWidget->currentRow()]->get_tract_points(points); @@ -846,7 +846,7 @@ bool ask_TDI_options(int& rec,int& rec2) } void tracking_window::on_actionTDI_Diffusion_Space_triggered() { - image::matrix<4,4,float> tr; + tipl::matrix<4,4,float> tr; tr.identity(); int rec,rec2; if(!ask_TDI_options(rec,rec2)) @@ -866,20 +866,20 @@ void tracking_window::on_actionTDI_Subvoxel_Diffusion_Space_triggered() "Input super-resolution ratio (e.g. 2, 3, or 4):",2,2,8,1,&ok); if(!ok) return; - image::matrix<4,4,float> tr; + tipl::matrix<4,4,float> tr; tr.identity(); tr[0] = tr[5] = tr[10] = ratio; - image::geometry<3> new_geo(handle->dim[0]*ratio,handle->dim[1]*ratio,handle->dim[2]*ratio); - image::vector<3,float> new_vs(handle->vs); + tipl::geometry<3> new_geo(handle->dim[0]*ratio,handle->dim[1]*ratio,handle->dim[2]*ratio); + tipl::vector<3,float> new_vs(handle->vs); new_vs /= (float)ratio; tractWidget->export_tract_density(new_geo,new_vs,tr,rec == QMessageBox::Yes,rec2 != QMessageBox::Yes); } void tracking_window::on_actionTDI_Import_Slice_Space_triggered() { - image::matrix<4,4,float> tr = current_slice->invT; - image::geometry<3> geo = current_slice->geometry; - image::vector<3,float> vs = current_slice->voxel_size; + tipl::matrix<4,4,float> tr = current_slice->invT; + tipl::geometry<3> geo = current_slice->geometry; + tipl::vector<3,float> vs = current_slice->voxel_size; int rec,rec2; if(!ask_TDI_options(rec,rec2)) return; @@ -933,7 +933,7 @@ void tracking_window::on_tracking_index_currentIndexChanged(int index) if(renderWidget->getData("fa_threshold").toFloat() != 0.0) set_data("fa_threshold", renderWidget->getData("otsu_threshold").toFloat()* - image::segmentation::otsu_threshold(image::make_image(handle->dir.fa[0],handle->dim))); + tipl::segmentation::otsu_threshold(tipl::make_image(handle->dir.fa[0],handle->dim))); scene.show_slice(); } @@ -1071,14 +1071,14 @@ void tracking_window::keyPressEvent ( QKeyEvent * event ) void tracking_window::on_actionManual_Registration_triggered() { - image::basic_image from = current_slice->get_source(); - image::filter::gaussian(from); - from -= image::segmentation::otsu_threshold(from); - image::lower_threshold(from,0.0); + tipl::image from = current_slice->get_source(); + tipl::filter::gaussian(from); + from -= tipl::segmentation::otsu_threshold(from); + tipl::lower_threshold(from,0.0); std::shared_ptr manual(new manual_alignment(this, from,handle->vs, fa_template_imp.I,fa_template_imp.vs, - image::reg::affine,image::reg::cost_type::corr)); + tipl::reg::affine,tipl::reg::cost_type::corr)); manual->on_rerun_clicked(); if(manual->exec() != QDialog::Accepted) @@ -1290,7 +1290,7 @@ void tracking_window::on_zoom_out_clicked() } std::pair evaluate_fib( - const image::geometry<3>& dim, + const tipl::geometry<3>& dim, const std::vector >& fib_fa, const std::vector >& fib_dir); void tracking_window::on_actionQuality_Assessment_triggered() @@ -1324,7 +1324,7 @@ void tracking_window::on_actionImprove_Quality_triggered() tracking_data fib; fib.read(*handle); float threshold = renderWidget->getData("otsu_threshold").toFloat()* - image::segmentation::otsu_threshold(image::make_image(handle->dir.fa[0],handle->dim)); + tipl::segmentation::otsu_threshold(tipl::make_image(handle->dir.fa[0],handle->dim)); if(!fib.dir.empty()) return; for(float cos_angle = 0.99f;check_prog(1000-cos_angle*1000,1000-866);cos_angle -= 0.005f) @@ -1340,22 +1340,22 @@ void tracking_window::on_actionImprove_Quality_triggered() std::copy(handle->dir.findex[i],handle->dir.findex[i]+size,new_index[i].begin()); } - for(image::pixel_index<3> index(handle->dim);index < handle->dim.size();++index) + for(tipl::pixel_index<3> index(handle->dim);index < handle->dim.size();++index) { if(handle->dir.fa[0][index.index()] < threshold) continue; - std::vector > neighbors; - image::get_neighbors(index,handle->dim,neighbors); + std::vector > neighbors; + tipl::get_neighbors(index,handle->dim,neighbors); - std::vector > dis(neighbors.size()); - std::vector > fib_dir(neighbors.size()); + std::vector > dis(neighbors.size()); + std::vector > fib_dir(neighbors.size()); std::vector fib_fa(neighbors.size()); for(unsigned char i = 0;i < neighbors.size();++i) { dis[i] = neighbors[i]; - dis[i] -= image::vector<3>(index); + dis[i] -= tipl::vector<3>(index); dis[i].normalize(); unsigned char fib_order,reverse; if(fib.get_nearest_dir_fib(neighbors[i].index(),dis[i],fib_order,reverse,threshold,cos_angle)) @@ -1377,7 +1377,7 @@ void tracking_window::on_actionImprove_Quality_triggered() float angle = fib_dir[i]*fib_dir[j]; if(angle > -cos_angle) // select opposite side continue; - image::vector<3> predict_dir(fib_dir[i]); + tipl::vector<3> predict_dir(fib_dir[i]); if(angle > 0) predict_dir += fib_dir[j]; else @@ -1388,9 +1388,9 @@ void tracking_window::on_actionImprove_Quality_triggered() if(fib.get_nearest_dir_fib(index.index(),predict_dir,fib_order,reverse,threshold,cos_angle)) { if(reverse) - predict_dir -= image::vector<3>(handle->dir.get_dir(index.index(),fib_order)); + predict_dir -= tipl::vector<3>(handle->dir.get_dir(index.index(),fib_order)); else - predict_dir += image::vector<3>(handle->dir.get_dir(index.index(),fib_order)); + predict_dir += tipl::vector<3>(handle->dir.get_dir(index.index(),fib_order)); predict_dir.normalize(); has_match = true; } @@ -1600,7 +1600,7 @@ void tracking_window::on_actionAdjust_Mapping_triggered() std::shared_ptr manual(new manual_alignment(this, slices[0]->get_source(),slices[0]->voxel_size, reg_slice->get_source(),reg_slice->voxel_size, - image::reg::rigid_body,image::reg::cost_type::mutual_info)); + tipl::reg::rigid_body,tipl::reg::cost_type::mutual_info)); manual->on_rerun_clicked(); if(manual->exec() != QDialog::Accepted) return; @@ -1672,18 +1672,18 @@ void tracking_window::on_actionInsert_MNI_images_triggered() QMessageBox::information(this,"Error","Cannot open the nifti file",0); return; } - const image::basic_image,3 >& mapping = handle->get_mni_mapping(); - image::basic_image I,J(mapping.geometry()); - image::matrix<4,4,float> T; + const tipl::image,3 >& mapping = handle->get_mni_mapping(); + tipl::image I,J(mapping.geometry()); + tipl::matrix<4,4,float> T; reader.toLPS(I); reader.get_image_transformation(T.begin()); T[15] = 1.0; T.inv(); - J.for_each_mt([&](float& v,const image::pixel_index<3>& pos) + J.for_each_mt([&](float& v,const tipl::pixel_index<3>& pos) { - image::vector<3> mni(mapping[pos.index()]); + tipl::vector<3> mni(mapping[pos.index()]); mni.to(T); - image::estimate(I,mni,v); + tipl::estimate(I,mni,v); }); QString name = QFileInfo(filename).baseName(); std::shared_ptr new_slice(new CustomSliceModel(handle)); @@ -1757,7 +1757,7 @@ void tracking_window::on_actionLoad_Color_Map_triggered() "Text files (*.txt);;All files|(*)"); if(filename.isEmpty()) return; - image::color_map_rgb new_color_map; + tipl::color_map_rgb new_color_map; if(!new_color_map.load_from_file(filename.toStdString().c_str())) { QMessageBox::information(this,"Error","Invalid color map format"); diff --git a/tracking/tracking_window.h b/tracking/tracking_window.h index f7df82a72..f2bbb3f24 100644 --- a/tracking/tracking_window.h +++ b/tracking/tracking_window.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include "SliceModel.h" #include "slice_view_scene.h" @@ -60,10 +60,10 @@ class tracking_window : public QMainWindow float get_scene_zoom(void); public: unsigned char cur_dim; - image::value_to_color v2c; + tipl::value_to_color v2c; public: std::shared_ptr overlay_slice; - image::value_to_color overlay_v2c; + tipl::value_to_color overlay_v2c; public: connectometry_result cnt_result; public: diff --git a/tracking/tract/tracttablewidget.cpp b/tracking/tract/tracttablewidget.cpp index d4289fa63..820e5a124 100644 --- a/tracking/tract/tracttablewidget.cpp +++ b/tracking/tract/tracttablewidget.cpp @@ -89,7 +89,7 @@ void TractTableWidget::addConnectometryResults(std::vector((index+1)*50,255); addNewTracts(QString("Lesser_") + QString::number((index+1)*10),false); - tract_models.back()->add_tracts(lesser[index],image::rgb_color(255,255-color,255-color)); + tract_models.back()->add_tracts(lesser[index],tipl::rgb(255,255-color,255-color)); item(tract_models.size()-1,1)->setText(QString::number(tract_models.back()->get_visible_track_count())); } for(unsigned int index = 0;index < greater.size();++index) @@ -98,7 +98,7 @@ void TractTableWidget::addConnectometryResults(std::vector((index+1)*50,255); addNewTracts(QString("Greater_") + QString::number((index+1)*10),false); - tract_models.back()->add_tracts(greater[index],image::rgb_color(255-color,255-color,255)); + tract_models.back()->add_tracts(greater[index],tipl::rgb(255-color,255-color,255)); item(tract_models.size()-1,1)->setText(QString::number(tract_models.back()->get_visible_track_count())); } cur_tracking_window.set_data("tract_color_style",1);//manual assigned @@ -201,7 +201,7 @@ void TractTableWidget::load_tracts(QStringList filenames) if(tract_models.back()->get_cluster_info().empty()) // not multiple cluster file { item(tract_models.size()-1,1)->setText(QString::number(tract_models.back()->get_visible_track_count())); - image::rgb_color c; + tipl::rgb c; c.from_hsl(((color_gen++)*1.1-std::floor((color_gen++)*1.1/6)*6)*3.14159265358979323846/3.0,0.85,0.7); tract_models.back()->set_color(c.color); } @@ -315,7 +315,7 @@ void TractTableWidget::assign_colors(void) { for(unsigned int index = 0;index < tract_models.size();++index) { - image::rgb_color c; + tipl::rgb c; c.from_hsl(((color_gen++)*1.1-std::floor((color_gen++)*1.1/6)*6)*3.14159265358979323846/3.0,0.85,0.7); tract_models[index]->set_color(c.color); } @@ -519,7 +519,7 @@ void TractTableWidget::save_end_point_in_mni(void) "Tract files (*.txt);;MAT files (*.mat);;All files (*)"); if(filename.isEmpty()) return; - std::vector > points; + std::vector > points; std::vector buffer; tract_models[currentRow()]->get_end_points(points); for(unsigned int index = 0;index < points.size();++index) @@ -539,7 +539,7 @@ void TractTableWidget::save_end_point_in_mni(void) } if (QFileInfo(filename).suffix().toLower() == "mat") { - image::io::mat_write out(filename.toLocal8Bit().begin()); + tipl::io::mat_write out(filename.toLocal8Bit().begin()); if(!out) return; out.write("end_points",(const float*)&*buffer.begin(),3,buffer.size()/3); @@ -611,15 +611,15 @@ void TractTableWidget::deep_learning_train(void) filename = QFileInfo(filename).absolutePath() + "/network_data.bin.gz"; - cnn.cnn_data.input = image::geometry<3>(60,75,3); - cnn.cnn_data.output = image::geometry<3>(1,1,rowCount()); + cnn.cnn_data.input = tipl::geometry<3>(60,75,3); + cnn.cnn_data.output = tipl::geometry<3>(1,1,rowCount()); cnn.cnn_data.save_to_file(filename.toStdString().c_str()); // save atlas as a nifti file if(cur_tracking_window.handle->is_qsdr) //QSDR condition { - image::basic_image atlas(image::geometry<4>( + tipl::image atlas(tipl::geometry<4>( cur_tracking_window.handle->dim[0], cur_tracking_window.handle->dim[1], cur_tracking_window.handle->dim[2], @@ -627,20 +627,20 @@ void TractTableWidget::deep_learning_train(void) for(unsigned int index = 0;check_prog(index,rowCount());++index) { - image::basic_image track_map(cur_tracking_window.handle->dim); + tipl::image track_map(cur_tracking_window.handle->dim); for(unsigned int i = 0;i < tract_models[index]->get_tracts().size();++i) { const std::vector& tracks = tract_models[index]->get_tracts()[i]; for(int j = 0;j < tracks.size();j += 3) { - image::pixel_index<3> p(std::round(tracks[j]),std::round(tracks[j+1]),std::round(tracks[j+2]),track_map.geometry()); + tipl::pixel_index<3> p(std::round(tracks[j]),std::round(tracks[j+1]),std::round(tracks[j+2]),track_map.geometry()); if(track_map.geometry().is_valid(p)) track_map[p.index()] = 1; if(j) { for(float r = 0.2f;r < 1.0f;r += 0.2f) { - image::pixel_index<3> p2(std::round(tracks[j]*r+tracks[j-3]*(1-r)), + tipl::pixel_index<3> p2(std::round(tracks[j]*r+tracks[j-3]*(1-r)), std::round(tracks[j+1]*r+tracks[j-2]*(1-r)), std::round(tracks[j+2]*r+tracks[j-1]*(1-r)),track_map.geometry()); if(track_map.geometry().is_valid(p2)) @@ -649,10 +649,10 @@ void TractTableWidget::deep_learning_train(void) } } } - while(image::morphology::smoothing_fill(track_map)) - image::morphology::defragment(track_map); - image::morphology::smoothing(track_map); - image::morphology::defragment(track_map); + while(tipl::morphology::smoothing_fill(track_map)) + tipl::morphology::defragment(track_map); + tipl::morphology::smoothing(track_map); + tipl::morphology::defragment(track_map); QString track_file_name = QFileInfo(filename).absolutePath() + "/" + item(index,0)->text() + ".nii.gz"; @@ -725,7 +725,7 @@ void TractTableWidget::saveTransformedTracts(const float* transform) { for(unsigned int j = 0;j < tract_data[i].size();j += 3) { - image::vector<3> v(&(tract_data[i][j])); + tipl::vector<3> v(&(tract_data[i][j])); cur_tracking_window.handle->subject2mni(v); tract_data[i][j] = v[0]; tract_data[i][j+1] = v[1]; @@ -836,7 +836,7 @@ void get_track_statistics(const std::vector& tract_models, std::string& result) { std::vector > track_results(tract_models.size()); - image::par_for(tract_models.size(),[&](unsigned int index) + tipl::par_for(tract_models.size(),[&](unsigned int index) { std::string tmp,line; tract_models[index]->get_quantitative_info(tmp); @@ -1237,9 +1237,9 @@ void TractTableWidget::trim_tracts(void) emit need_update(); } -void TractTableWidget::export_tract_density(image::geometry<3>& dim, - image::vector<3,float> vs, - image::matrix<4,4,float>& transformation,bool color,bool end_point) +void TractTableWidget::export_tract_density(tipl::geometry<3>& dim, + tipl::vector<3,float> vs, + tipl::matrix<4,4,float>& transformation,bool color,bool end_point) { if(color) { @@ -1249,25 +1249,25 @@ void TractTableWidget::export_tract_density(image::geometry<3>& dim, if(filename.isEmpty()) return; - image::basic_image tdi(dim); + tipl::image tdi(dim); for(unsigned int index = 0;index < tract_models.size();++index) { if(item(index,0)->checkState() != Qt::Checked) continue; tract_models[index]->get_density_map(tdi,transformation,end_point); } - image::basic_image mosaic; + tipl::image mosaic; if(QFileInfo(filename).completeSuffix().contains("nii")) { gz_nifti nii; - image::flip_xy(tdi); + tipl::flip_xy(tdi); nii << tdi; nii.set_voxel_size(vs); nii.save_to_file(filename.toStdString().c_str()); } else { - image::mosaic(tdi,mosaic,std::sqrt(tdi.depth())); + tipl::mosaic(tdi,mosaic,std::sqrt(tdi.depth())); QImage qimage((unsigned char*)&*mosaic.begin(), mosaic.width(),mosaic.height(),QImage::Format_RGB32); qimage.save(filename); @@ -1283,7 +1283,7 @@ void TractTableWidget::export_tract_density(image::geometry<3>& dim, if(QFileInfo(filename.toLower()).completeSuffix() != "mat") filename = QFileInfo(filename).absolutePath() + "/" + QFileInfo(filename).baseName() + ".nii.gz"; - image::basic_image tdi(dim); + tipl::image tdi(dim); for(unsigned int index = 0;index < tract_models.size();++index) { if(item(index,0)->checkState() != Qt::Checked) @@ -1292,7 +1292,7 @@ void TractTableWidget::export_tract_density(image::geometry<3>& dim, } if(QFileInfo(filename).completeSuffix().toLower() == "mat") { - image::io::mat_write mat_header(filename.toLocal8Bit().begin()); + tipl::io::mat_write mat_header(filename.toLocal8Bit().begin()); mat_header << tdi; } else @@ -1301,12 +1301,12 @@ void TractTableWidget::export_tract_density(image::geometry<3>& dim, nii_header.set_voxel_size(vs.begin()); if(cur_tracking_window.handle->is_qsdr) { - image::matrix<4,4,float> new_trans(transformation),trans(cur_tracking_window.handle->trans_to_mni.begin()); + tipl::matrix<4,4,float> new_trans(transformation),trans(cur_tracking_window.handle->trans_to_mni.begin()); new_trans.inv(); trans *= new_trans; nii_header.set_LPS_transformation(trans.begin(),tdi.geometry()); } - image::flip_xy(tdi); + tipl::flip_xy(tdi); nii_header << tdi; nii_header.save_to_file(filename.toLocal8Bit().begin()); } diff --git a/tracking/tract/tracttablewidget.h b/tracking/tract/tracttablewidget.h index 419661256..954443477 100644 --- a/tracking/tract/tracttablewidget.h +++ b/tracking/tract/tracttablewidget.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include "fib_data.hpp" class tracking_window; class TractModel; @@ -34,9 +34,9 @@ class TractTableWidget : public QTableWidget void addNewTracts(QString tract_name,bool checked = true); void addConnectometryResults(std::vector > >& greater, std::vector > >& lesser); - void export_tract_density(image::geometry<3>& dim, - image::vector<3,float> vs, - image::matrix<4,4,float>& transformation,bool color,bool endpoint); + void export_tract_density(tipl::geometry<3>& dim, + tipl::vector<3,float> vs, + tipl::matrix<4,4,float>& transformation,bool color,bool endpoint); void saveTransformedTracts(const float* transform); void saveTransformedEndpoints(const float* transform); diff --git a/tracking/tract_report.cpp b/tracking/tract_report.cpp index ef86a8cc0..1ef87dfc2 100644 --- a/tracking/tract_report.cpp +++ b/tracking/tract_report.cpp @@ -93,7 +93,7 @@ void tract_report::on_refresh_report_clicked() ui->report_widget->addGraph(); QPen pen; - image::rgb_color color = cur_tracking_window->tractWidget->tract_models[index]->get_tract_color(0); + tipl::rgb color = cur_tracking_window->tractWidget->tract_models[index]->get_tract_color(0); pen.setColor(QColor(color.r,color.g,color.b,200)); pen.setWidth(ui->linewidth->value()); ui->report_widget->graph()->setLineStyle(QCPGraph::lsLine); diff --git a/view_image.cpp b/view_image.cpp index 547f4a4cf..8837634ba 100644 --- a/view_image.cpp +++ b/view_image.cpp @@ -7,7 +7,7 @@ #include void show_view(QGraphicsScene& scene,QImage I); -bool load_image_from_files(QStringList filenames,image::basic_image& ref,image::vector<3>& vs) +bool load_image_from_files(QStringList filenames,tipl::image& ref,tipl::vector<3>& vs) { if(filenames.size() == 1 && filenames[0].toLower().contains("nii")) { @@ -23,7 +23,7 @@ bool load_image_from_files(QStringList filenames,image::basic_image& re else if(filenames.size() == 1 && filenames[0].contains("2dseq")) { - image::io::bruker_2dseq seq; + tipl::io::bruker_2dseq seq; if(!seq.load_from_file(filenames[0].toLocal8Bit().begin())) { QMessageBox::information(0,"Error","Not a valid 2dseq file",0); @@ -35,7 +35,7 @@ bool load_image_from_files(QStringList filenames,image::basic_image& re } else { - image::io::volume v; + tipl::io::volume v; std::vector file_list; for(int i = 0;i < filenames.size();++i) file_list.push_back(filenames[i].toStdString()); @@ -76,7 +76,7 @@ bool view_image::eventFilter(QObject *obj, QEvent *event) return false; QMouseEvent *mouseEvent = static_cast(event); QPointF point = ui->view->mapToScene(mouseEvent->pos().x(),mouseEvent->pos().y()); - image::vector<3,float> pos; + tipl::vector<3,float> pos; pos[0] = ((float)point.x()) / source_ratio - 0.5; pos[1] = ((float)point.y()) / source_ratio - 0.5; pos[2] = ui->slice_pos->value(); @@ -89,8 +89,8 @@ bool view_image::eventFilter(QObject *obj, QEvent *event) bool view_image::open(QStringList file_names) { gz_nifti nifti; - image::io::dicom dicom; - image::io::bruker_2dseq seq; + tipl::io::dicom dicom; + tipl::io::bruker_2dseq seq; gz_mat_read mat; data.clear(); float vs[3] = {1.0,1.0,1.0}; @@ -103,13 +103,13 @@ bool view_image::open(QStringList file_names) { for(unsigned int i = 0;check_prog(i,file_names.size());++i) { - image::color_image I; - image::io::bitmap bmp; + tipl::color_image I; + tipl::io::bitmap bmp; if(!bmp.load_from_file(file_names[i].toStdString().c_str())) return false; bmp >> I; if(i == 0) - data.resize(image::geometry<3>(I.width(),I.height(),file_names.size())); + data.resize(tipl::geometry<3>(I.width(),I.height(),file_names.size())); unsigned int pos = i*I.size(); for(unsigned int j = 0;j < I.size();++j) data[pos+j] = ((float)I[j].r+(float)I[j].r+(float)I[j].r)/3.0; @@ -238,24 +238,24 @@ void view_image::update_image(void) { if(data.empty()) return; - image::basic_image tmp(image::geometry<2>(data.width(),data.height())); + tipl::image tmp(tipl::geometry<2>(data.width(),data.height())); unsigned int offset = ui->slice_pos->value()*tmp.size(); std::copy(data.begin() + offset, data.begin() + offset + tmp.size(),tmp.begin()); max_source_value = std::max(max_source_value,*std::max_element(tmp.begin(),tmp.end())); if(max_source_value + 1.0 != 1.0) - image::divide_constant(tmp.begin(),tmp.end(),max_source_value/255.0); + tipl::divide_constant(tmp.begin(),tmp.end(),max_source_value/255.0); - float mean_value = image::mean(tmp.begin(),tmp.end()); - image::minus_constant(tmp.begin(),tmp.end(),mean_value); - image::multiply_constant(tmp.begin(),tmp.end(),ui->contrast->value()); - image::add_constant(tmp.begin(),tmp.end(),mean_value+ui->brightness->value()*25.5); + float mean_value = tipl::mean(tmp.begin(),tmp.end()); + tipl::minus_constant(tmp.begin(),tmp.end(),mean_value); + tipl::multiply_constant(tmp.begin(),tmp.end(),ui->contrast->value()); + tipl::add_constant(tmp.begin(),tmp.end(),mean_value+ui->brightness->value()*25.5); - image::upper_lower_threshold(tmp.begin(),tmp.end(),tmp.begin(),0.0f,255.0f); + tipl::upper_lower_threshold(tmp.begin(),tmp.end(),tmp.begin(),0.0f,255.0f); - buffer.resize(image::geometry<2>(data.width(),data.height())); + buffer.resize(tipl::geometry<2>(data.width(),data.height())); std::copy(tmp.begin(),tmp.end(),buffer.begin()); source_image = QImage((unsigned char*)&*buffer.begin(),data.width(),data.height(),QImage::Format_RGB32). diff --git a/view_image.h b/view_image.h index dfd568457..f5d6984c7 100644 --- a/view_image.h +++ b/view_image.h @@ -3,7 +3,7 @@ #include #include -#include +#include namespace Ui { class view_image; @@ -25,10 +25,10 @@ private slots: private: Ui::view_image *ui; - image::basic_image data; + tipl::image data; private: QGraphicsScene source; - image::color_image buffer; + tipl::color_image buffer; QImage source_image; float max_source_value,source_ratio;