-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectiveRed.m
42 lines (28 loc) · 914 Bytes
/
selectiveRed.m
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
img = imread('image.jpg');
img_hsv = rgb2hsv(img);
red_hue_threshold = 30 / 360;
saturation_weight = 0.5;
brightness_weight = 0.5;
[rows, cols, ~] = size(img);
for row = 1:rows
for col = 1:cols
H = img_hsv(row, col, 1);
S = img_hsv(row, col, 2);
V = img_hsv(row, col, 3);
hue_range = red_hue_threshold * (1 - S * saturation_weight) * (1 - V * brightness_weight);
if (H <= red_hue_threshold + hue_range) || (H >= 1 - red_hue_threshold - hue_range)
img_hsv(row, col, 2) = 1;
img_hsv(row, col, 3) = 1;
else
img_hsv(row, col, 2) = 0;
end
end
end
img_processed = hsv2rgb(img_hsv);
figure;
subplot(1, 2, 1);
imshow(img);
title('Original Image');
subplot(1, 2, 2);
imshow(img_processed);
title('Processed Image');