F#通过结构

问题描述 投票:0回答:1

我已经创建了一个结构。在循环中,我用这种类型的元素填充数组。我如何通过这个数组,并获得元素的总和?

type LAB = 
    struct 
        val L:float
        val A:float
        val B: float
        new (l:float,a:float,b:float) = {L= l; A =a; B=b}
    end

let RGBtoLAB(map: Bitmap) =
    let m1 = matrix [[ 0.3811; 0.5783; 0.0402 ]
                     [ 0.1967; 0.7244; 0.0782 ]
                     [ 0.0241; 0.1288; 0.8444 ]]

    let m2 = matrix [[ 0.5774; 0.5774; 0.5774 ]
                     [ 0.4082; 0.4082; -0.8164 ]
                     [ 0.7071; -0.7071; 0.0 ]]

    let lab = Array2D.zeroCreate map.Width map.Height
    for i=0 to map.Width-1 do
        for j=0 to map.Height-1 do
            let R = checkColor(map.GetPixel(i,j).R)
            let G = checkColor(map.GetPixel(i,j).G)
            let B = checkColor(map.GetPixel(i,j).B)
            let v = vector [R;G;B]
            let lms = m1*v
            let lmsLog = lms |> Vector.map (fun c -> Math.Log10(c))
            lab.[i,j] <- LAB((m2*lmsLog).Item(0),(m2*lmsLog).Item(1),(m2*lmsLog).Item(2))
    lab

谢谢你的回答

arrays loops f# structure
1个回答
0
投票

使用Array2D to Array的解决方案将Array2D转换为序列,然后按照描述使用Seq.fold

© www.soinside.com 2019 - 2024. All rights reserved.