News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

need help with mean and standard deviation

Started by guga, October 22, 2013, 09:51:05 AM

Previous topic - Next topic

guga

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
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

i have downloaded the PDF - let me see if i can understand it - lol

guga

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:


[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



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.KFactor

EndP



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.bFactor

EndP


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

If it gets really mathematical, you can check with either GSL or YEPPP!...

dedndave

the RosAsm syntax looks a bit strange   :P

guga

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

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

Hi,

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

   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

hi Steve
well - the 4shared page has about 20 download buttons on it - lol
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

Hi Steve

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

it is in 4shared here
http://search.4shared.com/postDownload/sVGa3s3X/p66-huang.html

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

guga,
dedndave,

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

guga

Nope, this article is on internet, but, it is not mine. The article was released by the authors on some color related websites for free.
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

QuotePermission 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
not made or distributed for profit or commercial advantage and that
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.
Copyright 2011 ACM 978-1-4503-0113-8/11/03...$10.00
MREAL macros - when you need floating point arithmetic while assembling!

guga

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.

Look at google and you will see this article in hundreds of universities sites with links etc
https://www.google.com.br/search?q=Copyright+2011+ACM+978-1-4503-0113-8/11/03%E2%80%A6%2410.00.&ie=utf-8&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&gws_rd=cr&ei=7YBmUtPZNsOrkQeqsYHABA#psj=1&q=ACM+978-1-4503-0113-8%2F11%2F03&rls=org.mozilla:en-US%3Aofficial&safe=off

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

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.
Your google result only shows references to that paper.

You might ask Hutch what he thinks on that or simply type out the formulas and correctly quote the text!
MREAL macros - when you need floating point arithmetic while assembling!