линейное растяжение по каналам red2_imadjust imadjust pic2 green2_imad

 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
% линейное растяжение по каналам
red2_imadjust = imadjust(pic2(:,:,1));
green2_imadjust = imadjust(pic2(:,:,2));
blue2_imadjust = imadjust(pic2(:,:,3));
pic22_ch_imadjust = cat(3, red2_imadjust, green2_imadjust, blue2_imadjust);
imshow(pic22_ch_imadjust)
%GrayWorld
pic222 = double(pic2)./256;
g2 = pic222(:,:,2);
r2 = pic222(:,:,1);
b2 = pic222(:,:,3);
avgR = mean(mean(r2));
avgG = mean(mean(g2));
avgB = mean(mean(b2));
avgGray = (avgR + avgG + avgB)/3;
if avgR == 0
outR = r2;
else
outR = (avgGray/avgR).*r2;
end
if avgG == 0
outG = g2;
else
outG = (avgGray/avgG).*g2;
end
if avgB == 0
outB = b2;
else
outB = (avgGray/avgG).*b2;
end
maxRGB = [max(max(outR)) max(max(outG)) max(max(outG))];
factor = max(maxRGB);
if factor > 1
outR = outR./factor;
outG = outG./factor;
outB = outB./factor;
end
GWpic2 = cat(3, outR, outG, outB);
figure, imshow (GWpic2)
GWpic2_uint = uint8(round(GWpic2*255)); % перевод из double в uint
new2_pic2 = cat(2, pic2, GWpic2_uint); %состыкованное исходное изображение и "серый мир"