### Author Topic: need help with mean and standard deviation  (Read 15053 times)

#### guga

• Moderator
• Member
• Posts: 1344
• Assembly is a state of art.
##### need help with mean and standard deviation
« on: October 22, 2013, 09:51:05 AM »
Hi guys, i need help understanding how to build a formula for mean and standard deviations for Lab colorspace

I´m trying to build a color transfer algorithm, but i didn´t understood the formulas neither how o create them.

The document i´m reading to build the formula is this
« Last Edit: October 22, 2013, 01:21:39 PM by guga »
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

#### dedndave

• Member
• Posts: 8827
• Still using Abacus 2.0
##### Re: need help with mean and standard derivation
« Reply #1 on: October 22, 2013, 12:36:51 PM »
i have downloaded the PDF - let me see if i can understand it - lol

#### guga

• Moderator
• Member
• Posts: 1344
• Assembly is a state of art.
##### Re: need help with mean and standard deviation
« Reply #2 on: October 22, 2013, 02:24:52 PM »
Tks dedndave

For the regular mean and standard deviations, i succeed to make. The problem is with this weight variable, covariance and Q attributes. I´m not being able to understand how to code them, because i don´t know how to analyse those mathematical formulas

For getting the regular standard deviation, i succedded making this:

Code: [Select]
`[CieLabVariance: CieLabVariance.Light: R\$ 0 CieLabVariance.aFactor: R\$ 0 CieLabVariance.bFactor: R\$ 0 CieLabVariance.KFactor: R\$ 0][CieLabMean: CieLabMean.Light: R\$ 0 CieLabMean.aFactor: R\$ 0 CieLabMean.bFactor: R\$ 0 CieLabMean.KFactor: R\$ 0][CieLabStdDev: CieLabStdDev.Light: R\$ 0 CieLabStdDev.aFactor: R\$ 0 CieLabStdDev.bFactor: R\$ 0 CieLabStdDev.KFactor: R\$ 0]Proc GetCieLabStandardDeviation:    Arguments @pColorData, @ImgWidth, @ImgHeight    call CieLabGetMean D@pColorData, D@ImgWidth, D@ImgHeight, CieLabMean    call CieLabGetVariance D@pColorData, CieLabMean, D@ImgWidth, D@ImgHeight    finit    fld R\$CieLabVariance.Light | fsqrt | fstp R\$CieLabStdDev.Light    fld R\$CieLabVariance.aFactor | fsqrt | fstp R\$CieLabStdDev.aFactor    fld R\$CieLabVariance.bFactor | fsqrt | fstp R\$CieLabStdDev.bFactor    ;fld R\$CieLabVariance.KFactor | fsqrt | fstp R\$StdDev.KFactor <------ weight ??????EndP`
Code: [Select]
`Proc CieLabGetMean:    Arguments @pColorData, @ImgWidth, @ImgHeight, @pCieLabMeanStr    Local @iCounter, @Red, @Green, @Blue, @Y, @MaxCount, @MyPixelSrc, @MaxCount2    Structure @TempStorage 44, @HueDis 0, @SaturationDis 8, @LightDis 16, @LumaDis 24, @aFactorDis 32, @bFactorDis 40    Uses eax, ebx, ecx, esi, edi, edx    mov D@iCounter 0    mov D@MaxCount2 0    mov ebx D@ImgWidth    imul ebx D@ImgHeight    mov D@MaxCount ebx    finit    mov esi D@pColorData    .While D@iCounter < ebx        lea ebx D@Red | movzx edi B\$esi+RGBTRIPLE.rgbtRedDis | mov D\$ebx edi        lea edx D@Green | movzx edi B\$esi+RGBTRIPLE.rgbtGreenDis | mov D\$edx edi        lea ecx D@Blue | movzx edi B\$esi+RGBTRIPLE.rgbtBlueDis | mov D\$ecx edi        lea edi D@MyPixelSrc | mov D\$edi 0        mov eax D@Red | mov B\$edi+ARGB.RedDis al        mov eax D@Green | mov B\$edi+ARGB.GreenDis al        mov eax D@Blue | mov B\$edi+ARGB.BlueDis al        lea ebx D@HueDis | mov D\$ebx 0 | mov D\$ebx+4 0        lea edx D@SaturationDis | mov D\$edx 0 | mov D\$edx+4 0        lea ecx D@LightDis | mov D\$ecx 0 | mov D\$ecx+4 0        call RGBtoHSL edi, ebx, edx, ecx        ...If eax <> 0 ; do not compute gray color            lea ebx D@LumaDis | mov D\$ebx 0 | mov D\$ebx+4 0            lea edx D@aFactorDis | mov D\$edx 0 | mov D\$edx+4 0            lea ecx D@bFactorDis | mov D\$ecx 0 | mov D\$ecx+4 0            call RGBtoCieLab D@Red, D@Green, D@Blue, ebx, edx, ecx            fld R\$CieLabMean.Light | fadd R\$ebx | fstp R\$CieLabMean.Light            fld R\$CieLabMean.aFactor | fadd R\$edx | fstp R\$CieLabMean.aFactor            fld R\$CieLabMean.bFactor | fadd R\$ecx | fstp R\$CieLabMean.bFactor            ;fld R\$CieLabMean.bFactor | fdiv R\$CieLabMean.aFactor | fadd R\$CieLabMean.KFactor | fstp R\$CieLabMean.KFactor            inc D@MaxCount2        ...End_If        add esi 3        inc D@iCounter        mov ebx D@MaxCount    .End_While    fld R\$CieLabMean.Light | fidiv F@MaxCount2 | fstp R\$CieLabMean.Light    fld R\$CieLabMean.aFactor | fidiv F@MaxCount2 | fstp R\$CieLabMean.aFactor    fld R\$CieLabMean.bFactor | fidiv F@MaxCount2 | fstp R\$CieLabMean.bFactor   ; fld R\$CieLabMean.KFactor | fidiv F@MaxCount2 | fstp R\$CieLabMean.KFactorEndP`
Code: [Select]
`Proc CieLabGetVariance:    Arguments @pColorData, @pMean, @ImgWidth, @ImgHeight    Local @iCounter, @Red, @Green, @Blue, @Y, @MaxCount, @MyPixelSrc, @MaxCount2    Structure @TempStorage 44, @HueDis 0, @SaturationDis 8, @LightDis 16, @LumaDis 24, @aFactorDis 32, @bFactorDis 40    Uses eax, ebx, ecx, esi, edi, edx    finit    mov D@iCounter 0    mov D@MaxCount2 0    mov ebx D@ImgWidth    imul ebx D@ImgHeight    mov D@MaxCount ebx    mov esi D@pColorData    .While D@iCounter < ebx        lea ebx D@Red | movzx edi B\$esi+RGBTRIPLE.rgbtRedDis | mov D\$ebx edi        lea edx D@Green | movzx edi B\$esi+RGBTRIPLE.rgbtGreenDis | mov D\$edx edi        lea ecx D@Blue | movzx edi B\$esi+RGBTRIPLE.rgbtBlueDis | mov D\$ecx edi        lea edi D@MyPixelSrc | mov D\$edi 0        mov eax D@Red | mov B\$edi+ARGB.RedDis al        mov eax D@Green | mov B\$edi+ARGB.GreenDis al        mov eax D@Blue | mov B\$edi+ARGB.BlueDis al        lea ebx D@HueDis | mov D\$ebx 0 | mov D\$ebx+4 0        lea edx D@SaturationDis | mov D\$edx 0 | mov D\$edx+4 0        lea ecx D@LightDis | mov D\$ecx 0 | mov D\$ecx+4 0        call RGBtoHSL edi, ebx, edx, ecx        ...If eax <> 0 ; do not compute gray color            lea ebx D@LumaDis | mov D\$ebx 0 | mov D\$ebx+4 0            lea edx D@aFactorDis | mov D\$edx 0 | mov D\$edx+4 0            lea ecx D@bFactorDis | mov D\$ecx 0 | mov D\$ecx+4 0            call RGBtoCieLab D@Red, D@Green, D@Blue, ebx, edx, ecx            fld R\$CieLabMean.Light | fsub R\$ebx | fabs | fmul ST0 | fadd R\$CieLabVariance.Light | fstp R\$CieLabVariance.Light            fld R\$CieLabMean.aFactor | fsub R\$edx | fabs | fmul ST0 | fadd R\$CieLabVariance.aFactor | fstp R\$CieLabVariance.aFactor            fld R\$CieLabMean.bFactor | fsub R\$ecx | fabs | fmul ST0 | fadd R\$CieLabVariance.bFactor | fstp R\$CieLabVariance.bFactor            ;fdiv R\$Variance.Saturation | fld R\$Mean.KFactor | fsub ST1 | fabs | fmul ST0 | fadd R\$Variance.KFactor | fstp R\$Variance.KFactor            inc D@MaxCount2        ...End_If        add esi 3        inc D@iCounter        mov ebx D@MaxCount    .End_While    fld R\$CieLabVariance.Light | fidiv F@MaxCount2 | fstp R\$CieLabVariance.Light    fld R\$CieLabVariance.aFactor | fidiv F@MaxCount2 | fstp R\$CieLabVariance.aFactor    fld R\$CieLabVariance.bFactor | fidiv F@MaxCount2 | fstp R\$CieLabVariance.bFactorEndP`
The GetCieLabStandardDeviation does not compute gray values. I´ll later make this as a variable and also make another variable to work with colors schemes different then D65, observer 2, such as D55, D50, observer 10 etc.

