1128 {
1130 data = File.ReadAllBytes(path);
1131 size = data.Length;
1132 if (getByte(0) != 73 || getByte(1) != 111)
1133 throw new IOException("This is not an ImageJ ROI");
1135 int type = getByte(
TYPE);
1136 int subtype = getShort(
SUBTYPE);
1137 int top = getShort(
TOP);
1138 int left = getShort(
LEFT);
1139 int bottom = getShort(
BOTTOM);
1140 int right = getShort(
RIGHT);
1141 int width = right - left;
1142 int height = bottom - top;
1144 if (n == 0)
1146 int options = getShort(
OPTIONS);
1149 int channel = 0, slice = 0, frame = 0;
1150 int overlayLabelColor = 0;
1151 int overlayFontSize = 0;
1152 int group = 0;
1153 int imageOpacity = 0;
1154 int imageSize = 0;
1156 bool drawOffset = subPixelResolution && (options &
DRAW_OFFSET) != 0;
1157 bool scaleStrokeWidth = true;
1158 if (version >= 228)
1160
1161 bool subPixelRect = version >= 223 && subPixelResolution && (type == rect || type == oval);
1162 double xd = 0.0, yd = 0.0, widthd = 0.0, heightd = 0.0;
1163 if (subPixelRect)
1164 {
1167 widthd = getFloat(
WIDTHD);
1169 roi.subPixel = true;
1170 }
1171
1172 if (hdr2Offset > 0 && hdr2Offset +
IMAGE_SIZE + 4 <= size)
1173 {
1181 group = getByte(hdr2Offset +
GROUP);
1182 }
1183
1184 if (name != null && name.EndsWith(".roi"))
1185 name = name.Substring(0, name.Length - 4);
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212 switch (type)
1213 {
1214 case 1:
1215 if (subPixelRect)
1216 roi =
ROI.
CreateRectangle(
new AForge.ZCT(slice - 1, channel - 1, frame - 1), xd, yd, widthd, heightd);
1217 else
1218 roi =
ROI.
CreateRectangle(
new AForge.ZCT(slice - 1, channel - 1, frame - 1), left, top, width, height);
1220 if (arcSize > 0)
1221 throw new NotSupportedException("Type rounded rectangle not supported.");
1222 break;
1223 case 2:
1224 if (subPixelRect)
1225 roi =
ROI.
CreateEllipse(
new AForge.ZCT(slice - 1, channel - 1, frame - 1), xd, yd, widthd, heightd);
1226 else
1227 roi =
ROI.
CreateEllipse(
new AForge.ZCT(slice - 1, channel - 1, frame - 1), left, top, width, height);
1228 break;
1229 case 3:
1230 float x1 = getFloat(
X1);
1231 float y1 = getFloat(
Y1);
1232 float x2 = getFloat(
X2);
1233 float y2 = getFloat(
Y2);
1234
1235 if (subtype ==
ARROW)
1236 {
1237 throw new NotSupportedException("Type arrow not supported.");
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249 }
1250 else
1251 {
1252 roi =
ROI.
CreateLine(
new AForge.ZCT(slice, channel, frame),
new AForge.PointD(x1, y1),
new AForge.PointD(x2, y2));
1253
1254 }
1255
1256 break;
1257 case 0:
1258 case 5:
1259 case 6:
1260 case 7:
1261 case 8:
1262 case 9:
1263 case 10:
1264
1265
1266
1267 if (n == 0 || n < 0) break;
1268 int[] x = new int[n];
1269 int[] y = new int[n];
1270 float[] xf = null;
1271 float[] yf = null;
1273 int base2 = base1 + 2 * n;
1274 int xtmp, ytmp;
1275 for (int i = 0; i < n; i++)
1276 {
1277 xtmp = getShort(base1 + i * 2);
1278 if (xtmp < 0) xtmp = 0;
1279 ytmp = getShort(base2 + i * 2);
1280 if (ytmp < 0) ytmp = 0;
1281 x[i] = left + xtmp;
1282 y[i] = top + ytmp;
1283 }
1284 if (subPixelResolution)
1285 {
1286 xf = new float[n];
1287 yf = new float[n];
1289 base2 = base1 + 4 * n;
1290 for (int i = 0; i < n; i++)
1291 {
1292 xf[i] = getFloat(base1 + i * 4);
1293 yf[i] = getFloat(base2 + i * 4);
1294 }
1295 }
1296 if (type == point)
1297 {
1298
1299 if (subPixelResolution)
1300 {
1302 }
1303 else
1305 if (version >= 226)
1306 {
1307
1309 }
1310
1311
1312
1313
1315 break;
1316 }
1317 if (type == polygon)
1319 else if (type == freehand)
1320 {
1323 {
1324 throw new NotSupportedException("ROI type not supported.");
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337 }
1338 }
1339 else if (type == traced)
1341 else if (type == polyline)
1343 else if (type == freeline)
1345 else if (type == angle)
1347 else
1349 if (subPixelResolution)
1350 {
1352
1353
1354 }
1355 else
1357 break;
1358 default:
1359 throw new IOException("Unrecognized ROI type: " + type);
1360 }
1361 if (roi == null)
1362 return null;
1363 roi.roiName = getRoiName();
1364
1365
1366 if (version >= 218)
1367 {
1368 getStrokeWidthAndColor(roi, hdr2Offset, scaleStrokeWidth);
1369
1370
1371
1372
1373
1374
1375
1376 }
1377
1378 if (version >= 218 && subtype ==
TEXT)
1379 {
1380 getTextRoi(roi, version);
1382 }
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402 if (version >= 228 && group > 0)
1403 roi.serie = group;
1404
1405 roi.coord.Z = position;
1406 if (channel > 0 || slice > 0 || frame > 0)
1407 roi.coord = new AForge.ZCT(slice - 1, channel - 1, frame - 1);
1408
1409
1410
1412 {
1413 for (
int i = 0; i < roi.
Points.Count; i++)
1414 {
1418 }
1419 }
1421 roi.closed = true;
1422 return roi;
1423 }
PointD ToStageSpace(PointD p)
Definition Bio.cs:3686
static int X2
Definition Fiji.cs:1032
static int COORDINATES
Definition Fiji.cs:1052
static int HEADER2_OFFSET
Definition Fiji.cs:1051
static int TEXT
Definition Fiji.cs:1070
static int ROTATED_RECT
Definition Fiji.cs:1074
static int C_POSITION
Definition Fiji.cs:1054
static int WIDTHD
Definition Fiji.cs:1036
static int ARROW
Definition Fiji.cs:1071
static int HEIGHTD
Definition Fiji.cs:1037
static int RIGHT
Definition Fiji.cs:1028
static int BOTTOM
Definition Fiji.cs:1027
static int SUBTYPE
Definition Fiji.cs:1043
static int T_POSITION
Definition Fiji.cs:1056
static int VERSION_OFFSET
Definition Fiji.cs:1023
static int N_COORDINATES
Definition Fiji.cs:1029
static int ROUNDED_RECT_ARC_SIZE
Definition Fiji.cs:1049
static int STROKE_WIDTH
Definition Fiji.cs:1039
static int ELLIPSE
Definition Fiji.cs:1072
static int OVERLAY_FONT_SIZE
Definition Fiji.cs:1060
static int SUB_PIXEL_RESOLUTION
Definition Fiji.cs:1084
static int Y2
Definition Fiji.cs:1033
static int DRAW_OFFSET
Definition Fiji.cs:1085
static int GROUP
Definition Fiji.cs:1061
static int TYPE
Definition Fiji.cs:1024
static int TOP
Definition Fiji.cs:1025
static int POSITION
Definition Fiji.cs:1050
static int YD
Definition Fiji.cs:1035
static int SCALE_STROKE_WIDTH
Definition Fiji.cs:1090
static int SHAPE_ROI_SIZE
Definition Fiji.cs:1040
static int XD
Definition Fiji.cs:1034
static int OPTIONS
Definition Fiji.cs:1044
static int Z_POSITION
Definition Fiji.cs:1055
static int LEFT
Definition Fiji.cs:1026
static int SIZE
Definition Fiji.cs:1038
static int IMAGE_OPACITY
Definition Fiji.cs:1062
static int OVERLAY_LABEL_COLOR
Definition Fiji.cs:1059
static int IMAGE_SIZE
Definition Fiji.cs:1063
static int X1
Definition Fiji.cs:1030
static int Y1
Definition Fiji.cs:1031
bool subPixel
Definition ROI.cs:211
static ROI CreateRectangle(ZCT coord, double x, double y, double w, double h)
Definition ROI.cs:1119
Type type
Definition ROI.cs:105
void UpdateBoundingBox()
Definition ROI.cs:1763
static ROI CreateEllipse(ZCT coord, double x, double y, double w, double h)
Definition ROI.cs:1136
void AddPoints(PointD[] p, bool convertPixelSpace=false, double physX=1, double physY=1)
Definition ROI.cs:1652
static ROI CreateLine(ZCT coord, PointD x1, PointD x2)
Definition ROI.cs:1099
List< PointD > Points
Definition ROI.cs:122