148 {
149 string met = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
150 "<OME xmlns=\"http://www.openmicroscopy.org/Schemas/OME/2016-06\" " +
151 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
152 "xsi:schemaLocation=\"http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd\">";
153 int c = Image.RGBChannelsCount;
154 string endian = Image.LittleEndian.ToString().ToLower();
155 int ib = 0;
156 foreach (Level l in Levels)
157 {
158 met +=
159 "<Image ID=\"Image:" + ib + "\">" +
160 "<Pixels BigEndian=\"" + endian + "\" DimensionOrder= \"XYCZT\" ID= \"Pixels:0\" Interleaved=\"true\" " +
161 "PhysicalSizeX=\"" + PhysicalX + "\" PhysicalSizeXUnit=\"µm\" PhysicalSizeY=\"" + PhysicalY + "\" PhysicalSizeYUnit=\"µm\" SignificantBits=\"" + Image.BitsPerPixel + "\" " +
162 "SizeC = \"" + c + "\" SizeT = \"" + 1 + "\" SizeX =\"" + Image.Width +
163 "\" SizeY= \"" + Image.Height + "\" SizeZ=\"" + 1;
164 if (Image.BitsPerPixel > 8) met += "\" Type= \"uint16\">";
165 else met += "\" Type= \"uint8\">";
166 int i = 0;
167 foreach (Channel ch in l.Channels)
168 {
169 met += "<Channel ID=\"Channel:" + ib + ":" + i + "\" SamplesPerPixel=\"1\"></Channel>";
170 i++;
171 }
172 met += "</Pixels></Image>";
173 ib++;
174 }
175 met += "</OME>";
176 int li = 0;
177 foreach (Level l in Levels)
178 {
179 string fs = file.Replace(".ome.tif", "");
180 NetVips.Image im = NetVips.Image.NewFromFile(fs + "-" + li + "ome.tif");
181 using var mutated = im.Mutate(mutable =>
182 {
183
184 mutable.Set(GValue.GStrType, "image-description", met);
185 mutable.Set(GValue.GIntType, "page-height", l.Height * l.PhysicalY);
186 });
187 if (l.Image.BitsPerPixel > 8)
188 mutated.Tiffsave(file, Compression, 1, Enums.ForeignTiffPredictor.None, true, (int)l.WidthPx, (int)l.HeightPx, true, false, 16,
189 Enums.ForeignTiffResunit.Cm, 1000 * l.PhysicalX, 1000 * l.PhysicalY, true, null, Enums.RegionShrink.Nearest,
190 CompressionLevel, true, Enums.ForeignDzDepth.One, true, false, null, null, (int)l.HeightPx);
191 else
192 mutated.Tiffsave(file, Compression, 1, Enums.ForeignTiffPredictor.None, true, (int)l.WidthPx, (int)l.HeightPx, true, false, 8,
193 Enums.ForeignTiffResunit.Cm, 1000 * l.PhysicalX, 1000 * l.PhysicalY, true, null, Enums.RegionShrink.Nearest,
194 CompressionLevel, true, Enums.ForeignDzDepth.One, true, false, null, null, (int)l.HeightPx);
195 li++;
196 }
197 }