For now, i´m just testing the standard deviation and see how to implement it as the ones in the pdf with the weight and other variables.

Note: a few variables names are incorrect, cause i didn´t had time to fix that yet. Since i was trying to make it work the std dev i let some variables there even if they are unused.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

#### jj2007

• Member
• Posts: 10644
• Assembler is fun ;-)
##### Re: need help with mean and standard deviation
« Reply #3 on: October 22, 2013, 04:22:03 PM »
If it gets really mathematical, you can check with either GSL or YEPPP!...

#### dedndave

• Member
• Posts: 8827
• Still using Abacus 2.0
##### Re: need help with mean and standard deviation
« Reply #4 on: October 22, 2013, 08:23:06 PM »
the RosAsm syntax looks a bit strange   :P

#### guga

• Moderator
• Member
• Posts: 1344
• Assembly is a state of art.
##### Re: need help with mean and standard deviation
« Reply #5 on: October 22, 2013, 08:28:19 PM »
If you found out how, try port to masm and will try to assemble it .

I´m currently trying to fix a RGBtoCielab/CieLabtoRGB functions, because it seems that there are some inconsistencies in those colorspaces.

I suceeded to convert the color spaces with http://www.easyrgb.com/index.php?X=MATH&H=01#text1, but....the resultant image losts quality due o gamma error i suppose. I´ll see later what is going on after i try this other code below:

