@@ -41713,61 +41713,82 @@ namespace cimg_library {
4171341713 /**
4171441714 \param axis Splitting axis. Can be <tt>{ 'x' | 'y' | 'z' | 'c' }</tt>.
4171541715 \param nb Number of split parts.
41716+ \param is_split2 Tells if split must be done only in two parts (only valid if nb<0).
4171641717 \note
4171741718 - If \c nb==0, instance image is split into blocs of equal values along the specified axis.
4171841719 - If \c nb<=0, instance image is split into blocs of -\c nb pixel wide.
4171941720 - If \c nb>0, instance image is split into \c nb blocs.
4172041721 **/
41721- CImgList<T> get_split(const char axis, const int nb=-1) const {
41722+ CImgList<T> get_split(const char axis, const int nb=-1, const bool is_split2=false ) const {
4172241723 CImgList<T> res;
4172341724 if (is_empty()) return res;
4172441725 const char _axis = cimg::lowercase(axis);
4172541726
4172641727 if (nb<0) { // Split by block size
41727- const unsigned int dp = (unsigned int)(nb? -nb:1) ;
41728+ const unsigned int dp = (unsigned int)-nb;
4172841729 switch (_axis) {
4172941730 case 'x': {
41730- if (_width>dp) {
41731- res.assign(_width/dp + (_width%dp?1:0),1,1);
41732- const unsigned int pe = _width - dp;
41733- cimg_pragma_openmp(parallel for cimg_openmp_if(res._width>=(cimg_openmp_sizefactor)*128 &&
41734- _height*_depth*_spectrum>=128))
41735- for (int p = 0; p<(int)pe; p+=dp)
41736- get_crop(p,0,0,0,p + dp - 1,_height - 1,_depth - 1,_spectrum - 1).move_to(res[p/dp]);
41737- get_crop((res._width - 1)*dp,0,0,0,_width - 1,_height - 1,_depth - 1,_spectrum - 1).move_to(res.back());
41731+ if (dp<_width) {
41732+ if (is_split2) {
41733+ res.assign(2);
41734+ get_columns(0,dp - 1).move_to(res[0]);
41735+ get_columns(dp,width() - 1).move_to(res[1]);
41736+ } else {
41737+ res.assign(_width/dp + (_width%dp?1:0));
41738+ const unsigned int pe = _width - dp;
41739+ cimg_pragma_openmp(parallel for cimg_openmp_if(res._width>=(cimg_openmp_sizefactor)*128 &&
41740+ _height*_depth*_spectrum>=128))
41741+ for (int p = 0; p<(int)pe; p+=dp) get_columns(p,p + dp - 1).move_to(res[p/dp]);
41742+ get_columns((res._width - 1)*dp,_width - 1).move_to(res.back());
41743+ }
4173841744 } else res.assign(*this);
4173941745 } break;
4174041746 case 'y': {
41741- if (_height>dp) {
41742- res.assign(_height/dp + (_height%dp?1:0),1,1);
41743- const unsigned int pe = _height - dp;
41744- cimg_pragma_openmp(parallel for cimg_openmp_if(res._width>=(cimg_openmp_sizefactor)*128 &&
41745- _width*_depth*_spectrum>=128))
41746- for (int p = 0; p<(int)pe; p+=dp)
41747- get_crop(0,p,0,0,_width - 1,p + dp - 1,_depth - 1,_spectrum - 1).move_to(res[p/dp]);
41748- get_crop(0,(res._width - 1)*dp,0,0,_width - 1,_height - 1,_depth - 1,_spectrum - 1).move_to(res.back());
41747+ if (dp<_height) {
41748+ if (is_split2) {
41749+ res.assign(2);
41750+ get_rows(0,dp - 1).move_to(res[0]);
41751+ get_rows(dp,height() - 1).move_to(res[1]);
41752+ } else {
41753+ res.assign(_height/dp + (_height%dp?1:0));
41754+ const unsigned int pe = _height - dp;
41755+ cimg_pragma_openmp(parallel for cimg_openmp_if(res._width>=(cimg_openmp_sizefactor)*128 &&
41756+ _width*_depth*_spectrum>=128))
41757+ for (int p = 0; p<(int)pe; p+=dp) get_rows(p,p + dp - 1).move_to(res[p/dp]);
41758+ get_rows((res._width - 1)*dp,_height - 1).move_to(res.back());
41759+ }
4174941760 } else res.assign(*this);
4175041761 } break;
4175141762 case 'z': {
41752- if (_depth>dp) {
41753- res.assign(_depth/dp + (_depth%dp?1:0),1,1);
41754- const unsigned int pe = _depth - dp;
41755- cimg_pragma_openmp(parallel for cimg_openmp_if(res._width>=(cimg_openmp_sizefactor)*128 &&
41756- _width*_height*_spectrum>=128))
41757- for (int p = 0; p<(int)pe; p+=dp)
41758- get_crop(0,0,p,0,_width - 1,_height - 1,p + dp - 1,_spectrum - 1).move_to(res[p/dp]);
41759- get_crop(0,0,(res._width - 1)*dp,0,_width - 1,_height - 1,_depth - 1,_spectrum - 1).move_to(res.back());
41763+ if (dp<_depth) {
41764+ if (is_split2) {
41765+ res.assign(2);
41766+ get_slices(0,dp - 1).move_to(res[0]);
41767+ get_slices(dp,depth() - 1).move_to(res[1]);
41768+ } else {
41769+ res.assign(_depth/dp + (_depth%dp?1:0));
41770+ const unsigned int pe = _depth - dp;
41771+ cimg_pragma_openmp(parallel for cimg_openmp_if(res._width>=(cimg_openmp_sizefactor)*128 &&
41772+ _width*_height*_spectrum>=128))
41773+ for (int p = 0; p<(int)pe; p+=dp) get_slices(p,p + dp - 1).move_to(res[p/dp]);
41774+ get_slices((res._width - 1)*dp,_depth - 1).move_to(res.back());
41775+ }
4176041776 } else res.assign(*this);
4176141777 } break;
4176241778 case 'c' : {
41763- if (_spectrum>dp) {
41764- res.assign(_spectrum/dp + (_spectrum%dp?1:0),1,1);
41765- const unsigned int pe = _spectrum - dp;
41766- cimg_pragma_openmp(parallel for cimg_openmp_if(res._width>=(cimg_openmp_sizefactor)*128 &&
41767- _width*_height*_depth>=128))
41768- for (int p = 0; p<(int)pe; p+=dp)
41769- get_crop(0,0,0,p,_width - 1,_height - 1,_depth - 1,p + dp - 1).move_to(res[p/dp]);
41770- get_crop(0,0,0,(res._width - 1)*dp,_width - 1,_height - 1,_depth - 1,_spectrum - 1).move_to(res.back());
41779+ if (dp<_spectrum) {
41780+ if (is_split2) {
41781+ res.assign(2);
41782+ get_channels(0,dp - 1).move_to(res[0]);
41783+ get_channels(dp,spectrum() - 1).move_to(res[1]);
41784+ } else {
41785+ res.assign(_spectrum/dp + (_spectrum%dp?1:0));
41786+ const unsigned int pe = _spectrum - dp;
41787+ cimg_pragma_openmp(parallel for cimg_openmp_if(res._width>=(cimg_openmp_sizefactor)*128 &&
41788+ _width*_height*_depth>=128))
41789+ for (int p = 0; p<(int)pe; p+=dp) get_channels(p,p + dp - 1).move_to(res[p/dp]);
41790+ get_channels((res._width - 1)*dp,_spectrum - 1).move_to(res.back());
41791+ }
4177141792 } else res.assign(*this);
4177241793 }
4177341794 }
@@ -41783,34 +41804,17 @@ namespace cimg_library {
4178341804 int err = (int)siz;
4178441805 unsigned int _p = 0;
4178541806 switch (_axis) {
41786- case 'x' : {
41787- cimg_forX(*this,p) if ((err-=nb)<=0) {
41788- get_crop(_p,0,0,0,p,_height - 1,_depth - 1,_spectrum - 1).move_to(res);
41789- err+=(int)siz;
41790- _p = p + 1U;
41791- }
41792- } break;
41793- case 'y' : {
41794- cimg_forY(*this,p) if ((err-=nb)<=0) {
41795- get_crop(0,_p,0,0,_width - 1,p,_depth - 1,_spectrum - 1).move_to(res);
41796- err+=(int)siz;
41797- _p = p + 1U;
41798- }
41799- } break;
41800- case 'z' : {
41801- cimg_forZ(*this,p) if ((err-=nb)<=0) {
41802- get_crop(0,0,_p,0,_width - 1,_height - 1,p,_spectrum - 1).move_to(res);
41803- err+=(int)siz;
41804- _p = p + 1U;
41805- }
41806- } break;
41807- case 'c' : {
41808- cimg_forC(*this,p) if ((err-=nb)<=0) {
41809- get_crop(0,0,0,_p,_width - 1,_height - 1,_depth - 1,p).move_to(res);
41810- err+=(int)siz;
41811- _p = p + 1U;
41812- }
41813- }
41807+ case 'x' :
41808+ cimg_forX(*this,p) if ((err-=nb)<=0) { get_columns(_p,p).move_to(res); err+=(int)siz; _p = p + 1U; }
41809+ break;
41810+ case 'y' :
41811+ cimg_forY(*this,p) if ((err-=nb)<=0) { get_rows(_p,p).move_to(res); err+=(int)siz; _p = p + 1U; }
41812+ break;
41813+ case 'z' :
41814+ cimg_forZ(*this,p) if ((err-=nb)<=0) { get_slices(_p,p).move_to(res); err+=(int)siz; _p = p + 1U; }
41815+ break;
41816+ case 'c' :
41817+ cimg_forC(*this,p) if ((err-=nb)<=0) { get_channels(_p,p).move_to(res); err+=(int)siz; _p = p + 1U; }
4181441818 }
4181541819 }
4181641820 } else { // Split by equal values according to specified axis
@@ -66218,9 +66222,9 @@ namespace cimg_library {
6621866222 }
6621966223
6622066224 //! Return a list where each image has been split along the specified axis \newinstance.
66221- CImgList<T> get_split(const char axis, const int nb=-1) const {
66225+ CImgList<T> get_split(const char axis, const int nb=-1, const bool is_split2=false ) const {
6622266226 CImgList<T> res;
66223- cimglist_for(*this,l) _data[l].get_split(axis,nb).move_to(res,~0U);
66227+ cimglist_for(*this,l) _data[l].get_split(axis,nb,is_split2 ).move_to(res,~0U);
6622466228 return res;
6622566229 }
6622666230
0 commit comments