Skip to content

Commit

Permalink
simplified by removing compositions and performing operation in the f…
Browse files Browse the repository at this point in the history
…unction directly; require zgap variant to be present for gradscore
  • Loading branch information
Cristian Goina committed Aug 8, 2024
1 parent b0bafa9 commit eb49c49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ public ColorDepthSearchAlgorithm<ShapeMatchScore> createColorDepthSearchAlgorith
int queryBorderSize,
ColorDepthSearchParams cdsParams) {
ImageTransformation clearIgnoredRegions = ImageTransformation.clearRegion(excludedRegions.getRegion(queryImageArray));
ImageProcessing negativeRadiusDilation = ImageProcessing.create(clearIgnoredRegions)
.applyColorTransformation(ColorTransformation.mask(queryThreshold))
.unsafeMaxFilter(cdsParams.getIntParam("negativeRadius", negativeRadius));
long startTime = System.currentTimeMillis();
LImage roiMaskImage;
if (roiMaskImageArray == null) {
Expand All @@ -126,8 +123,7 @@ public ColorDepthSearchAlgorithm<ShapeMatchScore> createColorDepthSearchAlgorith
roiMaskImage,
cdsParams.getIntParam("queryThreshold", queryThreshold),
cdsParams.getBoolParam("mirrorMask", mirrorMask),
clearIgnoredRegions,
negativeRadiusDilation
clearIgnoredRegions
);

LOG.debug("Created gradient area gap calculator for mask in {}ms", System.currentTimeMillis() - startTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@

import org.janelia.colormipsearch.imageprocessing.ColorTransformation;
import org.janelia.colormipsearch.imageprocessing.ImageArray;
import org.janelia.colormipsearch.imageprocessing.ImageProcessing;
import org.janelia.colormipsearch.imageprocessing.ImageTransformation;
import org.janelia.colormipsearch.imageprocessing.LImage;
import org.janelia.colormipsearch.imageprocessing.LImageUtils;
import org.janelia.colormipsearch.imageprocessing.QuadFunction;
import org.janelia.colormipsearch.imageprocessing.TriFunction;
import org.janelia.colormipsearch.model.ComputeFileType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -28,15 +26,20 @@ public class ShapeMatchColorDepthSearchAlgorithm implements ColorDepthSearchAlgo
private static final int DEFAULT_COLOR_FLUX = 40; // 40um
private static final int GAP_THRESHOLD = 3;

private static final TriFunction<Integer, Integer, Integer, Integer> PIXEL_GAP_OP = (targetGradPix, queryPix, targetDilatedPix) -> {
private static final QuadFunction<Integer, Integer, Integer, Integer, Integer> PIXEL_GAP_OP = (querySignal, targetGradPix, queryPix, targetDilatedPix) -> {
int gap;
if ((queryPix & 0xFFFFFF) != 0 && (targetDilatedPix & 0xFFFFFF) != 0) {
int pxGapSlice = GradientAreaGapUtils.calculateSliceGap(queryPix, targetDilatedPix);
if (DEFAULT_COLOR_FLUX <= pxGapSlice - DEFAULT_COLOR_FLUX) {
// negative score value
return pxGapSlice - DEFAULT_COLOR_FLUX;
gap = pxGapSlice - DEFAULT_COLOR_FLUX;
} else {
gap = querySignal * targetGradPix;
}
} else {
gap = querySignal * targetGradPix;
}
return targetGradPix; // this is conditioned actually by the querySignal
return gap > GAP_THRESHOLD ? gap : 0;
};

private final LImage queryImage;
Expand All @@ -46,29 +49,21 @@ public class ShapeMatchColorDepthSearchAlgorithm implements ColorDepthSearchAlgo
private final int queryThreshold;
private final boolean mirrorQuery;
private final ImageTransformation clearLabels;
private final ImageProcessing negativeRadiusDilation;
private final QuadFunction<Integer, Integer, Integer, Integer, Integer> gapOp;

ShapeMatchColorDepthSearchAlgorithm(LImage queryImage,
LImage queryIntensityValues,
LImage queryHighExpressionMask,
LImage queryROIMaskImage,
int queryThreshold,
boolean mirrorQuery,
ImageTransformation clearLabels,
ImageProcessing negativeRadiusDilation) {
ImageTransformation clearLabels) {
this.queryImage = queryImage;
this.queryIntensityValues = queryIntensityValues;
this.queryHighExpressionMask = queryHighExpressionMask;
this.queryROIMaskImage = queryROIMaskImage;
this.queryThreshold = queryThreshold;
this.mirrorQuery = mirrorQuery;
this.clearLabels = clearLabels;
this.negativeRadiusDilation = negativeRadiusDilation;
this.gapOp = (/*querySignal*/p1,
/*targetGrad*/p2,
/*queryPix*/p3,
/*target20pxDilation*/p4) -> PIXEL_GAP_OP.apply(p1 * p2, p3, p4);
}

@Override
Expand Down Expand Up @@ -157,15 +152,13 @@ public ShapeMatchScore calculateMatchingScore(@Nonnull ImageArray<?> targetImage
Map<ComputeFileType, Supplier<ImageArray<?>>> variantImageSuppliers) {
long startTime = System.currentTimeMillis();
ImageArray<?> targetGradientImageArray = getVariantImageArray(variantImageSuppliers.get(ComputeFileType.GradientImage));
if (targetGradientImageArray == null) {
ImageArray<?> targetZGapMaskImageArray = getVariantImageArray(variantImageSuppliers.get(ComputeFileType.ZGapImage));
if (targetGradientImageArray == null || targetZGapMaskImageArray == null) {
return new ShapeMatchScore(-1, -1, -1, false);
}
ImageArray<?> targetZGapMaskImageArray = getVariantImageArray(variantImageSuppliers.get(ComputeFileType.ZGapImage));
LImage targetImage = LImageUtils.create(targetImageArray).mapi(clearLabels);
LImage targetGradientImage = LImageUtils.create(targetGradientImageArray);
LImage targetZGapMaskImage = targetZGapMaskImageArray != null
? LImageUtils.create(targetZGapMaskImageArray)
: negativeRadiusDilation.applyTo(targetImage.map(ColorTransformation.mask(queryThreshold)));
LImage targetZGapMaskImage = LImageUtils.create(targetZGapMaskImageArray);

ShapeMatchScore negativeScores = calculateNegativeScores(targetImage, targetGradientImage, targetZGapMaskImage, ImageTransformation.IDENTITY, false);

Expand Down Expand Up @@ -216,7 +209,7 @@ private ShapeMatchScore calculateNegativeScores(LImage targetImage, LImage targe
targetGradientImage,
queryROIImage,
targetZGapMaskImage.mapi(maskTransformation),
gapOp.andThen(gap -> gap > GAP_THRESHOLD ? gap : 0)
PIXEL_GAP_OP
);
LImage highExpressionRegions = LImageUtils.combine2(
targetImage,
Expand Down

0 comments on commit eb49c49

Please sign in to comment.