http://www.bastijn.nl/archives/153

About the syntax....mainly this is the macro set i use.
The B\$ = byte ptr
D\$ = dword ptr
W\$ word ptr
@ = local variable

while/end_while macros same as in masm
If/..If...same as in masm

[CieLabStdDev:
CieLabStdDev.Light: R\$ 0
CieLabStdDev.aFactor: R\$ 0
CieLabStdDev.bFactor: R\$ 0
CieLabStdDev.KFactor: R\$ 0]

Global structure where each member has 8 bytes (Fpu Real)
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

#### guga

• Moderator
• Member
• Posts: 1344
• Assembly is a state of art.
##### Re: need help with mean and standard deviation
« Reply #6 on: October 22, 2013, 09:17:08 PM »
Here are some preliminary results from both algos of RBGtoCielab

From easyRGB site

From www.bastijn.nl site

Although bastin site looks way better....I just converted half of the function. I had no time to finish the CieLabtoRGB of it, so i used the one in EasyRGB. On this image it was ok, but on several others, there are showing artifacts and gamma errors (shows red, green, yellow, orange pixels)

I´ll fully convert it tonight an see what is the result.

If i suceed to convert it, then i can use the standard deviation etc, once dedndave suceed to translate it.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

#### FORTRANS

• Member
• Posts: 1078
##### Re: need help with mean and standard deviation
« Reply #7 on: October 22, 2013, 11:48:49 PM »
Hi,

