Skip to content

Commit

Permalink
Merge pull request #666 from micro-manager/lightSheetFixes
Browse files Browse the repository at this point in the history
Light sheet fixes
  • Loading branch information
henrypinkard authored Aug 19, 2023
2 parents b826b66 + 560b018 commit 1838686
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions java/src/main/java/org/micromanager/lightsheet/StackResampler.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ public StackResampler(
};

double[][] rotationMatrix = {
// working but inverted
// working but yields XZ rather than XY view
// {-Math.cos(Math.PI / 2 + theta), Math.sin(Math.PI / 2 + theta)},
// {-Math.sin(Math.PI / 2 + theta), -Math.cos(Math.PI / 2 + theta)}
{-Math.cos(theta), Math.sin(theta)},
{-Math.sin(theta), -Math.cos(theta)}
// rotates by 180 degrees around X axis
// {-Math.cos(theta), Math.sin(theta)},
// {-Math.sin(theta), -Math.cos(theta)

// this seems to be doing the right thing...
{Math.cos(theta), -Math.sin(theta)},
{Math.sin(theta), Math.cos(theta)}
};

double[][] cameraPixelToUmMatrix = {
Expand Down Expand Up @@ -242,9 +247,9 @@ private void computeRemappedCoordinateSpace() {
};

this.reconImageShape_ = new int[] {
(int) Math.ceil(totalTransformedExtent[0]) + 1,
(int) Math.ceil(totalTransformedExtent[1]) + 1,
this.cameraImageShape_[2] // x pixels are copied 1 to 1
(int) Math.ceil(totalTransformedExtent[0]) + 1, // Z
(int) Math.ceil(totalTransformedExtent[1]) + 1, // Y
this.cameraImageShape_[2] // X, x pixels are copied 1 to 1
};
}

Expand Down Expand Up @@ -375,6 +380,9 @@ public void initializeProjections() {
* @param imageSliceIndex z plane number, starting with 0.
*/
public void addImageToRecons(short[] image, int imageSliceIndex) {
if (image == null) {
return;
}
// Add to projection/recon
for (int yIndexCamera = 0; yIndexCamera < this.cameraImageShape_[1]; yIndexCamera++) {
if (!this.reconCoordLUT_.containsKey(new Point(imageSliceIndex, yIndexCamera))) {
Expand Down Expand Up @@ -577,7 +585,7 @@ public Runnable startStackProcessing() {

@Override
public boolean hasNext() {
return !stop_ && processedImages_.get() < StackResampler.this.cameraImageShape_[0];
return !stop_ && processedImages_.get() < (StackResampler.this.cameraImageShape_[0] - 1);
}

@Override
Expand All @@ -590,7 +598,8 @@ public ImagePlusSlice next() {
if (element.getPixels() == null) {
// This is the last image, stop processing
stop_ = true;
return null;
// returning null causes a null pointer exception soon.
//return null;
}
processedImages_.incrementAndGet();
return element;
Expand All @@ -603,9 +612,9 @@ public ImagePlusSlice next() {
return () -> StreamSupport.stream(Spliterators.spliterator(iterator,
StackResampler.this.cameraImageShape_[0],
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), true)
.forEach(imagePlusFrame ->
StackResampler.this.addImageToRecons(imagePlusFrame.getPixels(),
imagePlusFrame.getFrameNr()));
.forEach(imagePlusSlice ->
StackResampler.this.addImageToRecons(imagePlusSlice.getPixels(),
imagePlusSlice.getFrameNr()));
}


Expand Down

0 comments on commit 1838686

Please sign in to comment.