I have HSV algorithm posted under "color detection algorithm" but i failed to locate the lips as i did by using RGB algorithm. I set the H to 0.1 but still with the same result.
My color image is in pgm format, so i didn't use ind2rgb but straight away to call colorDetectHSV(), will this be a problem?
This is the colorDetectHSV():
Code:
function I = colorDetectHSV(RGB, hsvVal, tol)
HSV = rgb2hsv(RGB);
% find the difference between required and real H value:
diffH = abs(HSV(:,:,1) - hsvVal(1));
[M,N,t] = size(RGB);
I1 = zeros(M,N); I2 = zeros(M,N); I3 = zeros(M,N);
T1 = tol(1);
I1( find(diffH < T1) ) = 1;
if (length(tol)>1)
% find the difference between required and real S value:
diffS = abs(HSV(:,:,2) - hsvVal(2));
T2 = tol(2);
I2( find(diffS < T2) ) = 1;
if (length(tol)>2)
% find the difference between required and real V value:
difV = HSV(:,:,3) - hsvVal(3);
T3 = tol(3);
I3( find(diffS < T3) ) = 1;
I = I1.*I2.*I3;
else
I = I1.*I2;
end
else
I = I1;
end
subplot(2,1,1),imshow(RGB); title('Original Image');
subplot(2,1,2),imshow(I,[]); title('Detected Areas');
This is my main program:
Code:
a = imread('m-013-1.pgm');
b = colorDetectHSV(a, [0.1 1.0 0.5], [0.5 0.5 0.5]);
The original images is in my attachment below "image.zip".
However, i failed to allocate lips which is in red color. Please help, any comment will be appreciated.
I mean nothing has changed for red even i change the first value of colorDetectHSV() for red. I mean i can't even get the mouth like what i did in RGB. It's like a mess, can't differentiate the mouth from face skin no matter how i change the parameters.
Please try with the image i attached, then you will see.
Please help. Thanks
Never mind, it is ok. I hope someone can give me a helping hand. I have studied actually. Just wondering whether there is something wrong inside the codes.
I am also not familiar with HSV and your script. Anyway from the link below, I believe that when Hue = 300 to 360 or 0 to 60, the color should be red. You may like to identify pixels that is dominantly red and check if the shape forms the lip.
Here are some formulas which translate, and draws 49 distinct colors
Code:
Option Explicit
Private Type HSL
Hue As Long
Saturation As Long
Luminance As Long
End Type
Private Function HSLToRGB(ByVal Hue As Long, ByVal Saturation As Long, ByVal Luminance As Long) As Long
Dim R As Long, G As Long, B As Long
Dim lMax As Long, lMid As Long, lMin As Long
Dim Delta As Single
lMax = (Luminance * 255) / 100
lMin = (100 - Saturation) * lMax / 100
Delta = (lMax - lMin) / 60
Select Case Hue
Case 0 To 60
lMid = (Hue - 0) * Delta + lMin
R = lMax: G = lMid: B = lMin
Case 60 To 120
lMid = -(Hue - 120) * Delta + lMin
R = lMid: G = lMax: B = lMin
Case 120 To 180
lMid = (Hue - 120) * Delta + lMin
R = lMin: G = lMax: B = lMid
Case 180 To 240
lMid = -(Hue - 240) * Delta + lMin
R = lMin: G = lMid: B = lMax
Case 240 To 300
lMid = (Hue - 240) * Delta + lMin
R = lMid: G = lMin: B = lMax
Case 300 To 360
lMid = -(Hue - 360) * Delta + lMin
R = lMax: G = lMin: B = lMid
End Select
HSLToRGB = B * &H10000 + G * &H100& + R
End Function
Private Function RGBToHSL(ByVal RGBValue As Long) As HSL
Dim R As Long, G As Long, B As Long
Dim lMax As Long, lMin As Long
Dim Delta As Single
R = RGBValue And &HFF
G = (RGBValue And &HFF00&) \ &H100&
B = (RGBValue And &HFF0000) \ &H10000
If R > G Then
lMax = R: lMin = G
Else
lMax = G: lMin = R
End If
If B > lMax Then
lMax = B
ElseIf B < lMin Then
lMin = B
End If
RGBToHSL.Luminance = lMax * 100 / 255
If lMax > lMin Then
RGBToHSL.Saturation = (lMax - lMin) * 100 / lMax
Delta = 60 / (lMax - lMin)
Select Case lMax
Case R
If B > G Then
RGBToHSL.Hue = Delta * (G - B) + 360
Else
RGBToHSL.Hue = Delta * (G - B)
End If
Case G
RGBToHSL.Hue = Delta * (B - R) + 120
Case B
RGBToHSL.Hue = Delta * (R - G) + 240
End Select
End If
End Function
Private Sub cmdGo_Click()
Dim Color As HSL
Color = RGBToHSL(Val("&H" & txtRGB.Text))
For Color.Hue = 0 To 49
Picture1(Color.Hue).BackColor = HSLToRGB(Color.Hue, Color.Saturation, Color.Luminance)
Next Color.Hue
End Sub
Sub form_load()
Dim colour As Long, red As Byte, green As Byte, blue As Byte
Dim str As String
red = 11
green = 22
blue = 33
str = "Red : " & red & vbCrLf
str = str & "Green : " & green & vbCrLf
str = str & "Blue : " & blue & vbCrLf
MsgBox str
colour = RGB(red, green, blue)
blue = (colour And &HFF0000) \ &H10000
green = (colour And &HFF00&) \ &H100&
red = colour And &HFF
str = "Red : " & red & vbCrLf
str = str & "Green : " & green & vbCrLf
str = str & "Blue : " & blue & vbCrLf
MsgBox str
txtRGB.Text = RGB(100, 100, 100) ' colour
End Sub
dglienna: Do you mean these codes can help me to extract red region as well as the lips from an image?
My original image is in RGB. If HSL can detect lips and ignore others, i am going to use it. However, i am not expert in Matlab because i use it to test algorithm before doing C. Do you mind to show me which part can do the job as mentioned?
As far as i know, RGBToHSL() can be used to convert my rgb image to hsl color space. form_load() and cmdGo_Click() i have no idea. Do you mind to allocate a few minutes to educate me on this?
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.