forked from my3rs/ImageQt
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
executable file
·1115 lines (872 loc) · 33.8 KB
/
mainwindow.cpp
File metadata and controls
executable file
·1115 lines (872 loc) · 33.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QGraphicsPixmapItem>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
leftScene = new QGraphicsScene;
rightScene = new QGraphicsScene;
size = new QLabel;
info = NULL;
leftScene->setBackgroundBrush(QColor::fromRgb(224,224,224));
ui->leftGraphicsView->setScene(leftScene);
rightScene->setBackgroundBrush(QColor::fromRgb(224,224,224));
ui->rightGraphicsView->setScene(rightScene);
ui->statusBar->addPermanentWidget(size);
createAction();
createToolBar();
setActionStatus(false);
setWindowTitle("ImageQt");
ui->actionEnglish->setEnabled(false);
}
void MainWindow::createToolBar()
{
ui->toolBar->addAction(ui->actionOpen);
ui->toolBar->addAction(ui->actionClose);
ui->toolBar->addSeparator();
ui->toolBar->addAction(ui->actionRestore);
ui->toolBar->addAction(ui->actionHistogram);
ui->toolBar->addSeparator();
ui->toolBar->addAction(ui->actionChinese);
ui->toolBar->addSeparator();
ui->toolBar->addAction(finalEx);
}
void MainWindow::createAction()
{
finalEx = new QAction(QIcon(":/img/src/Final_Cut_Pro_X_96px_1134672_easyicon.net.png"), tr("Final"), this);
connect(finalEx, SIGNAL(triggered(bool)), this, SLOT(on_actionFinal_triggered()));
}
void MainWindow::on_actionFinal_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::Final(rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
MainWindow::~MainWindow()
{
delete ui;
if (leftScene)
{
delete leftScene;
leftScene = NULL;
}
if (size)
{
delete size;
size = NULL;
}
//add
if (rightScene)
{
delete leftScene;
leftScene = NULL;
}
}
/******************************************************************************
* Update right image and repaint right scene
*****************************************************************************/
void MainWindow::updateRightImage(QPixmap &pixmap)
{
rightPixmapItem->setPixmap(pixmap);
rightScene->setSceneRect(QRectF(pixmap.rect()));
qDebug() << "repaintRightScene" << rightScene->items().count();
}
/******************************************************************************
* Clean image of both Scene
*
*****************************************************************************/
void MainWindow::cleanImage()
{
leftScene->clear();
ui->leftGraphicsView->resetTransform();
rightScene->clear();
ui->rightGraphicsView->resetTransform();
if (size)
{
delete size;
size = new QLabel;
ui->statusBar->addPermanentWidget(size);
}
this->setWindowTitle(WINDOW_TITLE);
setActionStatus(false);
}
void MainWindow::setActionStatus(bool status)
{
ui->actionPrewitt->setEnabled(status);
ui->actionContour_extraction->setEnabled(status);
ui->actionEdge_following->setEnabled(status);
// sharpen
ui->actionLaplace->setEnabled(status);
ui->actionSobel->setEnabled(status);
//ui->actionEdge_Detection->setEnabled(status);
// Blur
ui->actionSimple->setEnabled(status);
ui->actionGauss->setEnabled(status);
ui->actionMeida_Filter->setEnabled(status);
// Grey Transform
ui->actionBinaryzation->setEnabled(status);
ui->actionStretch_transformation->setEnabled(status);
ui->actionExp_transfrom->setEnabled(status);
ui->actionTwo_thresholds_transform->setEnabled(status);
ui->actionPower_transformation->setEnabled(status);
ui->actionLogarithm_grey_level_transformation->setEnabled(status);
ui->actionSave->setEnabled(status);
ui->actionClose->setEnabled(status);
ui->actionSave_As->setEnabled(status);
ui->actionCool->setEnabled(status);
ui->actionWarm->setEnabled(status);
ui->actionFlower_frame->setEnabled(status);
ui->actionGrayscale->setEnabled(status);
ui->actionHistogram->setEnabled(status);
ui->actionHorizontal->setEnabled(status);
ui->actionLeft->setEnabled(status);
ui->actionLinear_level_transformation->setEnabled(status);
ui->actionMetal->setEnabled(status);
ui->actionMovie_frame->setEnabled(status);
ui->actionNormal->setEnabled(status);
ui->actionRestore->setEnabled(status);
ui->actionVertical->setEnabled(status);
ui->actionClassic_frame->setEnabled(status);
ui->actionAdjust_brightness->setEnabled(status);
ui->actionRight->setEnabled(status);
ui->zoomAction->setEnabled(status);
}
void MainWindow::receiveGaussianFactor(int radius, double sigma)
{
GaussianBlur *blur = new GaussianBlur(radius, sigma);
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = blur->BlurImage(rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
///******************************************************************************
// * Receive data from zoom dialog
// * and then call the function to done zoom action
// *****************************************************************************/
//void MainWindow::receiveZoomFactor(int factor)
//{
// qDebug()<<"zoom factor:"<<factor;
// if (factor != 100)
// {
// QPixmap rightImage = rightPixmapItem->pixmap();
// int cur_width = rightImage.width();
// int cur_height = rightImage.height();
// QPixmap newPixmap = rightImage.scaled(cur_width*factor/100, cur_height*factor/100);
// updateRightImage(newPixmap);
// }
// else
// {
// return;
// }
//}
void MainWindow::receiveLinearGreyParameter(double _a, double _b)
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::LinearLevelTransformation(rightImage.toImage(), _a, _b);
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
void MainWindow::receivePowerGreyParamter(double c, double r, double b)
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::PowerGreyLevelTransformation(rightImage.toImage(), c, r, b);
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
void MainWindow::receiveLogGreyParamter(double _a, double _b)
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::LinearLevelTransformation(rightImage.toImage(), _a, _b);
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
void MainWindow::receiveExpGreyParamter(double b, double c, double a)
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::ExpTransform(rightImage.toImage(), b, c, a);
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
void MainWindow::receiveTwoThresholdParamter(int t1, int t2, int option)
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::TwoThreshold(rightImage.toImage(), t1, t2, option);
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
void MainWindow::receiveStretchParamter(int x1, int x2,
double k1, double k2, double k3,
double b2, double b3)
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::StretchTransform(rightImage.toImage(),x1,x2,k1,k2,k3,b2,b3);
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
/******************************************************************************
* Open a image file and show it
******************************************************************************
* Args:
* QString imagePath: The abslute path of a image
*****************************************************************************/
void MainWindow::on_actionOpen_triggered()
{
// Automatically detects the current user's home directory
// And then wait the user to select one image
QString imagePath = QFileDialog::getOpenFileName(this, tr("Open image"), getUserPath() + "/Pictures",
tr("All Files (*);;"
"All Images (*.bpm *.gif *.jpg *.jpeg *.png *.ppm *.xbm *.xpm);;"
"Image BPM (*.bpm);;"
"Image GIF (*.gif);;"
"Image JPG (*.jpg);;"
"Image JPEG (*.jpeg);;"
"Image PNG (*.png);;"
"Image PPM (*.ppm);;"
"Image XBM (*.xbm);;"
"Image XPM (*.xpm);;"));
if (!imagePath.isEmpty())
{
QFile file(imagePath);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, tr(WINDOW_CRITICAL),
tr("Unable to open image."));
return;
}
// delete previous image
cleanImage();
// upload image
info = new QFileInfo(imagePath);
QPixmap leftPixmap(imagePath);
leftPixmapItem = leftScene->addPixmap(leftPixmap);
leftScene->setSceneRect(QRectF(leftPixmap.rect()));
QPixmap rightPixmap(imagePath);
rightPixmapItem = rightScene->addPixmap(rightPixmap);
rightScene->setSceneRect(QRectF(rightPixmap.rect()));
qDebug()<<"depth:"<<rightPixmap.depth();
qDebug()<<"hasAlpha:"<<rightPixmap.hasAlpha();
// settings
this->setWindowTitle(info->fileName() + " - ImageQt");
setActionStatus(true);
size->setText(QString::number(leftPixmapItem->pixmap().width())
+ " x " + QString::number(leftPixmapItem->pixmap().height()));
}
}
/******************************************************************************
* Clean image of both Scene
*
*****************************************************************************/
void MainWindow::on_actionClose_triggered()
{
cleanImage();
}
void MainWindow::on_actionSave_triggered()
{
}
/******************************************************************************
* Action : Save as
*****************************************************************************/
void MainWindow::on_actionSave_As_triggered()
{
QString newPath = QFileDialog::getSaveFileName(this, tr("Save image"), QString(),
tr("All files (*);;"
"Image BPM (*.bpm);;"
"Image GIF (*.gif);;"
"Image JPG (*.jpg);;"
"Image JPEG (*.jpeg);;"
"Image PNG (*.png);;"
"Image PPM (*.ppm);;"
"Image XBM (*.xbm);;"
"Image XPM (*.xpm);;"));
if (!newPath.isEmpty()) {
QFile file(newPath);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::critical(this, tr(WINDOW_CRITICAL), tr("Unable to save image."));
return;
}
//Save image to new path
rightPixmapItem->pixmap().save(newPath);
// rightImage->save(newPath);
}
}
/******************************************************************************
* Exit the program
*
*****************************************************************************/
void MainWindow::on_actionExit_triggered()
{
qApp->quit();
}
/******************************************************************************
* Greyscale
*****************************************************************************/
void MainWindow::on_actionGrayscale_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::GreyScale(rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
/******************************************************************************
* Adjust the image size to fit the window
*
*****************************************************************************/
void MainWindow::on_actionAdjust_triggered()
{
// left
int height = leftPixmapItem->pixmap().height();
int width = leftPixmapItem->pixmap().width();
int max_height = ui->leftGraphicsView->height();
int max_width = ui->leftGraphicsView->width();
int size,max_size,fact=0;
double val=0;
size = qMin(width,height);
max_size = qMin(max_width,max_height);
if (size < max_size) {
while ((size*val) < max_size)
val = pow(1.2,fact++);
val = pow(1.2,fact-2);
ui->leftGraphicsView->setFactor(fact-2);
}
else {
val = 1;
while ((size*val) > max_size)
val = pow(1.2,fact--);
val = pow(1.2,fact+1);
ui->leftGraphicsView->setFactor(fact+1);
}
ui->leftGraphicsView->scale(val,val);
// right
height = leftPixmapItem->pixmap().height();
width = leftPixmapItem->pixmap().width();
max_height = ui->rightGraphicsView->height();
max_width = ui->rightGraphicsView->width();
size = max_size = fact = 0;
val=0;
size = qMin(width,height);
max_size = qMin(max_width,max_height);
if (size < max_size) {
while ((size*val) < max_size)
val = pow(1.2,fact++);
val = pow(1.2,fact-2);
ui->rightGraphicsView->setFactor(fact-2);
}
else {
val = 1;
while ((size*val) > max_size)
val = pow(1.2,fact--);
val = pow(1.2,fact+1);
ui->rightGraphicsView->setFactor(fact+1);
}
ui->rightGraphicsView->scale(val,val);
}
/******************************************************************************
* Restore the image, both size and rotate
*****************************************************************************/
void MainWindow::on_actionRestore_triggered()
{
on_actionNormal_triggered();
}
/******************************************************************************
* 绘制图像直方图
*****************************************************************************/
void MainWindow::on_actionHistogram_triggered()
{
QDialog * hstgrmDialog = new QDialog(this);
QScrollArea * scrollArea = new QScrollArea(hstgrmDialog);
Histogram * hstgrm = new Histogram(scrollArea);
hstgrm->computeHstgrm(rightPixmapItem->pixmap().toImage());
if (hstgrm == NULL)
return;
scrollArea->setWidget(hstgrm);
QHBoxLayout * layout = new QHBoxLayout;
layout->addWidget(scrollArea);
hstgrmDialog->setLayout(layout);
hstgrm->resize(800, 780);
hstgrmDialog->setFixedWidth(820);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea->adjustSize();
hstgrmDialog->setWindowTitle("Histogram - ImageQt");
hstgrmDialog->show();
}
/******************************************************************************
* Add frame
*****************************************************************************/
void MainWindow::on_actionMovie_frame_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage frame = QImage(":/img/src/frame_3.png");
QImage newImage = Tools::DrawFrame(rightImage.toImage(), frame);
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
void MainWindow::on_actionClassic_frame_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage frame = QImage(":/img/src/frame_1.png");
QImage newImage = Tools::DrawFrame(rightImage.toImage(), frame);
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
void MainWindow::on_actionFlower_frame_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage frame = QImage(":/img/src/frame_2.png");
QImage newImage = Tools::DrawFrame(rightImage.toImage(), frame);
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
/******************************************************************************
* Add metal texture
*****************************************************************************/
void MainWindow::on_actionMetal_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::Metal(rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
/******************************************************************************
* Cool
*****************************************************************************/
void MainWindow::on_actionCool_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::Cool(30, rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
/******************************************************************************
* Warm
*****************************************************************************/
void MainWindow::on_actionWarm_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::Warm(30, rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
/******************************************************************************
* 简单平滑
*****************************************************************************/
void MainWindow::on_actionSimple_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::SimpleSmooth(rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
/******************************************************************************
* 高斯平滑
*****************************************************************************/
void MainWindow::on_actionGauss_triggered()
{
GaussianBlurDialog dialog;
connect(&dialog, SIGNAL(sendData(int, double)), this,
SLOT(receiveGaussianFactor(int, double)));
dialog.exec();
}
/******************************************************************************
* 中值滤波
*****************************************************************************/
void MainWindow::on_actionMeida_Filter_triggered()
{
bool ok;
int value = QInputDialog::getInt(this, tr("Media Filter"), "Input a value for radius(1~30)",3,1,30,1,&ok);
if (ok)
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::MeidaFilter(rightImage.toImage(), value);
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
}
/******************************************************************************
* Rotate Left
*****************************************************************************/
void MainWindow::on_actionLeft_triggered()
{
bool ok;
int factor = QInputDialog::getInt(this, tr("旋转"), "请输入要旋转的角度",0,-360,360,10,&ok);
if (ok)
{
if (factor != 0)
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage *imgRotate = new QImage;
QMatrix matrix;
matrix.rotate(factor);
*imgRotate = rightImage.toImage().transformed(matrix);
QPixmap newPixmap;
newPixmap = QPixmap::fromImage(*imgRotate);
updateRightImage(newPixmap);
}
else
{
return;
}
}
}
/******************************************************************************
* Rotate Right
*****************************************************************************/
void MainWindow::on_actionRight_triggered()
{
//ui->rightGraphicsView->rotate(90);
QPixmap rightImage = rightPixmapItem->pixmap();
QImage *imgRotate = new QImage;
QMatrix matrix;
matrix.rotate(90);
*imgRotate = rightImage.toImage().transformed(matrix);
QPixmap newPixmap;
newPixmap = QPixmap::fromImage(*imgRotate);
updateRightImage(newPixmap);
}
/******************************************************************************
* on Action tools->zoom triggered
*****************************************************************************/
void MainWindow::on_zoomAction_triggered()
{
bool ok;
int factor = QInputDialog::getInt(this, tr("Zoom"), "Input a value for zoom ratio(%)",100,10,1000,10,&ok);
if (ok)
{
if (factor != 100)
{
QPixmap rightImage = rightPixmapItem->pixmap();
int cur_width = rightImage.width();
int cur_height = rightImage.height();
QPixmap newPixmap = rightImage.scaled(cur_width*factor/100, cur_height*factor/100);
updateRightImage(newPixmap);
}
else
{
return;
}
}
}
/******************************************************************************
* Flip Horizontal
*****************************************************************************/
void MainWindow::on_actionHorizontal_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::Horizontal(rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
/******************************************************************************
* Flip Vertical
*****************************************************************************/
void MainWindow::on_actionVertical_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::Vertical(rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
/******************************************************************************
* 灰度线性变换 y = ax + b
*****************************************************************************/
void MainWindow::on_actionLinear_level_transformation_triggered()
{
LinearGrayDialog dialog;
connect(&dialog, SIGNAL(sendData(double, double)),
this, SLOT(receiveLinearGreyParameter(double,double)));
dialog.exec();
}
/******************************************************************************
* 灰度幂次变换
*****************************************************************************/
void MainWindow::on_actionPower_transformation_triggered()
{
DialogPowerGrey dialog;
connect(&dialog, SIGNAL(sendData(double, double, double)),
this, SLOT(receivePowerGreyParamter(double,double,double)));
dialog.exec();
}
/******************************************************************************
* 灰度对数变换 y = log(b+x)/log(a)
*****************************************************************************/
void MainWindow::on_actionLogarithm_grey_level_transformation_triggered()
{
DialogLogGrey dialog;
connect(&dialog, SIGNAL(sendData(double, double)),
this, SLOT(receiveLogGreyParamter(double,double)));
dialog.exec();
}
/******************************************************************************
* 灰度指数变换
*****************************************************************************/
void MainWindow::on_actionExp_transfrom_triggered()
{
DialogExpTransform dialog;
connect(&dialog, SIGNAL(sendData(double, double, double)),
this, SLOT(receiveExpGreyParamter(double,double,double)));
dialog.exec();
}
/******************************************************************************
* 灰度双阈值变换
*****************************************************************************/
void MainWindow::on_actionTwo_thresholds_transform_triggered()
{
DialogThresholdTransform dialog;
connect(&dialog, SIGNAL(sendData(int, int, int)),
this, SLOT(receiveTwoThresholdParamter(int,int,int)));
dialog.exec();
}
/******************************************************************************
* 灰度拉伸变换
*****************************************************************************/
void MainWindow::on_actionStretch_transformation_triggered()
{
DialogStretchTransform dialog;
connect(&dialog, SIGNAL(sendData(int,int,double,double,double,double,double)),
this, SLOT(receiveStretchParamter(int,int,double,double,double,double,double)));
dialog.exec();
}
/******************************************************************************
* laplace sharpen
*****************************************************************************/
void MainWindow::on_actionLaplace_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::LaplaceSharpen(rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
void MainWindow::on_actionSobel_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::SobelEdge(rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
void MainWindow::on_actionBinaryzation_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::Binaryzation(rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
/******************************************************************************
* 调整亮度
*****************************************************************************/
void MainWindow::on_actionAdjust_brightness_triggered()
{
bool ok;
int delta = QInputDialog::getInt(this,
tr("Brightness"),
"Input a value for brightness(+/-)",
0,-1000,1000,10,&ok);
if (ok)
{
if (delta != 100)
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::Brightness(delta, rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
else
{
return;
}
}
}
/******************************************************************************
* To do
*****************************************************************************/
void MainWindow::on_actionNormal_triggered()
{
QPixmap leftImage = leftPixmapItem->pixmap();
updateRightImage(leftImage);
ui->rightGraphicsView->resetTransform();
}
/******************************************************************************
* “关于”窗口
*****************************************************************************/
void MainWindow::on_actionAbout_triggered()
{
QMessageBox message(QMessageBox::NoIcon, tr(WINDOW_ABOUT), "<h1>ImageQt</h1>"
"Powered By Qt 5.7.1.");
message.setIconPixmap(QPixmap(":/img/src/logo_1.png"));
message.exec();
}
/******************************************************************************
* 语言支持
*****************************************************************************/
void MainWindow::on_actionChinese_triggered()
{
QTranslator translator;
translator.load(":/language/cn.qm");
qApp->installTranslator(&translator);
ui->retranslateUi(this);
ui->actionChinese->setEnabled(false);
ui->actionEnglish->setEnabled(true);
}
void MainWindow::on_actionEnglish_triggered()
{
QTranslator translator;
translator.load(":/language/cn.qm");
qApp->removeTranslator(&translator);
ui->retranslateUi(this);
ui->actionEnglish->setEnabled(false);
ui->actionChinese->setEnabled(true);
}
/******************************************************************************
* 获得当前用户的用户名
*****************************************************************************/
QString MainWindow::getUserName()
{
QString userPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
QString userName = userPath.section("/", -1, -1);
return userName;
}
/******************************************************************************
* 获得当前用户的家目录
*****************************************************************************/
QString MainWindow::getUserPath()
{
QString userPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
return userPath;
}
void MainWindow::on_actionT_triggered()
{
QLabel* l = new QLabel;
if (!rightPixmapItem->pixmap().isNull()) {
qDebug() << "hello";
l->setPixmap(rightPixmapItem->pixmap());
l->show();
}
}
/******************************************************************************
* Prewitt边缘检测
*****************************************************************************/
void MainWindow::on_actionPrewitt_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::PrewittEdge(rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
/******************************************************************************
* 轮廓提取法
*****************************************************************************/
void MainWindow::on_actionContour_extraction_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImage = Tools::ContourExtraction(rightImage.toImage());
rightImage.convertFromImage(newImage);
updateRightImage(rightImage);
}
void MainWindow::on_actionArea_triggered()
{
QPixmap rightImage = rightPixmapItem->pixmap();
QImage newImg = rightImage.toImage();
QImage binImg = Tools::Binaryzation(newImg);
int area = 0;
for(int x=0; x<binImg.width(); x++)
{
for(int y=0; y<binImg.height(); y++)
{
if (QColor(binImg.pixel(x,y)).red() == 0)
area ++;
}
}
QMessageBox *message =new QMessageBox(QMessageBox::NoIcon,QObject::tr("面积计算"),"连通区域的面积为:"+QString::number(area));
message->show();
}