Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d48f32f
Add 2d bijective rotation approaches
sbreuils Jul 11, 2024
382fa31
continue adding bijective rotations method
sbreuils Jul 18, 2024
aaf63b0
continue adding bijective rotations method with pragma
sbreuils Jul 18, 2024
32b90f8
added error computation for each method
sbreuils Jul 20, 2024
756ae30
remove useless rounding template parameter
sbreuils Jul 22, 2024
8914158
Added new Metrics like the continuity loss
sbreuils Aug 7, 2024
91e83a7
rbc test and remove usless comments
sbreuils Aug 8, 2024
ffaaeae
Add examples and tests
sbreuils Aug 26, 2024
60350d3
update QSH RDSL CDLR OTC
sbreuils Sep 3, 2024
701263b
RDSL to CDLR
sbreuils Sep 3, 2024
81091d7
all approaches except cbdr
sbreuils Sep 4, 2024
cf3371d
rbc has now the right functions
sbreuils Sep 4, 2024
1aeb8c1
updated CBDR is now in the repo
sbreuils Sep 5, 2024
73e0067
Merge branch 'DGtal-team:master' into bijective-rotations
sbreuils Sep 5, 2024
1ee09a7
add error vector field and policy
sbreuils Sep 5, 2024
0b83611
update example with the right header
sbreuils Sep 6, 2024
28ee0c1
update test with the right headers
sbreuils Sep 6, 2024
5b3a3fb
Remove useless disp
sbreuils Sep 6, 2024
c7184cd
add ref in example and remove unused variable
sbreuils Sep 6, 2024
2fb0c64
remove unused stb files
sbreuils Sep 6, 2024
714b1ad
Rotationtable has now the right file name in the comment
sbreuils Sep 6, 2024
f68361d
add comments for all parameters of CBDR constructor
sbreuils Sep 6, 2024
f0b3cf3
revise comments parameter in NbijectiveGenerator
sbreuils Sep 6, 2024
d49e6f3
OTC constructor white unused
sbreuils Sep 6, 2024
b71345a
revise QSH constructor s comments
sbreuils Sep 6, 2024
fa2b932
revise OTC constructor comments
sbreuils Sep 6, 2024
f54d7f8
Merge branch 'master' into bijective-rotations
dcoeurjo Nov 30, 2024
22738f4
Merge branch 'master' into bijective-rotations
dcoeurjo Jan 9, 2025
83589a5
Merge branch 'master' into bijective-rotations
dcoeurjo Aug 19, 2025
584f70d
Merge branch 'master' into bijective-rotations
dcoeurjo Aug 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions examples/images/example2DBijectiveRotations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
**/

#pragma once

/**
* @file CBDR.h
* @author S. Breuils, J.O. Lachaud, D. Coeurjolly ; [email protected]
* @ingroup Examples
* @date 2024/08
*
* This file is part of the DGtal library.
*/
#include <iostream>

Check warning on line 27 in examples/images/example2DBijectiveRotations.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

examples/images/example2DBijectiveRotations.cpp#L27

Include file: <iostream> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/readers/PPMReader.h"
#include "DGtal/io/writers/GenericWriter.h"
#include "DGtal/images/RigidTransformation2D.h"


//////////////////////////////////////////////////////////////////////////////
// Inclusions
#include "DGtal/images/bijectiverotations/QSH.h"
#include "DGtal/images/bijectiverotations/CDLR.h"
#include "DGtal/images/bijectiverotations/RBC.h"
#include "DGtal/images/bijectiverotations/OTC.h"
#include "DGtal/images/bijectiverotations/CBDR.h"
#include "DGtal/images/bijectiverotations/Rotationtables.h"


using namespace std;
using namespace DGtal;
using namespace functors;
using namespace Z2i;

std::vector<std::string> supportedBijectiveRotation = {
"OTC", "CBDR", "CDLR", "QSH" , "RBC"
};

