【发布时间】:2017-05-02 16:56:47
【问题描述】:
如何在 C# 中使用 32 位浮点图像?
我更喜欢使用 openExr 但是,tiff 或类似的也可以,基本上我只想从磁盘加载一个 32 位浮点 (每像素/通道 32 位) 图像并获取像素单个通道的值并将其放入数组中,最好是尽可能简单的解决方案。
Download visual studio project
代码:C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
using System.IO;
namespace ImgToVxlForm
{
public partial class Form1 : Form
{
Bitmap myBitmap;
Byte[] byteArr;
public Form1()
{
InitializeComponent();
}
private void browseBtn_Click(object sender, EventArgs e)
{
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = "Open Image";
dlg.Filter = "png files (*.png)|*.png";
if (dlg.ShowDialog() == DialogResult.OK)
{
myBitmap = new Bitmap(dlg.FileName);
pictureBox1.Image = myBitmap;
}
}
}
private void runBtn_Click(object sender, EventArgs e)
{
byteArr = (ImageToArr(myBitmap));
for (int i = 0; i < byteArr.Length; i++)
{
// Debug.WriteLine(byteArr[i]);
}
lb_debug.Text = byteArr.Length.ToString();
}
public static byte[] ImageToArr(Bitmap inBitmap)
{
int w = inBitmap.Width;
int h = inBitmap.Height;
Byte[] tmpByteArr = new byte[w * h];
int count = 0;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
Color pixelColor = inBitmap.GetPixel(x, y);
tmpByteArr[count] = pixelColor.R;
count++;
}
}
return tmpByteArr;
}
}
}
【问题讨论】:
-
那么你包含的代码是什么?不行吗?
-
我的代码适用于 8 位图像(当前为 png),但我想使用 32 位浮点图像,如 tiff 或 openExr
-
查找 DICOM 的代码示例。例如JPEG2000等图片支持HDR 12 bit+灰度
-
另外,"...获取单个通道的像素值..." - 我认为您不了解高动态范围 (HDR) “32 位浮点” 图像。你不只是得到一个像素颜色。单个文件代表多种曝光,因此获取像素颜色将是您的 窗口级别 的一项功能。你不能只是
inBitmap.GetPixel(x,y) -
嗯,认为你是不了解 HDR 32 位浮动图像的人......如果你用摄影制作 HDR 图像,你会合并多次曝光,32 位浮动图像只是每个通道的 32 位浮动值,一个 8 位 0-255 将是 0.0-1.0 浮点数,你可以有负数和远远超出的值,问题是我已经用 MaxScript .Net 编写了应用程序,它支持 getPixels(x,y) 32bit开箱即用浮动 OpenEXR,我只是想将该应用程序转换为独立的 C# 应用程序。
标签: c# .net image winforms hdr