public AddModelByDepthMap ( |
||
image | ||
origin | Point3D | |
xVec | Vector3D | |
yVec | Vector3D | |
zVec | Vector3D | |
xSize | double | |
ySize | double | |
zSize | double | |
whiteIsBackground | bool | |
return | void |
public void AddModelByDepthMap(Bitmap image, Point3D origin, Vector3D xVec, Vector3D yVec, Vector3D zVec, double xSize, double ySize, double zSize,
bool whiteIsBackground = true)
{
xVec.Normalize();
yVec.Normalize();
zVec.Normalize();
Func<int, int, Point3D> getPoint = ((x, y) =>
{
Color color = image.GetPixel(x, y);
int depth = (whiteIsBackground ? color.R + color.G + color.B : 765 - (color.R + color.G + color.B));
if (depth != 765)
return origin + xVec * xSize * x / (image.Width - 1) + yVec * ySize * y / (image.Height - 1) + zVec * zSize * depth / 765;
else
return null;
});
for (int x = 0; x < image.Width - 1; x++)
for (int y = 0; y < image.Height - 1; y++)
{
Point3D p1 = getPoint(x, y), p2 = getPoint(x + 1, y), p3 = getPoint(x, y + 1), p4 = getPoint(x + 1, y + 1);
if (p1 != null && p2 != null && p3 != null)
AddPolygon(new Point3D[] { p1, p2, p3 });
if (p2 != null && p3 != null && p4 != null)
AddPolygon(new Point3D[] { p2, p3, p4 });
if (p2 == null && p1 != null && p3 != null && p4 != null)
AddPolygon(new Point3D[] { p1, p3, p4 });
if (p3 == null && p1 != null && p2 != null && p4 != null)
AddPolygon(new Point3D[] { p1, p2, p4 });
}
}
private static void CreateWavesWithImage() { var asb = new AutoStereogramBuilder(1024, 768, 3); asb.AddSphere(-0.2, -0.2, 1.6, 0.025); asb.AddSphere(-0.2, -0.2, 1.4, 0.025); asb.AddSurface(WavesSurfaceFunc, 2.3, 1.7); Bitmap bitmap = (Bitmap)Image.FromFile(GetPathAtAssemblyLocation("input\\hi.png")); asb.AddModelByDepthMap(bitmap, new Point3D { X = 0.1, Y = -0.3, Z = 1.8 }, new Vector3D { X = 1, Y = 0.5, Z = -1 }, new Vector3D { X = -0.5, Y = 1, Z = -1 }, new Vector3D { X = 1, Y = 1, Z = 1 }, 0.8, 0.8, 0.05); Bitmap backgroundImage = (Bitmap)Image.FromFile(GetPathAtAssemblyLocation("input\\background.jpg")); asb.GenerateBitmap(backgroundImage).Save(GetPathAtAssemblyLocation("output\\hello.jpg"), ImageFormat.Jpeg); }