我有一组原始像素数据.我想将其转换为8bpp Bitmap.
public static Bitmap ByteToGrayBitmap(byte[] rawBytes, int width, int height)
{
Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height),
ImageLockMode.WriteOnly, bitmap.PixelFormat);
Marshal.Copy(rawBytes, 0, bitmapData .Scan0, rawBytes.Length);
bitmap.UnlockBits(bitmapData);
return bitmap;
}
Run Code Online (Sandbox Code Playgroud)
位图看起来像彩色图像而不是灰度.
我有以下代码,我从目录中读取图像并使用ImageJ Auto Threshold插件来分割我的图像.
dir = getDirectory("path");
list = getFileList(dir);
for (i=0; i<list.length; i++)
{
if (endsWith(list[i], ".tif"))
{
open(dir + list[i]);
run("8-bit");
run("Gaussian Blur...", "sigma=2");
setAutoThreshold("Otsu dark");
run("Convert to Mask");
saveAs("TIFF", dir+list[i]);
close();
}
}
Run Code Online (Sandbox Code Playgroud)
我想使用"Otsu dark"方法获取阈值,并修改该值(例如,将其缩放一个因子)并将其应用于我的图像以进行分割.