-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimagepro.cpp
More file actions
769 lines (708 loc) · 21.2 KB
/
Copy pathimagepro.cpp
File metadata and controls
769 lines (708 loc) · 21.2 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
#include "imagepro.h"
#include <QFile>
#include <QDebug>
#include <QVector2D>
#include <QtMath>
#include <algorithm>
#include <cstring>
ImagePro::ImagePro(QObject *parent) : QObject(parent)
{
}
bool ImagePro::setPic(QString &filename)
{
if(filename.isEmpty())
{
return false;
}
QImage *newSrc = new QImage(filename);
if(newSrc->isNull())
{
delete newSrc;
return false;
}
// 转换为ARGB32格式以提高处理性能
if(newSrc->format() != QImage::Format_ARGB32)
{
*newSrc = newSrc->convertToFormat(QImage::Format_ARGB32);
}
if(src != nullptr)
{
delete src;
}
src = newSrc;
if(dst != nullptr)
{
delete dst;
}
dst = new QImage(*src);
qDebug() << "Image loaded:" << src->width() << "x" << src->height();
emit showSrc(src);
return true;
}
QImage *ImagePro::doProcess(Task t,bool flag,int value)
{
switch (t)
{
case GRAY:
toGray();
break;
case BINARY:
toBinary(value);
break;
case HISTOGRAM:
calHistogram();
break;
case HISTOGRAM_EQUAL:
his_equal();
break;
case GAUSSIAN_BLUR:
gaussian_blur();
break;
case H_SHARPEN:
h_sharpen();
break;
case V_SHARPEN:
v_sharpen();
break;
case SOBEL:
sobel(flag);
break;
case DUAL_SHARPEN:
dual_sharpen();
break;
case MED_FILTER:
med_filter();
break;
case SQUARE_MASK:
square_mask();
break;
case FOURIER:
fourier();
break;
case INV_FOURIER:
inv_fourier();
break;
case EROSION:
erosion();
break;
case DILATION:
dilation();
break;
}
return dst;
}
ImagePro::~ImagePro()
{
if(src)
delete src;
if(dst)
delete dst;
if(histo)
delete[] histo;
qDebug() << "~ImageProc";
}
QImage* ImagePro::toGray()
{
qDebug() << "to Gray";
//灰度处理:平均值法
if(src == nullptr || src->isNull())
return nullptr;
if(dst->size() != src->size() || dst->format() != src->format())
{
*dst = QImage(src->size(), src->format());
}
for(int row = 0; row < src->height(); ++row)
{
const QRgb *srcLine = reinterpret_cast<const QRgb*>(src->constScanLine(row));
QRgb *dstLine = reinterpret_cast<QRgb*>(dst->scanLine(row));
for(int col = 0; col < src->width(); ++col)
{
QRgb pixel = srcLine[col];
int gray = (qRed(pixel) + qGreen(pixel) + qBlue(pixel)) / 3;
dstLine[col] = qRgb(gray, gray, gray);
}
}
emit showDst(dst);
return dst;
}
QImage* ImagePro::toBinary(int threshold)
{
if(src == nullptr || src->isNull())
return nullptr;
if(dst->size() != src->size() || dst->format() != src->format())
{
*dst = QImage(src->size(), src->format());
}
for(int row = 0; row < src->height(); ++row)
{
const QRgb *srcLine = reinterpret_cast<const QRgb*>(src->constScanLine(row));
QRgb *dstLine = reinterpret_cast<QRgb*>(dst->scanLine(row));
for(int col = 0; col < src->width(); ++col)
{
QRgb pixel = srcLine[col];
int gray = (qRed(pixel) + qGreen(pixel) + qBlue(pixel)) / 3;
QRgb binaryColor = (gray > threshold) ? qRgb(255, 255, 255) : qRgb(0, 0, 0);
dstLine[col] = binaryColor;
}
}
emit showDst(dst);
return dst;
}
QImage *ImagePro::gaussian_blur()
{
/*采用7*7的高斯模板进行卷积*/
static const int TEMPLATE_SIZE = 7;
static const double gaussianTemplate[TEMPLATE_SIZE][TEMPLATE_SIZE] =
{
{0.00000067, 0.00002292, 0.00019117, 0.00038771, 0.00019117, 0.00002292, 0.00000067},
{0.00002292, 0.00078633, 0.00655965, 0.01330373, 0.00655965, 0.00078633, 0.00002292},
{0.00019117, 0.00655965, 0.05472157, 0.11098164, 0.05472157, 0.00655965, 0.00019117},
{0.00038771, 0.01330373, 0.11098164, 0.22508352, 0.11098164, 0.01330373, 0.00038771},
{0.00019117, 0.00655965, 0.05472157, 0.11098164, 0.05472157, 0.00655965, 0.00019117},
{0.00002292, 0.00078633, 0.00655965, 0.01330373, 0.00655965, 0.00078633, 0.00002292},
{0.00000067, 0.00002292, 0.00019117, 0.00038771, 0.00019117, 0.00002292, 0.00000067}
};
if(src == nullptr || src->isNull())
return nullptr;
if(dst->size() != src->size() || dst->format() != src->format())
{
*dst = QImage(src->size(), src->format());
}
int width = src->width();
int height = src->height();
int halfSize = TEMPLATE_SIZE / 2;
for(int row = halfSize; row < height - halfSize; ++row)
{
for(int col = halfSize; col < width - halfSize; ++col)
{
double t_red = 0.0;
double t_green = 0.0;
double t_blue = 0.0;
for(int i = 0; i < TEMPLATE_SIZE; ++i)
{
for(int j = 0; j < TEMPLATE_SIZE; ++j)
{
int srcCol = col + j - halfSize;
int srcRow = row + i - halfSize;
QRgb rgb = src->pixel(srcCol, srcRow);
double weight = gaussianTemplate[i][j];
t_red += weight * qRed(rgb);
t_green += weight * qGreen(rgb);
t_blue += weight * qBlue(rgb);
}
}
dst->setPixel(col, row, qRgb(qBound(0, static_cast<int>(t_red), 255),
qBound(0, static_cast<int>(t_green), 255),
qBound(0, static_cast<int>(t_blue), 255)));
}
}
emit showDst(dst);
return dst;
}
QImage* ImagePro::h_sharpen()
{
/***********************************
* 水平边缘检测:
* g(x,y)=|f(x,y) - f(x-1,y)|
* 相当于模板[-1,1]
************************************/
if(src == nullptr)
return nullptr;
int width = src->width();
int height = src->height();
QRgb rgb;
QImage temp(*dst);
toGray();
temp.fill(QColor(255,255,255));
for(int row=1;row<height;row++)
{
for(int col=1;col<width;col++)
{
rgb = qAbs(dst->pixel(col,row) - dst->pixel(col-1,row));
temp.setPixel(col,row,rgb);
}
}
*dst = temp.copy(temp.rect());
emit showDst(dst);
return dst;
}
QImage* ImagePro::v_sharpen()
{
/***********************************
* 垂直边缘检测:
* g(x,y)=|f(x,y) - f(x,y-1)|
* 相当于模板[-1
* ,1]
************************************/
if(src == nullptr)
return nullptr;
int width = src->width();
int height = src->height();
QRgb rgb;
QImage temp(*dst);
toGray();
temp.fill(QColor(255,255,255));
for(int row=1;row<height;row++)
{
for(int col=1;col<width;col++)
{
rgb = qAbs(dst->pixel(col,row) - dst->pixel(col,row-1));
temp.setPixel(col,row,rgb);
}
}
*dst = temp.copy(temp.rect());
emit showDst(dst);
return dst;
}
QImage* ImagePro::dual_sharpen()
{
/***********************************
* 双向边缘检测:
* 利用最简单的算子[-1,1]计算梯度
* 梯度:G(x,y)=sqt[(f(x,y) - f(x-1,y))^2 + (f(x,y) - f(x,y-1))^2]
* 注意:目标图像保存的是图片的变化率,也就是梯度
************************************/
if(src == nullptr)
return nullptr;
int width = src->width();
int height = src->height();
QImage temp(*dst);
toGray();
temp.fill(QColor(255,255,255));
for(int row=1;row<height;row++)
{
for(int col=1;col<width;col++)
{
int delta_x = qRed(dst->pixel(col,row)) - qRed(dst->pixel(col-1,row));
int delta_y = qRed(dst->pixel(col,row)) - qRed(dst->pixel(col,row-1));
int delta = qCeil(qSqrt(delta_x*delta_x+delta_y*delta_y));
delta = qBound(0,delta,255);
temp.setPixelColor(col,row,QColor(delta,delta,delta));
}
}
*dst = temp.copy(temp.rect());
emit showDst(dst);
return dst;
}
QImage* ImagePro::sobel(bool enhanced)
{
/*******************************
* [-1,0,1] [-1,-2,-1]
* x=[-2,0,1] y=[ 0, 0, 0]
* [-1,0,1] [ 1, 2, 1]
*
* 梯度:G(x,y) = sqrt(x^2+y^2)
*
* 注意:目标图像保存的是图片的变化率,也就是梯度
*******************************/
//bool enhanced = false; //针对原图还是灰度图
static const int X_TEMPLATE_SIZE = 3;
static const int Y_TEMPLATE_SIZE = 3;
static int sobel_x[X_TEMPLATE_SIZE][X_TEMPLATE_SIZE] =
{
{-1,-2,-1},
{ 0, 0, 0},
{ 1, 2, 1}
};
static int sobel_y[Y_TEMPLATE_SIZE][Y_TEMPLATE_SIZE] =
{
{-1, 0, 1},
{-2, 0, 2},
{-1, 0, 1}
};
if(src == nullptr)
return nullptr;
int width = src->width();
int height = src->height();
QImage temp(*dst);
toGray();
if(!enhanced)
temp.fill(QColor(0,0,0));
for(int row=X_TEMPLATE_SIZE/2;row<height;row++)
{
for(int col=Y_TEMPLATE_SIZE/2;col<width;col++)
{
int delta_x = 0;
int delta_y = 0;
//X方向卷积计算
for(int i=0;i<X_TEMPLATE_SIZE;i++)
{
for(int j=0;j<Y_TEMPLATE_SIZE;j++)
{
if(((col+j-X_TEMPLATE_SIZE/2)>=width) || ((row+i-Y_TEMPLATE_SIZE/2) >= height))
{
continue;
}
delta_x += qRed(src->pixel(col+j-X_TEMPLATE_SIZE/2,row+i-Y_TEMPLATE_SIZE/2)) * sobel_x[i][j];
delta_y += qRed(src->pixel(col+j-X_TEMPLATE_SIZE/2,row+i-Y_TEMPLATE_SIZE/2)) * sobel_y[i][j];
}
}
int delta = qCeil(qSqrt(delta_x*delta_x+delta_y*delta_y));
delta = qBound(0,delta,255);
if(enhanced)
{
if(delta > 100)
{
QRgb rgb = temp.pixel(col,row);
int red = qRed(rgb) + 100;
int green = qGreen(rgb) + 100;
int blue = qBlue(rgb) + 100;
temp.setPixelColor(col,row,qRgb(red,green,blue));
}
}
else
{
temp.setPixelColor(col,row,QColor(delta,delta,delta));
}
}
}
*dst = temp.copy(temp.rect());
emit showDst(dst);
return dst;
}
double* ImagePro::calHistogram()
{
if(src == nullptr || src->isNull())
return nullptr;
toGray();
if(histo == nullptr)
histo = new double[256];
memset(histo, 0, 256 * sizeof(double));
// 使用scanLine提高性能
for(int row = 0; row < dst->height(); ++row)
{
const QRgb *line = reinterpret_cast<const QRgb*>(dst->constScanLine(row));
for(int col = 0; col < dst->width(); ++col)
{
int gray = qRed(line[col]);
if(gray >= 0 && gray < 256)
{
histo[gray]++;
}
}
}
double max = 0;
double min = 0;
for(int i = 0; i < 256; ++i)
{
if(histo[i] > max)
max = histo[i];
if(histo[i] < min)
min = histo[i];
}
// 归一化
double range = max - min;
if(range > 0.0001) // 避免除零
{
for(int i = 0; i < 256; ++i)
{
histo[i] = (histo[i] - min) / range;
if(histo[i] < 0.001)
{
histo[i] = 0.0;
}
}
}
return histo;
}
double *ImagePro::his_equal()
{
if(src == nullptr || src->isNull())
return nullptr;
toGray();
if(histo == nullptr)
histo = new double[256];
memset(histo, 0, 256 * sizeof(double));
/************************
算法步骤:
1.先计算每个像素灰度出现的概率(灰度直方图)
2.计算累积概率(累积直方图)
3.灰度级(255)乘以累积概率,得出灰度值
4.按照映射表改变源像素的灰度值
*************************/
// [1] 计算灰度直方图
int size = dst->height() * dst->width();
if(size == 0)
return nullptr;
for(int row = 0; row < dst->height(); ++row)
{
const QRgb *line = reinterpret_cast<const QRgb*>(dst->constScanLine(row));
for(int col = 0; col < dst->width(); ++col)
{
int gray = qRed(line[col]);
if(gray >= 0 && gray < 256)
{
histo[gray]++;
}
}
}
// 归一化为概率
for(int i = 0; i < 256; ++i)
{
histo[i] = histo[i] / size;
if(histo[i] < 0)
{
histo[i] = 0.0;
}
}
// [2] 计算累积分布函数(CDF)
double cdf[256] = {0};
cdf[0] = histo[0];
for(int i = 1; i < 256; ++i)
{
cdf[i] = histo[i] + cdf[i-1];
}
// [3] 创建灰度映射表
int gray_table_equal[256] = {0};
for(int i = 0; i < 256; ++i)
{
gray_table_equal[i] = qBound(0, static_cast<int>(255 * cdf[i]), 255);
}
// [4] 应用映射表
for(int row = 0; row < dst->height(); ++row)
{
QRgb *line = reinterpret_cast<QRgb*>(dst->scanLine(row));
for(int col = 0; col < dst->width(); ++col)
{
int oldGray = qRed(line[col]);
int newGray = gray_table_equal[oldGray];
line[col] = qRgb(newGray, newGray, newGray);
}
}
emit showDst(dst);
// 重新计算归一化直方图用于显示
memset(histo, 0, 256 * sizeof(double));
for(int row = 0; row < dst->height(); ++row)
{
const QRgb *line = reinterpret_cast<const QRgb*>(dst->constScanLine(row));
for(int col = 0; col < dst->width(); ++col)
{
int gray = qRed(line[col]);
if(gray >= 0 && gray < 256)
{
histo[gray]++;
}
}
}
for(int i = 0; i < 256; ++i)
{
histo[i] = (histo[i] / size) * 100; // 归一化为百分比
if(histo[i] < 0.001)
{
histo[i] = 0.0;
}
}
return histo;
}
QImage* ImagePro::med_filter()
{
/***********************
* 取目标像素的八邻域排序, *
* 取中间值替代目标像素 *
************************/
if(src == nullptr)
return nullptr;
int width = src->width();
int height = src->height();
int TEMPLATE_SIZE = 3;
int mid = TEMPLATE_SIZE * TEMPLATE_SIZE / 2;
int total_num = TEMPLATE_SIZE * TEMPLATE_SIZE;
QRgb num9_temp[9] = {0};
for(int row=TEMPLATE_SIZE/2;row<height;row++)
{
for(int col=TEMPLATE_SIZE/2;col<width;col++)
{
int numsize = 0;
for(int i=0;i<TEMPLATE_SIZE;i++)
{
for(int j=0;j<TEMPLATE_SIZE;j++)
{
if(((col+j-TEMPLATE_SIZE/2)>=width) || ((row+i-TEMPLATE_SIZE/2) >= height))
{
continue;
}
num9_temp[numsize++] = src->pixel(col+j-TEMPLATE_SIZE/2,row+i-TEMPLATE_SIZE/2);
std::sort(num9_temp,num9_temp+total_num);//排序
}
}
dst->setPixel(col,row,num9_temp[mid]);//取中间值
}
}
emit showDst(dst);
return dst;
}
QImage* ImagePro::square_mask()
{
//用平均值将图片马赛克化
if(src == nullptr)
return nullptr;
int width = src->width();
int height = src->height();
int TEMPLATE_SIZE = 9; //以9*9的模板马赛克化
int total_num = TEMPLATE_SIZE * TEMPLATE_SIZE;
for(int row=TEMPLATE_SIZE/2;row<height;row+=TEMPLATE_SIZE/2)
{
for(int col=TEMPLATE_SIZE/2;col<width;col+=TEMPLATE_SIZE/2)
{
int totalBlue = 0;
int totalGreen = 0;
int totalRed = 0;
for(int i=0;i<TEMPLATE_SIZE;i++)
{
for(int j=0;j<TEMPLATE_SIZE;j++)
{
if(((col+j-TEMPLATE_SIZE/2)>=width) || ((row+i-TEMPLATE_SIZE/2) >= height))
{
continue;
}
QRgb rgb = src->pixel(col+j-TEMPLATE_SIZE/2,row+i-TEMPLATE_SIZE/2);
totalRed += qRed(rgb);
totalBlue += qBlue(rgb);
totalGreen += qGreen(rgb);
}
}
QRgb average = qRgb(totalRed/total_num,totalGreen/total_num,totalBlue/total_num);
for(int i=0;i<TEMPLATE_SIZE;i++)
{
for(int j=0;j<TEMPLATE_SIZE;j++)
{
if(((col+j-TEMPLATE_SIZE/2)>=width) || ((row+i-TEMPLATE_SIZE/2) >= height))
{
continue;
}
dst->setPixel(col+j-TEMPLATE_SIZE/2,row+i-TEMPLATE_SIZE/2,average);
}
}
}
}
emit showDst(dst);
return dst;
}
void ImagePro::fourier()
{
FourierTransform ft(this,src);
ft.dft(src,dst);
emit showDst(dst);
}
void ImagePro::inv_fourier()
{
// 逆傅里叶变换:先进行傅里叶变换,然后进行逆变换恢复原图
if(src == nullptr || src->isNull())
return;
FourierTransform ft(this, src);
// 先进行傅里叶变换(计算频域数据)
ft.dft(src, dst);
// 然后进行逆傅里叶变换(恢复空间域图像)
ft.inv_dft(dst);
emit showDst(dst);
}
void ImagePro::swap()
{
if(src != nullptr)
{
*src = dst->copy(dst->rect());
emit showSrc(src);
}
}
QImage* ImagePro::erosion()
{
/************************
* 形态学腐蚀操作
* 使用3x3结构元素
* 对于二值图像,如果结构元素覆盖的所有像素都是前景(255),则输出为前景
************************/
if(src == nullptr || src->isNull())
return nullptr;
// 如果图像不是二值图像,先进行二值化
if(dst->format() != src->format() || dst->size() != src->size())
{
*dst = QImage(*src);
}
// 先转换为灰度图,然后二值化
toGray();
toBinary(128); // 使用默认阈值进行二值化
int width = dst->width();
int height = dst->height();
QImage temp(*dst);
static const int STRUCTURE_SIZE = 3;
int halfSize = STRUCTURE_SIZE / 2;
for(int row = halfSize; row < height - halfSize; ++row)
{
for(int col = halfSize; col < width - halfSize; ++col)
{
bool allWhite = true;
// 检查结构元素覆盖的所有像素
for(int i = -halfSize; i <= halfSize; ++i)
{
for(int j = -halfSize; j <= halfSize; ++j)
{
QRgb pixel = dst->pixel(col + j, row + i);
int gray = qRed(pixel);
if(gray < 128) // 如果是黑色像素
{
allWhite = false;
break;
}
}
if(!allWhite) break;
}
// 如果所有像素都是白色,输出白色,否则输出黑色
QRgb result = allWhite ? qRgb(255, 255, 255) : qRgb(0, 0, 0);
temp.setPixel(col, row, result);
}
}
*dst = temp;
emit showDst(dst);
return dst;
}
QImage* ImagePro::dilation()
{
/************************
* 形态学膨胀操作
* 使用3x3结构元素
* 对于二值图像,如果结构元素覆盖的像素中有任何一个前景(255),则输出为前景
************************/
if(src == nullptr || src->isNull())
return nullptr;
// 如果图像不是二值图像,先进行二值化
if(dst->format() != src->format() || dst->size() != src->size())
{
*dst = QImage(*src);
}
// 先转换为灰度图,然后二值化
toGray();
toBinary(128); // 使用默认阈值进行二值化
int width = dst->width();
int height = dst->height();
QImage temp(*dst);
static const int STRUCTURE_SIZE = 3;
int halfSize = STRUCTURE_SIZE / 2;
for(int row = halfSize; row < height - halfSize; ++row)
{
for(int col = halfSize; col < width - halfSize; ++col)
{
bool hasWhite = false;
// 检查结构元素覆盖的所有像素
for(int i = -halfSize; i <= halfSize; ++i)
{
for(int j = -halfSize; j <= halfSize; ++j)
{
QRgb pixel = dst->pixel(col + j, row + i);
int gray = qRed(pixel);
if(gray >= 128) // 如果有白色像素
{
hasWhite = true;
break;
}
}
if(hasWhite) break;
}
// 如果有白色像素,输出白色,否则输出黑色
QRgb result = hasWhite ? qRgb(255, 255, 255) : qRgb(0, 0, 0);
temp.setPixel(col, row, result);
}
}
*dst = temp;
emit showDst(dst);
return dst;
}