Skip to content

Instantly share code, notes, and snippets.

@edtechd
Created December 1, 2017 14:06
Show Gist options
  • Save edtechd/277924b425f46d24be4f1988860e15f0 to your computer and use it in GitHub Desktop.
Save edtechd/277924b425f46d24be4f1988860e15f0 to your computer and use it in GitHub Desktop.
private void savebutton_Click(object sender, EventArgs e)
{
string template = File.ReadAllText("template.txt");
template = template.Replace("{n}", (layerNum.Maximum+1).ToString());
template = template.Replace("{zstart}", "0");
template = template.Replace("{zend}", Convert.ToString((layerNum.Maximum+1)/*/ 5.0*/));
byte[] predata = GetBytes(template);
// в поток fs будет записываться результат
FileStream fs = new System.IO.FileStream(settings.output, System.IO.FileMode.Create,
System.IO.FileAccess.Write);
// поток чтобы записать маркеры для сегментации методом водораздела из файла
FileStream fsmarkers = new System.IO.FileStream(settings.markers, System.IO.FileMode.Create,
System.IO.FileAccess.Write);
// записываем заголовок файла
fs.Write(predata,0,predata.Length);
// WRITE SEGMENTATION DATA
for (int k = 0; k <= layerNum.Maximum; k++)
{
byte[] markersdata = new byte[markersa[k].ImageSize];
Marshal.Copy(markersa[k].ImageData, markersdata, 0, markersdata.Length);
fsmarkers.Write(markersdata, 0, markersdata.Length);
IplImage markers2 = markersa[k].Clone();
// вызывается OpenCV метод сегментации Watershed
sources[k].Watershed(markers2);
int length = markers2.Width * markers2.Height;
byte[] data = new byte[length];
int n = markers2.Height;
// копирование данных из OpenCV в обычный двумерный массив
for (int i = 0; i < markers2.Height; i++)
for (int j = 0; j < markers2.Width; j++)
{
byte d = (byte)markers2.Get2D(i, j);
switch (d)
{
case 1:
data[i * n + j] = 0;
break;
case 30:
data[i * n + j] = 1;
break;
case 90:
data[i * n + j] = 2;
break;
default:
data[i * n + j] = 0;
break;
}
}
// сохраняем двоичные данные в файл
fs.Write(data, 0, data.Length);
}
/////
fs.Close();
fsmarkers.Close();
MessageBox.Show("OK");
}
# AmiraMesh BINARY-LITTLE-ENDIAN 2.1
define Lattice 600 600 {n}
Parameters {
Materials {
Exterior {
Name "Exterior"
}
Dent {
Id 2,
Color 0.184314 0.309804 0.309804
}
}
ImageData "RESHETNYAK-MARIYA-KIRILLOVNA3",
Content "600x600x{n} byte, uniform coordinates",
BoundingBox 0 119.8 0 119.8 {zstart} {zend},
CoordType "uniform"
}
Lattice { byte Labels } @1
# Data section follows
@1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment