Repository navigation
Expand file tree
/
Copy pathhistogram_equalization.h
More file actions
441 lines (416 loc) · 21 KB
/
Copy pathhistogram_equalization.h
File metadata and controls
441 lines (416 loc) · 21 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
#pragma once
#include<iostream>
#include<cmath>
#include"read_write_bmp.h"
//直方图均衡化
bmp_file histogram_equalize(bmp_file origin_bmp)
{
int num_pixel = origin_bmp.bmp_info_header.biWidth * origin_bmp.bmp_info_header.biHeight;
int num_pixel_actual = origin_bmp.biWidth_actual * origin_bmp.bmp_info_header.biHeight;
bmp_file result_bmp;
switch (origin_bmp.bmp_info_header.biBitCount)
{
case 8: //* 8位(256色)bmp
{
//提取像素
uint8_t* pixel = new uint8_t[num_pixel_actual];
long temp_index = 0;
if (num_pixel_actual > 1) //以防pixel访问越界
for (long i = 0; i < origin_bmp.bmp_info_header.biHeight; i++)
{
for (long j = 0; j < origin_bmp.bmp_info_header.biWidth; j++)
pixel[i * origin_bmp.biWidth_actual + j] = origin_bmp.bmp_pixel8[i * origin_bmp.biWidth_actual + j];
//for (long j= origin_bmp.bmp_info_header.biWidth;j<origin_bmp.biWidth_actual;j++)
// pixel[i * origin_bmp.bmp_info_header.biWidth + j]
}
int* hist_counting = hist_0_255(pixel, origin_bmp.bmp_info_header.biWidth, origin_bmp.bmp_info_header.biHeight, origin_bmp.biWidth_actual);
uint8_t* transformation_result = new uint8_t[256];
int total_counting = 0;
//*L-1 = 256-1 = 255
for (int i = 0; i < 256; i++)
{
total_counting += hist_counting[i];
transformation_result[i] = uint8_t(round(255.0 * total_counting / num_pixel));
}
if (num_pixel_actual > 1) //以防pixel访问越界
for (long i = 0; i < origin_bmp.bmp_info_header.biHeight; i++)
for (long j = 0; j < origin_bmp.bmp_info_header.biWidth; j++)
{
temp_index = i * origin_bmp.bmp_info_header.biWidth + j;
uint8_t temp = transformation_result[pixel[temp_index]];
pixel[temp_index] = temp;
}
//结果bmp
result_bmp.bmp_file_header.bfType = origin_bmp.bmp_file_header.bfType;
result_bmp.bmp_file_header.bfReserved1 = origin_bmp.bmp_file_header.bfReserved1;
result_bmp.bmp_file_header.bfReserved2 = origin_bmp.bmp_file_header.bfReserved2;
result_bmp.bmp_file_header.bfSize = origin_bmp.bmp_file_header.bfSize;
result_bmp.bmp_file_header.bfOffBits = origin_bmp.bmp_file_header.bfOffBits;
result_bmp.bmp_info_header.biHeight = origin_bmp.bmp_info_header.biHeight;
result_bmp.bmp_info_header.biWidth = origin_bmp.bmp_info_header.biWidth;
result_bmp.bmp_info_header.biBitCount = origin_bmp.bmp_info_header.biBitCount;
result_bmp.bmp_info_header.biClrImportant = origin_bmp.bmp_info_header.biClrUsed;
result_bmp.bmp_info_header.biClrUsed = origin_bmp.bmp_info_header.biClrImportant;
result_bmp.bmp_info_header.biCompression = origin_bmp.bmp_info_header.biCompression;
result_bmp.bmp_info_header.biPlanes = origin_bmp.bmp_info_header.biPlanes;
result_bmp.bmp_info_header.biSize = origin_bmp.bmp_info_header.biSize;
result_bmp.bmp_info_header.biSizeImage = origin_bmp.bmp_info_header.biSizeImage;
result_bmp.bmp_info_header.biXPelsPerMeter = origin_bmp.bmp_info_header.biXPelsPerMeter;
result_bmp.bmp_info_header.biYPelsPerMeter = origin_bmp.bmp_info_header.biYPelsPerMeter;
result_bmp.bmp_pixel8 = pixel;
result_bmp.biWidth_actual = origin_bmp.biWidth_actual;
delete[] transformation_result;
}
break;
case 24: //* 24位(真彩色)bmp
{
//**转换到HSI域
origin_bmp.bmp_pixel24_H_double = new double[num_pixel];
origin_bmp.bmp_pixel24_S_double = new double[num_pixel];
origin_bmp.bmp_pixel24_I_double = new double[num_pixel];
memset(origin_bmp.bmp_pixel24_H_double, 0, sizeof(double) * num_pixel);
memset(origin_bmp.bmp_pixel24_S_double, 0, sizeof(double) * num_pixel);
memset(origin_bmp.bmp_pixel24_I_double, 0, sizeof(double) * num_pixel);
double temp_theta = 0.0;
double temp_R = 0.0, temp_G = 0.0, temp_B = 0.0;
double R_G_B_sum = 0.0;
double R_minus_G = 0.0, R_minus_B = 0.0, G_minus_B = 0.0;
int temp_row_index = 0, temp_index = 0;
if (num_pixel > 1) //以防访问越界
for (int i = 0; i < origin_bmp.bmp_info_header.biHeight; i++)
{
temp_row_index = i * origin_bmp.bmp_info_header.biWidth;
for (int j = 0; j < origin_bmp.bmp_info_header.biWidth; j++)
{
temp_index = temp_row_index + j;
temp_B = double(origin_bmp.bmp_pixel24_RGB[temp_index].rgbtBlue) / 255;
temp_G = double(origin_bmp.bmp_pixel24_RGB[temp_index].rgbtGreen) / 255;
temp_R = double(origin_bmp.bmp_pixel24_RGB[temp_index].rgbtRed) / 255;
R_minus_G = temp_R - temp_G;
R_minus_B = temp_R - temp_B;
G_minus_B = temp_G - temp_B;
R_G_B_sum = temp_B + temp_G + temp_R;
//***色调
temp_theta = acos(0.5 * ((R_minus_G)+(R_minus_B)) / sqrt(R_minus_G * R_minus_G + R_minus_B * G_minus_B + 1e-300)); //避免除以0
temp_theta = abs(temp_theta * 180 / pi); //弧度转换成角度
origin_bmp.bmp_pixel24_H_double[temp_index] = temp_B > temp_G ? (360.0 - temp_theta) : temp_theta;
//***饱和度
if (origin_bmp.bmp_pixel24_RGB[temp_index].rgbtBlue == 0 && origin_bmp.bmp_pixel24_RGB[temp_index].rgbtGreen == 0
&& origin_bmp.bmp_pixel24_RGB[temp_index].rgbtRed == 0) // 原R=G=B=0,即纯黑时,饱和度为0
origin_bmp.bmp_pixel24_S_double[temp_index] = 0.0;
else
origin_bmp.bmp_pixel24_S_double[temp_index] = 1.0 - 3.0 * min(min(temp_R, temp_G), temp_B) / (R_G_B_sum);
//***亮度
origin_bmp.bmp_pixel24_I_double[temp_index] = R_G_B_sum / 3;
}
}
//**对亮度直方图均衡化处理
int top = 255;
int* I_integer = new int[num_pixel];
for (int i = 0; i < num_pixel; i++)I_integer[i] = CLAMP_0_x(origin_bmp.bmp_pixel24_I_double[i] * top, top);
int* hist_counting = hist_0_x(I_integer, origin_bmp.bmp_info_header.biWidth, origin_bmp.bmp_info_header.biHeight, top);
int* transformation_result = new int[top + 1];
int total_counting = 0;
//***L-1 = 256-1 = 255 或 L-1 = top
for (int i = 0; i <= top; i++)
{
total_counting += hist_counting[i];
transformation_result[i] = (int)(double(top) * total_counting / num_pixel + 0.5);
}
if (num_pixel > 1) //以防访问越界
for (int i = 0; i < num_pixel; i++)
{
int temp = I_integer[i];
I_integer[i] = transformation_result[temp];
}
//**转换回RGB域
double* I_result = new double[num_pixel];
for (int i = 0; i < num_pixel; i++)I_result[i] = double(I_integer[i]) / top;
tagRGBTRIPLE* new_pixel24_RGB = new tagRGBTRIPLE[origin_bmp.bmp_info_header.biWidth * origin_bmp.bmp_info_header.biHeight];
double temp_H = 0.0;
if (num_pixel > 1) //以防访问越界
for (int i = 0; i < origin_bmp.bmp_info_header.biHeight; i++)
{
temp_row_index = i * origin_bmp.bmp_info_header.biWidth;
for (int j = 0; j < origin_bmp.bmp_info_header.biWidth; j++)
{
temp_index = temp_row_index + j;
temp_H = origin_bmp.bmp_pixel24_H_double[temp_index];
if (temp_H < 120)
{
temp_H = temp_H * pi / 180; // 变为弧度制以便<cmath>的cos处理
temp_B = I_result[temp_index] * (1.0 - origin_bmp.bmp_pixel24_S_double[temp_index]);
temp_R = I_result[temp_index] * (1.0 + (origin_bmp.bmp_pixel24_S_double[temp_index] * cos(temp_H) / cos(pi / 3 - temp_H)));
temp_G = 3.0 * I_result[temp_index] - (temp_R + temp_B);
new_pixel24_RGB[temp_index].rgbtBlue = CLAMP_0_255(temp_B * 255);
new_pixel24_RGB[temp_index].rgbtRed = CLAMP_0_255(temp_R * 255);
new_pixel24_RGB[temp_index].rgbtGreen = CLAMP_0_255(temp_G * 255);
}
else if (temp_H >= 120 && temp_H < 240)
{
temp_H -= 120;
temp_H = temp_H * pi / 180; // 变为弧度制以便<cmath>的cos处理
temp_R = I_result[temp_index] * (1.0 - origin_bmp.bmp_pixel24_S_double[temp_index]);
temp_G = I_result[temp_index] * (1.0 + (origin_bmp.bmp_pixel24_S_double[temp_index] * cos(temp_H) / cos(pi / 3 - temp_H)));
temp_B = 3.0 * I_result[temp_index] - (temp_R + temp_G);
new_pixel24_RGB[temp_index].rgbtBlue = CLAMP_0_255(temp_B * 255);
new_pixel24_RGB[temp_index].rgbtRed = CLAMP_0_255(temp_R * 255);
new_pixel24_RGB[temp_index].rgbtGreen = CLAMP_0_255(temp_G * 255);
}
else if (temp_H >= 240 && temp_H <= 360)
{
temp_H -= 240;
temp_H = temp_H * pi / 180; // 变为弧度制以便<cmath>的cos处理
temp_G = I_result[temp_index] * (1.0 - origin_bmp.bmp_pixel24_S_double[temp_index]);
temp_B = I_result[temp_index] * (1.0 + (origin_bmp.bmp_pixel24_S_double[temp_index] * cos(temp_H) / cos(pi / 3 - temp_H)));
temp_R = 3.0 * I_result[temp_index] - (temp_G + temp_B);
new_pixel24_RGB[temp_index].rgbtBlue = CLAMP_0_255(temp_B * 255);
new_pixel24_RGB[temp_index].rgbtRed = CLAMP_0_255(temp_R * 255);
new_pixel24_RGB[temp_index].rgbtGreen = CLAMP_0_255(temp_G * 255);
}
}
}
//**结果bmp
result_bmp.bmp_file_header.bfType = origin_bmp.bmp_file_header.bfType;
result_bmp.bmp_file_header.bfReserved1 = origin_bmp.bmp_file_header.bfReserved1;
result_bmp.bmp_file_header.bfReserved2 = origin_bmp.bmp_file_header.bfReserved2;
result_bmp.bmp_file_header.bfSize = origin_bmp.bmp_file_header.bfSize;
result_bmp.bmp_file_header.bfOffBits = origin_bmp.bmp_file_header.bfOffBits;
result_bmp.bmp_info_header.biHeight = origin_bmp.bmp_info_header.biHeight;
result_bmp.bmp_info_header.biWidth = origin_bmp.bmp_info_header.biWidth;
result_bmp.bmp_info_header.biBitCount = origin_bmp.bmp_info_header.biBitCount;
result_bmp.bmp_info_header.biClrImportant = origin_bmp.bmp_info_header.biClrUsed;
result_bmp.bmp_info_header.biClrUsed = origin_bmp.bmp_info_header.biClrImportant;
result_bmp.bmp_info_header.biCompression = origin_bmp.bmp_info_header.biCompression;
result_bmp.bmp_info_header.biPlanes = origin_bmp.bmp_info_header.biPlanes;
result_bmp.bmp_info_header.biSize = origin_bmp.bmp_info_header.biSize;
result_bmp.bmp_info_header.biSizeImage = origin_bmp.bmp_info_header.biSizeImage;
result_bmp.bmp_info_header.biXPelsPerMeter = origin_bmp.bmp_info_header.biXPelsPerMeter;
result_bmp.bmp_info_header.biYPelsPerMeter = origin_bmp.bmp_info_header.biYPelsPerMeter;
result_bmp.biWidth_actual = origin_bmp.biWidth_actual;
result_bmp.bmp_pixel24_RGB = new_pixel24_RGB;
delete[] I_integer, I_result, transformation_result;
}
break;
default:
break;
}
return result_bmp;
}
//直方图均衡化:可指定图片偏亮或偏暗
bmp_file histogram_equalize(bmp_file origin_bmp, bool dark)
{
int num_pixel = origin_bmp.bmp_info_header.biWidth * origin_bmp.bmp_info_header.biHeight;
int num_pixel_actual = origin_bmp.biWidth_actual * origin_bmp.bmp_info_header.biHeight;
bmp_file result_bmp;
switch (origin_bmp.bmp_info_header.biBitCount)
{
case 8: //* 8位(256色)bmp
{
//提取像素
uint8_t* pixel = new uint8_t[num_pixel_actual];
long temp_index = 0;
if (num_pixel_actual > 1) //以防pixel访问越界
for (long i = 0; i < origin_bmp.bmp_info_header.biHeight; i++)
{
for (long j = 0; j < origin_bmp.bmp_info_header.biWidth; j++)
pixel[i * origin_bmp.biWidth_actual + j] = origin_bmp.bmp_pixel8[i * origin_bmp.biWidth_actual + j];
//for (long j= origin_bmp.bmp_info_header.biWidth;j<origin_bmp.biWidth_actual;j++)
// pixel[i * origin_bmp.bmp_info_header.biWidth + j]
}
int* hist_counting = hist_0_255(pixel, origin_bmp.bmp_info_header.biWidth, origin_bmp.bmp_info_header.biHeight, origin_bmp.biWidth_actual);
uint8_t* transformation_result = new uint8_t[256];
int total_counting = 0;
//*L-1 = 256-1 = 255
for (int i = 0; i < 256; i++)
{
total_counting += hist_counting[i];
transformation_result[i] = uint8_t(round(255.0 * total_counting / num_pixel));
}
if (num_pixel_actual > 1) //以防pixel访问越界
for (long i = 0; i < origin_bmp.bmp_info_header.biHeight; i++)
for (long j = 0; j < origin_bmp.bmp_info_header.biWidth; j++)
{
temp_index = i * origin_bmp.bmp_info_header.biWidth + j;
uint8_t temp = transformation_result[pixel[temp_index]];
pixel[temp_index] = temp;
}
//结果bmp
result_bmp.bmp_file_header.bfType = origin_bmp.bmp_file_header.bfType;
result_bmp.bmp_file_header.bfReserved1 = origin_bmp.bmp_file_header.bfReserved1;
result_bmp.bmp_file_header.bfReserved2 = origin_bmp.bmp_file_header.bfReserved2;
result_bmp.bmp_file_header.bfSize = origin_bmp.bmp_file_header.bfSize;
result_bmp.bmp_file_header.bfOffBits = origin_bmp.bmp_file_header.bfOffBits;
result_bmp.bmp_info_header.biHeight = origin_bmp.bmp_info_header.biHeight;
result_bmp.bmp_info_header.biWidth = origin_bmp.bmp_info_header.biWidth;
result_bmp.bmp_info_header.biBitCount = origin_bmp.bmp_info_header.biBitCount;
result_bmp.bmp_info_header.biClrImportant = origin_bmp.bmp_info_header.biClrUsed;
result_bmp.bmp_info_header.biClrUsed = origin_bmp.bmp_info_header.biClrImportant;
result_bmp.bmp_info_header.biCompression = origin_bmp.bmp_info_header.biCompression;
result_bmp.bmp_info_header.biPlanes = origin_bmp.bmp_info_header.biPlanes;
result_bmp.bmp_info_header.biSize = origin_bmp.bmp_info_header.biSize;
result_bmp.bmp_info_header.biSizeImage = origin_bmp.bmp_info_header.biSizeImage;
result_bmp.bmp_info_header.biXPelsPerMeter = origin_bmp.bmp_info_header.biXPelsPerMeter;
result_bmp.bmp_info_header.biYPelsPerMeter = origin_bmp.bmp_info_header.biYPelsPerMeter;
result_bmp.bmp_pixel8 = pixel;
result_bmp.biWidth_actual = origin_bmp.biWidth_actual;
delete[] transformation_result;
}
break;
case 24: //* 24位(真彩色)bmp
{
//**转换到HSI域
origin_bmp.bmp_pixel24_H_double = new double[num_pixel];
origin_bmp.bmp_pixel24_S_double = new double[num_pixel];
origin_bmp.bmp_pixel24_I_double = new double[num_pixel];
memset(origin_bmp.bmp_pixel24_H_double, 0, sizeof(double) * num_pixel);
memset(origin_bmp.bmp_pixel24_S_double, 0, sizeof(double) * num_pixel);
memset(origin_bmp.bmp_pixel24_I_double, 0, sizeof(double) * num_pixel);
double temp_theta = 0.0;
double temp_R = 0.0, temp_G = 0.0, temp_B = 0.0;
double R_G_B_sum = 0.0;
double R_minus_G = 0.0, R_minus_B = 0.0, G_minus_B = 0.0;
int temp_row_index = 0, temp_index = 0;
if (num_pixel > 1) //以防访问越界
for (int i = 0; i < origin_bmp.bmp_info_header.biHeight; i++)
{
temp_row_index = i * origin_bmp.bmp_info_header.biWidth;
for (int j = 0; j < origin_bmp.bmp_info_header.biWidth; j++)
{
temp_index = temp_row_index + j;
temp_B = double(origin_bmp.bmp_pixel24_RGB[temp_index].rgbtBlue) / 255;
temp_G = double(origin_bmp.bmp_pixel24_RGB[temp_index].rgbtGreen) / 255;
temp_R = double(origin_bmp.bmp_pixel24_RGB[temp_index].rgbtRed) / 255;
R_minus_G = temp_R - temp_G;
R_minus_B = temp_R - temp_B;
G_minus_B = temp_G - temp_B;
R_G_B_sum = temp_B + temp_G + temp_R;
//***色调
temp_theta = acos(0.5 * ((R_minus_G)+(R_minus_B)) / sqrt(R_minus_G * R_minus_G + R_minus_B * G_minus_B + 1e-300)); //避免除以0
temp_theta = abs(temp_theta * 180 / pi); //弧度转换成角度
origin_bmp.bmp_pixel24_H_double[temp_index] = temp_B > temp_G ? (360.0 - temp_theta) : temp_theta;
//***饱和度
if (origin_bmp.bmp_pixel24_RGB[temp_index].rgbtBlue == 0 && origin_bmp.bmp_pixel24_RGB[temp_index].rgbtGreen == 0
&& origin_bmp.bmp_pixel24_RGB[temp_index].rgbtRed == 0) // 原R=G=B=0,即纯黑时,饱和度为0
origin_bmp.bmp_pixel24_S_double[temp_index] = 0.0;
else
origin_bmp.bmp_pixel24_S_double[temp_index] = 1.0 - 3.0 * min(min(temp_R, temp_G), temp_B) / (R_G_B_sum);
//***亮度
origin_bmp.bmp_pixel24_I_double[temp_index] = R_G_B_sum / 3;
}
}
//**对亮度直方图均衡化处理
int top = 255;
int* I_integer = new int[num_pixel];
for (int i = 0; i < num_pixel; i++)I_integer[i] = CLAMP_0_x(origin_bmp.bmp_pixel24_I_double[i] * top, top);
int* hist_counting = hist_0_x(I_integer, origin_bmp.bmp_info_header.biWidth, origin_bmp.bmp_info_header.biHeight, top);
int* transformation_result = new int[top + 1];
int total_counting = 0;
//***L-1 = 256-1 = 255
//***L-1 = top
for (int i = 0; i <= top; i++)
{
total_counting += hist_counting[i];
transformation_result[i] = (int)(double(top) * total_counting / num_pixel + 0.5);
}
if (num_pixel > 1) //以防访问越界
for (int i = 0; i < num_pixel; i++)
{
int temp = I_integer[i];
I_integer[i] = transformation_result[temp];
}
////**饱和度均衡化处理
if (!dark)
for (int i = 0; i < num_pixel; i++)
{
if (origin_bmp.bmp_pixel24_I_double[i] <= 0.5)
{
if (origin_bmp.bmp_pixel24_S_double[i] <= origin_bmp.bmp_pixel24_I_double[i] * 2)
origin_bmp.bmp_pixel24_S_double[i] = origin_bmp.bmp_pixel24_S_double[i] * 6;
else
origin_bmp.bmp_pixel24_S_double[i] = 0.0;
}
else
{
if (origin_bmp.bmp_pixel24_S_double[i] <= (1.0 - origin_bmp.bmp_pixel24_I_double[i]) * 2)
origin_bmp.bmp_pixel24_S_double[i] = origin_bmp.bmp_pixel24_S_double[i] * 6;
else
origin_bmp.bmp_pixel24_S_double[i] = 0.0;
}
//origin_bmp.bmp_pixel24_S_double[i] = 6 * origin_bmp.bmp_pixel24_S_double[i] * (1 - origin_bmp.bmp_pixel24_S_double[i]);
if (origin_bmp.bmp_pixel24_S_double[i] > 1)origin_bmp.bmp_pixel24_S_double[i] = 1.0;
}
//**转换回RGB域
double* I_result = new double[num_pixel];
for (int i = 0; i < num_pixel; i++)I_result[i] = double(I_integer[i]) / top;
tagRGBTRIPLE* new_pixel24_RGB = new tagRGBTRIPLE[origin_bmp.bmp_info_header.biWidth * origin_bmp.bmp_info_header.biHeight];
double temp_H = 0.0;
if (num_pixel > 1) //以防访问越界
for (int i = 0; i < origin_bmp.bmp_info_header.biHeight; i++)
{
temp_row_index = i * origin_bmp.bmp_info_header.biWidth;
for (int j = 0; j < origin_bmp.bmp_info_header.biWidth; j++)
{
temp_index = temp_row_index + j;
temp_H = origin_bmp.bmp_pixel24_H_double[temp_index];
if (temp_H < 120)
{
temp_H = temp_H * pi / 180; // 变为弧度制以便<cmath>的cos处理
temp_B = I_result[temp_index] * (1.0 - origin_bmp.bmp_pixel24_S_double[temp_index]);
temp_R = I_result[temp_index] * (1.0 + (origin_bmp.bmp_pixel24_S_double[temp_index] * cos(temp_H) / cos(pi / 3 - temp_H)));
temp_G = 3.0 * I_result[temp_index] - (temp_R + temp_B);
new_pixel24_RGB[temp_index].rgbtBlue = CLAMP_0_255(temp_B * 255);
new_pixel24_RGB[temp_index].rgbtRed = CLAMP_0_255(temp_R * 255);
new_pixel24_RGB[temp_index].rgbtGreen = CLAMP_0_255(temp_G * 255);
}
else if (temp_H >= 120 && temp_H < 240)
{
temp_H -= 120;
temp_H = temp_H * pi / 180; // 变为弧度制以便<cmath>的cos处理
temp_R = I_result[temp_index] * (1.0 - origin_bmp.bmp_pixel24_S_double[temp_index]);
temp_G = I_result[temp_index] * (1.0 + (origin_bmp.bmp_pixel24_S_double[temp_index] * cos(temp_H) / cos(pi / 3 - temp_H)));
temp_B = 3.0 * I_result[temp_index] - (temp_R + temp_G);
new_pixel24_RGB[temp_index].rgbtBlue = CLAMP_0_255(temp_B * 255);
new_pixel24_RGB[temp_index].rgbtRed = CLAMP_0_255(temp_R * 255);
new_pixel24_RGB[temp_index].rgbtGreen = CLAMP_0_255(temp_G * 255);
}
else if (temp_H >= 240 && temp_H <= 360)
{
temp_H -= 240;
temp_H = temp_H * pi / 180; // 变为弧度制以便<cmath>的cos处理
temp_G = I_result[temp_index] * (1.0 - origin_bmp.bmp_pixel24_S_double[temp_index]);
temp_B = I_result[temp_index] * (1.0 + (origin_bmp.bmp_pixel24_S_double[temp_index] * cos(temp_H) / cos(pi / 3 - temp_H)));
temp_R = 3.0 * I_result[temp_index] - (temp_G + temp_B);
new_pixel24_RGB[temp_index].rgbtBlue = CLAMP_0_255(temp_B * 255);
new_pixel24_RGB[temp_index].rgbtRed = CLAMP_0_255(temp_R * 255);
new_pixel24_RGB[temp_index].rgbtGreen = CLAMP_0_255(temp_G * 255);
}
}
}
//**结果bmp
result_bmp.bmp_file_header.bfType = origin_bmp.bmp_file_header.bfType;
result_bmp.bmp_file_header.bfReserved1 = origin_bmp.bmp_file_header.bfReserved1;
result_bmp.bmp_file_header.bfReserved2 = origin_bmp.bmp_file_header.bfReserved2;
result_bmp.bmp_file_header.bfSize = origin_bmp.bmp_file_header.bfSize;
result_bmp.bmp_file_header.bfOffBits = origin_bmp.bmp_file_header.bfOffBits;
result_bmp.bmp_info_header.biHeight = origin_bmp.bmp_info_header.biHeight;
result_bmp.bmp_info_header.biWidth = origin_bmp.bmp_info_header.biWidth;
result_bmp.bmp_info_header.biBitCount = origin_bmp.bmp_info_header.biBitCount;
result_bmp.bmp_info_header.biClrImportant = origin_bmp.bmp_info_header.biClrUsed;
result_bmp.bmp_info_header.biClrUsed = origin_bmp.bmp_info_header.biClrImportant;
result_bmp.bmp_info_header.biCompression = origin_bmp.bmp_info_header.biCompression;
result_bmp.bmp_info_header.biPlanes = origin_bmp.bmp_info_header.biPlanes;
result_bmp.bmp_info_header.biSize = origin_bmp.bmp_info_header.biSize;
result_bmp.bmp_info_header.biSizeImage = origin_bmp.bmp_info_header.biSizeImage;
result_bmp.bmp_info_header.biXPelsPerMeter = origin_bmp.bmp_info_header.biXPelsPerMeter;
result_bmp.bmp_info_header.biYPelsPerMeter = origin_bmp.bmp_info_header.biYPelsPerMeter;
result_bmp.biWidth_actual = origin_bmp.biWidth_actual;
result_bmp.bmp_pixel24_RGB = new_pixel24_RGB;
delete[] I_integer, I_result, transformation_result;
}
break;
default:
break;
}
return result_bmp;
}