28 #include "DGtal/images/ImageContainerBySTLVector.h"
29 #include "DGtal/helpers/StdDefs.h"
30 #include "DGtal/base/Common.h"
31 #include "DGtal/io/Color.h"
32 #include "DGtal/io/readers/PPMReader.h"
33 #include "DGtal/io/writers/GenericWriter.h"
34 #include "DGtal/images/RigidTransformation2D.h"
39 #include "DGtal/images/bijectiverotations/QSH.h"
40 #include "DGtal/images/bijectiverotations/CDLR.h"
41 #include "DGtal/images/bijectiverotations/RBC.h"
42 #include "DGtal/images/bijectiverotations/OTC.h"
43 #include "DGtal/images/bijectiverotations/CBDR.h"
44 #include "DGtal/images/bijectiverotations/Rotationtables.h"
48 using namespace DGtal;
49 using namespace functors;
53 "OTC",
"CBDR",
"CDLR",
"QSH" ,
"RBC"
57 template <
typename TImage,
typename TBijectiveRotation>
59 performRotation(
const TImage& img, TBijectiveRotation& obj )
62 std::string structName = obj.tostring();
63 TImage output( img.domain() );
64 if ( std::find( sbr.begin(), sbr.end(), structName ) != sbr.end() )
67 output = obj.rotateImage( img );
71 throw std::runtime_error(
"Unsupported bijective rotation : " + structName);
75 void usage(
const std::string& cmd )
77 std::cout <<
"Usage: " << cmd <<
" <image> <angle> [<method>] [black|*white*] [detect]" <<
"\n"
78 <<
"\t Compute the rotated <image> by an angle <angle> (in degrees) \n"
79 <<
"\t - <method> in { OTC, CBDR, CDLR, QSH, *RBC* }\n"
84 int main(
int argc,
char* argv[] )
86 if ( argc < 3 ) {
usage( argv[ 0 ] );
return 1; }
87 std::string fname = argv[ 1 ];
88 double degree = std::atof( argv[ 2 ] );
89 double angle = degree * M_PI / 180.0;
90 std::string method = ( argc > 3 ) ? argv[ 3 ] :
"RBC";
95 typedef MyDomainTransformer::Bounds Bounds;
99 int W=image.
domain().myUpperBound[0]+1;
100 int H=image.domain().myUpperBound[1]+1;
101 trace.
info() <<
"Image has size " << W <<
"x" <<
H << std::endl;
104 if ( method ==
"QSH" )
107 output = performRotation<Image,QSH<Space>> (
image,rotQSH);
109 else if ( method ==
"CDLR" )
111 auto linf = std::make_shared<DGtal::LinfPolicy<Space,Domain,DGtal::CDLR_naiverotation<Space>>>();
113 output = performRotation<Image,CDLR<Space>> (
image,rotDSL);
115 else if ( method ==
"RBC" )
118 rot_rbcvec.setAngle() =
angle;
119 rot_rbcvec.center() = c;
121 output = performRotation<Image,DGtal::RBC<Space,RealPoint>> (
image,rot_RBC);
123 else if ( method ==
"CBDR" )
125 auto linfCBDR = std::make_shared<DGtal::LinfPolicy<Space,Domain,DGtal::CBDR_naiverotation<Space>>>();
129 output = performRotation<Image,DGtal::CBDR<Space,RealPoint>> (
image,rot_CBDR);
132 else if ( method ==
"OTC" )
135 std::vector< std::vector< int > > tableOTC = DGtal::functions::loadOTCTable<Space>(
"../tables/",rwidth);
137 int alpha = int( round( angle * 180.0 / M_PI ) );
138 rot_OTC.set_angle( alpha );
139 output = performRotation<Image,DGtal::OTC<Space,RealPoint>> (
image,rot_OTC);
143 std::string out_fname =
"rotated-image-" + method +
"-" + std::to_string(
int(degree) );
void usage(int, char **argv)
CDLR : Rotation with Discrete Line Reflections,.
Aim: implements association bewteen points lying in a digital domain and values.
const Domain & domain() const
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
CBDR : Composition of Bijective Digitized Reflections,.
OTC : Optimal Transport through Circle bijective rotation.
static ImageContainer importPPM(const std::string &aFilename, const Functor &aFunctor=functors::ColorRGBEncoder< Value >(), bool topbotomOrder=true)
QSH : Quasi Shears represents a bijective rotation through shears.
RBC : Bijective Rotation through Circles.
RBC : Bijective Rotation through Circles.
int main(int argc, char **argv)
std::vector< std::string > supportedBijectiveRotation
double angle(const DGtal::Z2i::RealPoint &point)
ImageContainerBySTLVector< Domain, Value > Image