如何使用NiBabel(Python)预处理NIfTI数据格式

时间:2019-03-05 19:37:45

标签: python machine-learning computer-vision neuroscience nibabel

在使用NiBabel将NIfTI文件转换为数组后,该数组具有三个维度,数字看起来像这样:

[-9.35506855e-42 -1.78675141e-35  1.18329136e-30 -1.58892995e-24
5.25227377e-24  1.11677966e-23 -2.41237451e-24 -1.51333104e-25
6.79829196e-30 -9.84047188e-36  1.23314265e-43 -0.00000000e+00]

如何对该数组进行预处理以进行机器学习?如果仅选择指数,则在绘制图像时大多数信息会丢失,因此底数也许也很重要?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

这将帮助您将niftiimage转换为numpy数组:

func getData() {
    // Making a reference
    let transactionRef = Database.database().reference(withPath: "transactions")
    transactionRef.observeSingleEvent(of: .value, with: { (snapshot) in

        // Printing the child count
        print("There are \(snapshot.childrenCount) children found")    

        // Checking if the reference has some values
        if snapshot.childrenCount > 0 {

            // Go through every child
            for data in snapshot.children.allObjects as! [DataSnapshot] {
                if let data = data.value as? [String: Any] {

                    // Retrieve the data per child


                    // Example
                    let name = data["name"] as? String
                    let age = data["age"] as? Int

                    // Print the values for each child or do whatever you want
                    print("Name: \(name)\nAge: \(age)")
                }
            }
        }
    })
}