// Generic function to handle rotation based on type
template <typename TImage,typename TBijectiveRotation>
TImage
performRotation( const TImage& img, TBijectiveRotation& obj )
{
const auto& sbr = supportedBijectiveRotation;
std::string structName = obj.tostring();
TImage output( img.domain() );
if ( std::find( sbr.begin(), sbr.end(), structName ) != sbr.end() )
{
trace.beginBlock ( obj.tostring() );
output = obj.rotateImage( img );
trace.endBlock ();
}
else
throw std::runtime_error("Unsupported bijective rotation : " + structName);
return output;
}

void usage( const std::string& cmd )
{
std::cout << "Usage: " << cmd << " <image> <angle> [<method>] [black|*white*] [detect]" << "\n"
<< "\t Compute the rotated <image> by an angle <angle> (in degrees) \n"
<< "\t - <method> in { OTC, CBDR, CDLR, QSH, *RBC* }\n"
<< std::endl;
}


int main( int argc, char* argv[] )
{
if ( argc < 3 ) { usage( argv[ 0 ] ); return 1; }
std::string fname = argv[ 1 ];
double degree = std::atof( argv[ 2 ] );
double angle = degree * M_PI / 180.0;
std::string method = ( argc > 3 ) ? argv[ 3 ] : "RBC";

typedef ImageContainerBySTLVector< Domain, Color > Image;
typedef ForwardRigidTransformation2D < Space > ForwardTrans;
typedef DomainRigidTransformation2D < Domain, ForwardTrans > MyDomainTransformer;
typedef MyDomainTransformer::Bounds Bounds;

Image image = DGtal::PPMReader<Image>::importPPM ( fname );
Image output = image;
int W=image.domain().myUpperBound[0]+1;
int H=image.domain().myUpperBound[1]+1;
trace.info() << "Image has size " << W << "x" << H << std::endl;
Point c(W/2, H/2);

if ( method == "QSH" )
{
DGtal::QSH<Space> rotQSH(angle,c);
output = performRotation<Image,QSH<Space>> (image,rotQSH);
}
else if ( method == "CDLR" )
{
auto linf = std::make_shared<DGtal::LinfPolicy<Space,Domain,DGtal::CDLR_naiverotation<Space>>>();
DGtal::CDLR<DGtal::SpaceND<2, DGtal::int32_t> > rotDSL(angle, c, linf);
output = performRotation<Image,CDLR<Space>> (image,rotDSL);
}
else if ( method == "RBC" )
{
DGtal::RBC_vec<Space,RealPoint> rot_rbcvec(2*max(W,H));
rot_rbcvec.setAngle() = angle;
rot_rbcvec.center() = c;
DGtal::RBC<Space,RealPoint> rot_RBC(rot_rbcvec,angle,c);
output = performRotation<Image,DGtal::RBC<Space,RealPoint>> (image,rot_RBC);
}
else if ( method == "CBDR" )
{
auto linfCBDR = std::make_shared<DGtal::LinfPolicy<Space,Domain,DGtal::CBDR_naiverotation<Space>>>();
const int n = 4;
const int kmax=30;
DGtal::CBDR<Space,RealPoint> rot_CBDR(angle,c,n,kmax,linfCBDR,true);
output = performRotation<Image,DGtal::CBDR<Space,RealPoint>> (image,rot_CBDR);
}

else if ( method == "OTC" )
{
int rwidth = 2;
std::vector< std::vector< int > > tableOTC = DGtal::functions::loadOTCTable<Space>("../tables/",rwidth);
DGtal::OTC<Space,RealPoint> rot_OTC( tableOTC, rwidth, c, W, H );
int alpha = int( round( angle * 180.0 / M_PI ) );
rot_OTC.set_angle( alpha ); // in degree
output = performRotation<Image,DGtal::OTC<Space,RealPoint>> (image,rot_OTC);
}


std::string out_fname = "rotated-image-" + method + "-" + std::to_string( int(degree) );
out_fname += ".ppm";
output >> out_fname;
return 0;
}
Loading
Loading