imagej / imagej/imagej-ops

MapNeighborhood Concurrency Issue

Open
#360 7 comments 0 reactions 0 assignees View on GitHub
2016-07-hackathon
Dominant language
Java
Stars
94
Forks
44
PR merge metrics
No merged PRs in 30d

Description

Code to generate the problem:

```
@Test
public void test() {
ops.run(MapNeighborhood.class, out, in,
new AbstractUnaryComputerOp, ByteType>()
{

@Override
public void compute1(Iterable input, ByteType output) {
for (ByteType e : input)
e.copy();
}
}, new RectangleShape(1, false));
}
```

where `out` and `in` are two `Img`.

The test above basically iterate through all the 3x3 rectangular neighborhoods in the input image, and do a `copy()` on each pixel of each neighborhood. This test always `ArrayIndexOutOfBoundException` at `ByteArray#getValue(index)`.

Other observations:
1. changing to `FloatType` does not help
2. `DiamondShape`, `HorizontalLineShape`, still produce the problem, but `PairOfPointShape` does not
3. When the shape is changed to `new RectangleShape(0, false)` (1x1 rectangle so no overlap between nearby shapes), this test does not throw exception.
4. change `copy()` to some method call that does not access the value (e.g. `getEntitiesPerPixel()`) does not produce the problem
5. [`MapNeighborhood`](https://github.com/imagej/imagej-ops/blob/master/src/main/java/net/imagej/ops/map/neighborhood/MapNeighborhood.java#L81) uses `shape.neighborhoodSafe(...)`, which seems to be "thread safe" to me (I do not know how those `shape`s are implemented).

I think the reason of this behavior is that each pixel is accessed concurrently, in different `RectangleShape`s. I suspect that those shapes are not implemented correctly.

Since any useful use of `MapNeighborhood` need to access the pixel values in the neighborhood, I think this issue is quite serious. Or do I misunderstand how this op should be used? @dietzc @ctrueden

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reproduction in the issue and MapNeighborhood.java around the neighborhoodSafe call. Inspect the relevant shape implementations, especially RectangleShape and the overlapping-neighborhood path, while comparing against PairOfPointShape and a 1x1 RectangleShape. Done means the reproduction can read neighborhood pixel values concurrently without ArrayIndexOutOfBoundsException, with a regression test covering the failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
computer-vision
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.