Skip to content

Commit d883e65

Browse files
committed
Add existing file
1 parent 40ae9fe commit d883e65

File tree

145 files changed

+36233
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+36233
-0
lines changed

AbstractionProcess.cpp

Lines changed: 2168 additions & 0 deletions
Large diffs are not rendered by default.

AbstractionProcess.h

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*--------------------------- MegaWave2 Module -----------------------------*/
2+
/* mwcommand
3+
name = {fgrain_side};
4+
version = {"1.2"};
5+
author = {"Pascal Monasse, Frederic Guichard, G. Facciolo"};
6+
function = {"Grain filter of an image"};
7+
usage = {
8+
'a': [min_area=20]-> pMinArea "Min area of grains we keep",
9+
image_in -> pFloatImageInput "Input fimage",
10+
image_out <- pFloatImageOutput "Output fimage"
11+
};
12+
*/
13+
/*----------------------------------------------------------------------
14+
v1.2 (04/2007): simplified header (LM)
15+
v1.3 (2013): portable version (GF)
16+
v1.4 (2014): fgrain_side: removes only upper (bright) or lower (dark) courves
17+
----------------------------------------------------------------------*/
18+
19+
#ifndef ABSTRACTIONGRAINPROCESS_H
20+
#define ABSTRACTIONGRAINPROCESS_H
21+
22+
#include <QImage>
23+
24+
#include "mw3.h"
25+
#include "mw3-modules.h"
26+
#include "stdio.h"
27+
#include "stdlib.h"
28+
#include "tree_of_shapes.h"
29+
#include <cfloat>
30+
#include "TreeOfShapes.h"
31+
32+
enum Abstraction_Mode { COLOR_SKETCH=0, FILTER_COLOR=1, SHOW_TREE=2, SYNTEXTURE_COLOR=3, SYNTEXTURE_COLOR_WA=4,
33+
SYNTEXTURE_COLOR_DICT=5, SYNTEXTURE_COLOR_DICT2=6, SYNTEXTURE_COLOR_V2=7,
34+
SYNTEXTURE_COLOR_V3=8, SYNTEXTURE_COLOR_V4=9,
35+
SYNTEXTURE_COLOR_DICT2_OUTPUT=10, SYNTEXTURE_COLOR_DICT3=11, SYNTEXTURE_COLOR_MULT=12,
36+
SYNTEXTURE_COLOR_TT=13};
37+
38+
class AbstractionProcess
39+
{
40+
public:
41+
AbstractionProcess(){ _image_loaded = false; }
42+
AbstractionProcess( std::string fileNameIn );
43+
AbstractionProcess( const QImage &imageIn );
44+
~AbstractionProcess();
45+
46+
QImage run (int process, char* dictionnary_name);
47+
QImage render(TOSParameters tosParameters, bool &tree_recomputed, DictionaryParameters dictionaryParameters = getDefaultDictionaryParameters(), TreeOfShapes * dictionnary=NULL);
48+
std::vector<QImage> render_shape_by_shape(TOSParameters tosParameters, DictionaryParameters dictionaryParameters, TreeOfShapes * dictionnary);
49+
void addDictionnary( TreeOfShapes * dictionary );
50+
51+
void save_shapes( QString folder_name, bool average_color ){ _treeOfShapes->save_shapes(folder_name, average_color); }
52+
void save_shapes( QString folder_name, TOSParameters tosParameters, DictionaryParameters dictionaryParameters = getDefaultDictionaryParameters(), TreeOfShapes * dictionnary=NULL );
53+
TOSParameters getParameters(){return _tosParameters;}
54+
int getMaxArea(){return _treeOfShapes->getMaxArea();}
55+
void getTreeInfo(std::vector<QPoint> &positions, std::vector<QColor> &colors,
56+
std::vector< std::vector< std::pair<int, int> > > &pixels, std::vector<int> & heights, std::vector<std::pair<int, int> > &edges){
57+
_treeOfShapes->getTreeInfo(positions, colors, pixels, heights, edges);
58+
}
59+
protected:
60+
bool _tree_computed;
61+
Cfimage _imgin;
62+
bool _image_loaded;
63+
64+
TreeOfShapes *_treeOfShapes;
65+
TreeOfShapes *_dictionnary;
66+
67+
Shapes _pTree;
68+
69+
Fimage _NormOfDu;
70+
71+
TOSParameters _tosParameters;
72+
73+
void init(Cfimage inputImg, Shapes &pTree);
74+
75+
Cfimage cfimageread(const char* name);
76+
77+
Cfimage cfimages_from_qimage( const QImage &input_image );
78+
79+
QImage qimages_from_cfimage( Cfimage input_img );
80+
81+
QImage qimages_from_ccimage( Ccimage input_img );
82+
83+
/* This removes the shapes from the tree associated to pFloatImageInput
84+
that are too small (threshold *pMinArea). As a consequence all the remaining
85+
shapes of pFloatImageOutput are of area larger or equal than *pMinArea */
86+
87+
void mw_fgrain_side(int *pMinArea, Fimage pFloatImageInput, Fimage pFloatImageOutput, int sideflag);
88+
89+
90+
/*in and out must be allocated*/
91+
void fgrain_side(int MinArea, float *in, int nx, int ny, float *out, int sideflag);
92+
93+
Shape m_order_parent(Shape pShape,
94+
int *mn,
95+
bool dict = false);
96+
void Order(Fsignal t2b_index,
97+
int *p, int *q);
98+
void Bubble( Fsignal t2b_index);
99+
100+
void shape_orilam(Shape pShape,float *out_ori, float *out_e, float *out_k);
101+
void shape_orilam(Shape pShape, float *out_ori, float *out_e, float *out_k, float *pX0, float *pY0);
102+
void compute_shape_attribute();
103+
104+
float min_contrast(Shape pShape);
105+
106+
void synshapeEllipse(Shape pShape,
107+
Ccimage imgsyn,
108+
float *alpha,
109+
int *relief,
110+
float *reliefOrentation, float *reliefHeight);
111+
void synshapeRect(Shape pShape,
112+
Ccimage imgsyn,
113+
float *alpha,
114+
int *relief,
115+
float *reliefOrentation, float *reliefHeight);
116+
void synshapeOriginal(Shape pShape,
117+
Ccimage imgsyn,
118+
Cimage imgShapeLabelSyn,
119+
Fimage imgShapeBlurSyn,
120+
Fsignal gaussKernel,
121+
int *median,
122+
float *alpha,
123+
int *relief,
124+
float *reliefOrentation, float *reliefHeight);
125+
void synshapeOriginal( Shape pShape,
126+
Ccimage imgsyn,
127+
float *alpha);
128+
129+
void top2bottom_index_tree(Fsignal t2b_index);
130+
void random_tree_order(Fsignal t2b_index);
131+
132+
void random_leaf(Fsignal leaf,
133+
Fsignal t2b_index,
134+
int *k_ind);
135+
136+
void random_shift_shape(float *shift);
137+
void adaptive_shift_shape(float *shift,
138+
float *theta);
139+
float mean_contrast(Shape pShape);
140+
141+
Fsignal sgauss(float *std,
142+
Fsignal out,
143+
int *size);
144+
Fsignal Sgauss(float *std, Fsignal out, int *size);
145+
146+
float peri_shape(Shape pShape);
147+
148+
void compute_shape_attribute(int *ns);
149+
void filter_image(int *ns,
150+
float *alpha,
151+
int *mpixel);
152+
void filter_shapes( Fimage sketch,
153+
Cfimage out,
154+
char *local,
155+
float *eps);
156+
void get_shapes_truearea(Shape s, Shape root,
157+
int *truearea);
158+
159+
Shape selectShapeDict(Shapes pTreeDict,
160+
Shape pShape,
161+
float *paDict,
162+
int *randS);
163+
int random_number(int *M);
164+
};
165+
166+
#endif // ABSTRACTIONGRAINPROCESS_H

