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