|
36 | 36 |
|
37 | 37 | import net.imagej.ops.AbstractOpTest; |
38 | 38 | import net.imagej.ops.Op; |
| 39 | +import net.imagej.ops.map.neighborhood.array.MapNeighborhoodNativeType; |
| 40 | +import net.imagej.ops.map.neighborhood.array.MapNeighborhoodNativeTypeExtended; |
| 41 | +import net.imagej.ops.map.neighborhood.array.MapNeighborhoodWithCenterNativeType; |
39 | 42 | import net.imagej.ops.special.computer.AbstractUnaryComputerOp; |
40 | 43 | import net.imglib2.algorithm.neighborhood.RectangleShape; |
41 | 44 | import net.imglib2.img.Img; |
@@ -113,6 +116,179 @@ public void testMapNeighborhoodsWithCenterAccess() { |
113 | 116 | } |
114 | 117 | } |
115 | 118 |
|
| 119 | + /** |
| 120 | + * Test if every neighborhood pixel of the 2D image was really accessed during |
| 121 | + * the map operation. |
| 122 | + * |
| 123 | + * @see MapNeighborhoodNativeType |
| 124 | + */ |
| 125 | + @Test |
| 126 | + public void testMapNeighborhoodsArrayImage2D() { |
| 127 | + final Op functional = |
| 128 | + ops.op(MapNeighborhoodNativeType.class, out, in, |
| 129 | + new RectangleShape(1, false), new CountNeighbors()); |
| 130 | + functional.run(); |
| 131 | + |
| 132 | + final byte[] expected = |
| 133 | + new byte[] { 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6, 9, 9, 9, 9, 9, 9, 9, 9, |
| 134 | + 9, 6, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, |
| 135 | + 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 9, |
| 136 | + 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 9, 9, 9, |
| 137 | + 9, 9, 9, 9, 9, 9, 6, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4 }; |
| 138 | + |
| 139 | + int index = 0; |
| 140 | + for (ByteType t : out) { |
| 141 | + assertEquals("Index " + index + ": ", expected[index++], t.get()); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * Test if every neighborhood pixel of the 2D image was really accessed during |
| 147 | + * the map operation. |
| 148 | + * |
| 149 | + * @see MapNeighborhoodNativeTypeExtended |
| 150 | + */ |
| 151 | + @Test |
| 152 | + public void testMapNeighborhoodsArrayImageAlias2D() { |
| 153 | + in = generateByteArrayTestImg(true, 7, 7); |
| 154 | + out = generateByteArrayTestImg(false, 7, 7); |
| 155 | + |
| 156 | + final Op functional = |
| 157 | + ops.op(MapNeighborhoodNativeTypeExtended.class, out, in, |
| 158 | + new RectangleShape(1, false), new CountNeighbors()); |
| 159 | + functional.run(); |
| 160 | + |
| 161 | + int index = 0; |
| 162 | + for (ByteType t : out) { |
| 163 | + assertEquals("Index " + index + ": ", 9, t.get()); |
| 164 | + index++; |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * Test if every neighborhood pixel of the 1D image was really accessed during |
| 170 | + * the map operation. |
| 171 | + * |
| 172 | + * @see MapNeighborhoodNativeType |
| 173 | + */ |
| 174 | + @Test |
| 175 | + public void testMapNeighborhoodsArrayImage1D() { |
| 176 | + in = generateByteArrayTestImg(true, 7); |
| 177 | + out = generateByteArrayTestImg(false, 7); |
| 178 | + |
| 179 | + final Op functional = |
| 180 | + ops.op(MapNeighborhoodNativeType.class, out, in, |
| 181 | + new RectangleShape(1, false), new CountNeighbors()); |
| 182 | + functional.run(); |
| 183 | + |
| 184 | + final byte[] expected = new byte[] { 2, 3, 3, 3, 3, 3, 2 }; |
| 185 | + |
| 186 | + int index = 0; |
| 187 | + for (ByteType t : out) { |
| 188 | + assertEquals("Index " + index + ": ", expected[index++], t.get()); |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + /** |
| 193 | + * Test if every neighborhood pixel of the 1D image was really accessed during |
| 194 | + * the map operation. |
| 195 | + * |
| 196 | + * @see MapNeighborhoodNativeTypeExtended |
| 197 | + */ |
| 198 | + @Test |
| 199 | + public void testMapNeighborhoodsArrayImageAlias1D() { |
| 200 | + in = generateByteArrayTestImg(true, 7); |
| 201 | + out = generateByteArrayTestImg(false, 7); |
| 202 | + |
| 203 | + final Op functional = |
| 204 | + ops.op(MapNeighborhoodNativeTypeExtended.class, out, in, |
| 205 | + new RectangleShape(1, false), new CountNeighbors()); |
| 206 | + functional.run(); |
| 207 | + |
| 208 | + int index = 0; |
| 209 | + for (ByteType t : out) { |
| 210 | + assertEquals("Index " + index + ": ", 3, t.get()); |
| 211 | + index++; |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + /** |
| 216 | + * Test if every neighborhood pixel of the 3D image was really accessed during |
| 217 | + * the map operation. |
| 218 | + * |
| 219 | + * @see MapNeighborhoodNativeType |
| 220 | + */ |
| 221 | + @Test |
| 222 | + public void testMapNeighborhoodsArrayImage3D() { |
| 223 | + in = generateByteArrayTestImg(true, 3, 3, 3); |
| 224 | + out = generateByteArrayTestImg(false, 3, 3, 3); |
| 225 | + |
| 226 | + final Op functional = |
| 227 | + ops.op(MapNeighborhoodNativeType.class, out, in, |
| 228 | + new RectangleShape(1, false), new CountNeighbors()); |
| 229 | + functional.run(); |
| 230 | + |
| 231 | + final byte[] expected = |
| 232 | + new byte[] { 8, 12, 8, 12, 18, 12, 8, 12, 8, 12, 18, 12, 18, 27, 18, 12, |
| 233 | + 18, 12, 8, 12, 8, 12, 18, 12, 8, 12, 8 }; |
| 234 | + |
| 235 | + int index = 0; |
| 236 | + for (ByteType t : out) { |
| 237 | + assertEquals("Index " + index + ": ", expected[index++], t.get()); |
| 238 | + } |
| 239 | + } |
| 240 | + |
| 241 | + /** |
| 242 | + * Test if every neighborhood pixel of the 3D image was really accessed during |
| 243 | + * the map operation. |
| 244 | + * |
| 245 | + * @see MapNeighborhoodNativeTypeExtended |
| 246 | + */ |
| 247 | + @Test |
| 248 | + public void testMapNeighborhoodsArrayImageAlias3D() { |
| 249 | + in = generateByteArrayTestImg(true, 7, 7, 7); |
| 250 | + out = generateByteArrayTestImg(false, 7, 7, 7); |
| 251 | + |
| 252 | + final Op functional = |
| 253 | + ops.op(MapNeighborhoodNativeTypeExtended.class, out, in, |
| 254 | + new RectangleShape(1, false), new CountNeighbors()); |
| 255 | + functional.run(); |
| 256 | + |
| 257 | + int index = 0; |
| 258 | + for (ByteType t : out) { |
| 259 | + assertEquals("Index " + index + ": ", 27, t.get()); |
| 260 | + index++; |
| 261 | + } |
| 262 | + } |
| 263 | + |
| 264 | + /** |
| 265 | + * Test if every neighborhood pixel of the 2D image was really accessed during |
| 266 | + * the map operation. |
| 267 | + * |
| 268 | + * @see MapNeighborhoodWithCenterNativeType |
| 269 | + */ |
| 270 | + @Test |
| 271 | + public void testMapNeighborhoodsWithCenterAccessArrayImage2D() { |
| 272 | + final Op functional = |
| 273 | + ops.op(MapNeighborhoodWithCenterNativeType.class, out, in, |
| 274 | + new RectangleShape(1, false), new CountNeighborsWithCenter()); |
| 275 | + functional.run(); |
| 276 | + |
| 277 | + final byte[] expected = |
| 278 | + new byte[] { 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6, 9, 9, 9, 9, 9, 9, 9, 9, |
| 279 | + 9, 6, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, |
| 280 | + 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 9, |
| 281 | + 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 9, 9, 9, |
| 282 | + 9, 9, 9, 9, 9, 9, 6, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4 }; |
| 283 | + |
| 284 | + int index = 0; |
| 285 | + for (ByteType t : out) { |
| 286 | + assertEquals("Index " + index + ": ", expected[index++], t.get()); |
| 287 | + } |
| 288 | + } |
| 289 | + |
| 290 | + |
| 291 | + |
116 | 292 | /** |
117 | 293 | * Function which increments the output value for every pixel in the |
118 | 294 | * neighborhood. |
|
0 commit comments