Dictionary.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "Dictionary.h"
2+
3+
Dictionary::Dictionary()
4+
{
5+
6+
}
7+

Dictionary.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef DICTIONARY_H
2+
#define DICTIONARY_H
3+
4+
5+
class Dictionary : public TreeOfShapes
6+
{
7+
public:
8+
Dictionary();
9+
};
10+
11+
#endif // DICTIONARY_H

ImageLabel.cpp

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
#include "ImageLabel.h"
2+
#include <QPainter>
3+
4+
#include <iostream>
5+
6+
ImageLabel::ImageLabel(QWidget *parent) :
7+
QLabel(parent)
8+
{
9+
10+
_draw_selection = false;
11+
_selection_active = false;
12+
_current_scale = 1.;
13+
_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
14+
_click_pos = QPoint(0,0);
15+
16+
}
17+
18+
19+
void ImageLabel::mousePressEvent(QMouseEvent *event)
20+
{
21+
_click_pos = event->pos();
22+
if( _draw_selection ){
23+
_move_selection = false;
24+
25+
if( _selection_active
26+
&& std::min( _origin.x(), _end.x() ) < _click_pos.x() && std::max( _origin.x(), _end.x() ) > _click_pos.x()
27+
&& std::min( _origin.y(), _end.y() ) < _click_pos.y() && std::max( _origin.y(), _end.y() ) > _click_pos.y()){
28+
_move_selection = true;
29+
_previous_mouse_pos = _click_pos;
30+
} else {
31+
32+
delete _rubberBand;
33+
_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
34+
35+
_rubberBand->setGeometry(QRect(_click_pos, QSize()));
36+
_rubberBand->show();
37+
_selection_active = true;
38+
}
39+
}
40+
emit pointClicked();
41+
}
42+
43+
void ImageLabel::mouseMoveEvent(QMouseEvent *event)
44+
{
45+
if( _draw_selection ){
46+
if( _move_selection ){
47+
QPoint translation = event->pos() - _previous_mouse_pos;
48+
_origin = _origin+translation;
49+
_end = _end+translation;
50+
_previous_mouse_pos = event->pos();
51+
} else {
52+
_origin = _click_pos;
53+
_end = event->pos();
54+
55+
}
56+
_rubberBand->setGeometry(QRect(_origin, _end).normalized());
57+
emit selectionChanged();
58+
}
59+
}
60+
61+
void ImageLabel::mouseReleaseEvent(QMouseEvent *event)
62+
{
63+
if( _draw_selection ){
64+
QPoint release_pos = event->pos();
65+
_selection_active = true;
66+
67+
if(! _move_selection )
68+
if( abs(_click_pos.x() - release_pos.x()) > 1 && abs(_click_pos.y() - release_pos.y()) > 1 ){
69+
_origin = _click_pos;
70+
_end = release_pos;
71+
emit selectionChanged();
72+
} else {
73+
_selection_active = false;
74+
}
75+
76+
_move_selection = false;
77+
}
78+
// if (rubberBand)
79+
// rubberBand->hide();
80+
// determine selection, for example using QRect::intersects()
81+
// and QRect::contains().
82+
83+
84+
}
85+
86+
void ImageLabel::updateImage( const QImage &image){
87+
this->setPixmap(QPixmap::fromImage(image));
88+
}
89+
90+
void ImageLabel::setImage( const QImage &image){
91+
_current_scale = 1.;
92+
_input_size = image.size();
93+
this->setPixmap(QPixmap::fromImage(image));
94+
}
95+
96+
void ImageLabel::setScale(float scale){
97+
98+
this->resize(scale * this->pixmap()->size());
99+
100+
_origin = (_origin/_current_scale)*scale;
101+
_end = (_end/_current_scale)*scale;
102+
103+
if( _draw_selection && _selection_active )
104+
_rubberBand->setGeometry(QRect(_origin, _end).normalized());
105+
106+
_current_scale = scale;
107+
}
108+
109+
110+
QImage ImageLabel::crop(){
111+
112+
QImage image = this->pixmap()->toImage();
113+
114+
if( _selection_active && _draw_selection ){
115+
QPoint A( std::min( _origin.x(), _end.x() ), std::min( _origin.y(), _end.y() ) );
116+
QPoint B( std::max( _origin.x(), _end.x() ), std::max( _origin.y(), _end.y() ) );
117+
118+
A = A/_current_scale;
119+
B = B/_current_scale;
120+
121+
A = QPoint ( std::min( std::max( 0, A.x() ), this->pixmap()->width()-1 ), std::min( std::max( 0, A.y() ), this->pixmap()->height()-1 ) );
122+
B = QPoint ( std::min( std::max( 0, B.x() ), this->pixmap()->width()-1 ), std::min( std::max( 0, B.y() ), this->pixmap()->height()-1 ) );
123+
124+
image = image.copy(QRect( A, B ));
125+
}
126+
return image;
127+
}
128+
129+
130+
QRect ImageLabel::getSelection(){
131+
QPoint A( 0, 0 );
132+
QPoint B( this->pixmap()->width(), this->pixmap()->height() );
133+
134+
if( _selection_active && _draw_selection ){
135+
A = QPoint( std::min( _origin.x(), _end.x() ), std::min( _origin.y(), _end.y() ) );
136+
B = QPoint( std::max( _origin.x(), _end.x() ), std::max( _origin.y(), _end.y() ) );
137+
138+
A = A/_current_scale;
139+
B = B/_current_scale;
140+
141+
A = QPoint ( std::min( std::max( 0, A.x() ), this->pixmap()->width() ), std::min( std::max( 0, A.y() ), this->pixmap()->height() ) );
142+
B = QPoint ( std::min( std::max( 0, B.x() ), this->pixmap()->width() ), std::min( std::max( 0, B.y() ), this->pixmap()->height() ) );
143+
}
144+
return QRect( A, B );
145+
146+
}
147+
QPoint ImageLabel::getClickedPixel(){
148+
return _click_pos/_current_scale;
149+
}
150+
151+
void ImageLabel::setDrawSelection(bool draw_selection) {
152+
_draw_selection = draw_selection;
153+
154+
if(_draw_selection) {
155+
156+
if( !_selection_active ){
157+
delete _rubberBand;
158+
_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
159+
160+
QSize image_size = this->pixmap()->size();
161+
_origin = QPoint( image_size.width()*_current_scale*0.25, image_size.height()*_current_scale*0.25 );
162+
_end = QPoint( image_size.width()*0.75*_current_scale, image_size.height()*_current_scale*0.75 );
163+
_rubberBand->setGeometry(QRect(_origin, _end).normalized());
164+
165+
_selection_active = true;
166+
}
167+
_rubberBand->show();
168+
emit selectionChanged();
169+
} else {
170+
_rubberBand->hide();
171+
}
172+
173+
}
174+
175+
void ImageLabel::paintEvent(QPaintEvent * e){
176+
QLabel::paintEvent(e);
177+
178+
if(_selection_active)
179+
{
180+
181+
//TODO draw center
182+
}
183+
}

0 commit comments

Comments
 (0)