Following that link gets me to an *.EXE, not a *.PDF.  Is

I have a book that mentions the L-a-b (or L*a*b*) color
coordinate system, but just gives a formula for the coord-
inate transformation and a description.

Regards,

Steve

#### dedndave

• Member
• Posts: 8827
• Still using Abacus 2.0
##### Re: need help with mean and standard deviation
« Reply #8 on: October 23, 2013, 12:04:56 AM »
hi Steve
and when you find the right one - you have to sign in to get it

maybe Christian Graus can help with the colors...
this is part 6 of a 6-part series
http://www.codeproject.com/Articles/7138/Image-Processing-for-Dummies-with-C-and-GDI-Part-6
his other articles are listed here
http://www.codeproject.com/Articles/Christian-Graus#articles

#### guga

• Moderator
• Member
• Posts: 1344
• Assembly is a state of art.
##### Re: need help with mean and standard deviation
« Reply #9 on: October 23, 2013, 12:07:55 AM »
Hi Steve

a exe ? Are u sure ? The link is in my 1st post

it is in 4shared here

It is a rar file that inside contains the pdf

The formula is what i´m trying to understand. I suceeded to convert some color functions on the easyrgb site,  but this last one from them is too slow and also innacurate. I`m trying to convert the 2nd example. The results so far are somewhat similar to a IPT colorspace, except that they don´t show so much details when the image is too dark.

What i´m trying to understand and create is the formulas described in the chapter

3. AUTOMATIC SELECTIVE COLOR TRANSFER ALGORITHM FOR IMAGES
3.1 New mean and standard deviation values of ASCT algorithm

page 2 of the pdf i uploaded

These formulas:

I don´t know what they means so i can try to code them.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

#### qWord

• Member
• Posts: 1476
• The base type of a type is the type itself
##### Re: need help with mean and standard deviation
« Reply #10 on: October 23, 2013, 12:11:53 AM »
guga,
dedndave,

did you have the rights to share that paper?
MREAL macros - when you need floating point arithmetic while assembling!

#### guga

• Moderator
• Member
• Posts: 1344
• Assembly is a state of art.
##### Re: need help with mean and standard deviation
« Reply #11 on: October 23, 2013, 12:14:46 AM »
It is not from a book or something.

Btw...the article is not commercial. As far i remember it is a study from students from a university related to color transfer techniques.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

#### qWord

• Member
• Posts: 1476
• The base type of a type is the type itself
##### Re: need help with mean and standard deviation
« Reply #12 on: October 23, 2013, 12:21:35 AM »
Quote
Permission to make digital or hard copies of all or part of this work for
personal or classroom use is granted without fee provided that copies are
copies bear this notice and the full citation on the first page. To copy
otherwise, or republish, to post on servers or to redistribute to lists,
requires prior specific permission and/or a fee.
SAC’11, March 21-25, 2011, TaiChung, Taiwan.
MREAL macros - when you need floating point arithmetic while assembling!

#### guga

• Moderator
• Member
• Posts: 1344
• Assembly is a state of art.
##### Re: need help with mean and standard deviation
« Reply #13 on: October 23, 2013, 12:46:15 AM »
Yeah, like i said, it is for free as long you don´t use for commercial purposes. But the copy or post the whole pages (or the book, that contains this article) requires permission.

The article is at page 66, therefore it is not the whole "book" and neither for commercial purposes, so using a few pages (6) for study and educational is granted.

This is related to the whole book that seems to be released articles from several people on a symposium.

What is not allowed is copy the whole book of this Symposhium and share it. But isolated articles for study and educational purposes this is ok.

I´m not sure if this Yao-Hsien Huang is the same guy that send me trough email his app that is able to unblur images that will be releases on Adobe CS, but definitelly, reproducing and article for this purposes and situation is legal.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

#### qWord

• Member
• Posts: 1476
• The base type of a type is the type itself
##### Re: need help with mean and standard deviation
« Reply #14 on: October 23, 2013, 01:13:51 AM »
Your argumentation makes not much sense, because the Article can be download from the ACM digital library (copyright holder) for 10\$ (15\$ for non members). Educational (or private) purposes implies that the paper is only shared within the study group and not the WWW.