Skip to content

Commit 0c2960a

Browse files
committed
some changes in the gradscore calculation
1 parent f63d4d2 commit 0c2960a

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

colormipsearch-api/src/main/java/org/janelia/colormipsearch/cds/ColorDepthSearchAlgorithmProviderFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ public ColorDepthSearchAlgorithm<ShapeMatchScore> createColorDepthSearchAlgorith
113113
queryImage.mapi(ImageTransformation.unsafeMaxFilter(60)),
114114
queryImage.mapi(ImageTransformation.unsafeMaxFilter(20)),
115115
(p1, p2) -> {
116-
return (p2 & 0xFFFFFF) != 0 ? 0xFF000000 : p1;
116+
return (p2 & 0xFFFFFF) != 0 ? 0xFF000000 : ((p1 & 0xFFFFFF) == 0 ? 0 : 1);
117117
} // mask pixels from the 60x image if they are present in the 20x image
118118
);
119119
ShapeMatchColorDepthSearchAlgorithm maskNegativeScoresCalculator = new ShapeMatchColorDepthSearchAlgorithm(
120120
queryImage,
121121
queryImage.map(ColorTransformation.toGray16WithNoGammaCorrection()).map(ColorTransformation.gray8Or16ToSignal(2)).reduce(),
122122
maskForRegionsWithTooMuchExpression.map(ColorTransformation.toGray16WithNoGammaCorrection()).map(ColorTransformation.gray8Or16ToSignal(0)).reduce(),
123123
roiMaskImage,
124-
cdsParams.getIntParam("queryThreshold", queryThreshold),
124+
queryThreshold,
125125
cdsParams.getBoolParam("mirrorMask", mirrorMask),
126126
clearIgnoredRegions
127127
);

colormipsearch-api/src/main/java/org/janelia/colormipsearch/cds/GradientAreaGapUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,14 @@ public static double calculateNormalizedScore(int pixelMatchScore,
228228
if (pixelMatchScore == 0 || maxPixelMatch == 0 || shapeScore < 0 || maxShapeScore <= 0) {
229229
return pixelMatchScore;
230230
} else {
231+
double normalizedPixelScore = (double) pixelMatchScore / maxPixelMatch;
231232
double normalizedShapeScore = (double)shapeScore / maxShapeScore;
232233
double boundedShapeScore = Math.min(
233234
Math.max(normalizedShapeScore * 2.5, LOW_NORMALIZED_NEGATIVE_SCORE),
234235
HIGH_NORMALIZED_NEGATIVE_SCORE
235236
);
236237

237-
return (double)pixelMatchScore / (double)maxPixelMatch / boundedShapeScore * 100;
238+
return normalizedPixelScore / boundedShapeScore * 100;
238239
}
239240
}
240241

colormipsearch-api/src/main/java/org/janelia/colormipsearch/imageprocessing/ColorTransformation.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,6 @@ static ColorTransformation toBinary8(int threshold) {
150150
return ColorTransformation.toGray8WithNoGammaCorrection().thenApplyColorTransformation(pv -> ColorTransformation.grayToBinary8(pv, threshold));
151151
}
152152

153-
public static ColorTransformation rgbToSignal(int threshold) {
154-
return new ColorTransformation(pt -> pt) {
155-
@Override
156-
public Integer apply(ImageType pt, Integer pv) {
157-
int grayPixelValue = ColorTransformation.rgbToGrayNoGammaCorrection(pv, 255);
158-
return grayPixelValue > threshold ? 1 : 0;
159-
}
160-
};
161-
}
162-
163153
public static ColorTransformation gray8Or16ToSignal(int threshold) {
164154
return new ColorTransformation(pt -> pt) {
165155
@Override

colormipsearch-api/src/main/java/org/janelia/colormipsearch/model/CDMatchEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public boolean hasGradScore() {
8484
}
8585

8686
private boolean has2DShapeScore() {
87-
return gradientAreaGap != null && gradientAreaGap >= 0 && highExpressionArea != null && highExpressionArea > 0;
87+
return gradientAreaGap != null && gradientAreaGap >= 0 && highExpressionArea != null && highExpressionArea >= 0;
8888
}
8989

9090
private boolean has3DBidirectionalShapeScore() {

colormipsearch-tools/src/main/java/org/janelia/colormipsearch/cmd/CalculateGradientScoresCmd.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static class CalculateGradientScoresArgs extends AbstractGradientScoresArgs {
9999
/**
100100
* Generator State is used by Reactor flux to generate new items.
101101
* Initially I thought I would use it to set up more context but now the only context that we keep is the start time.
102+
*
102103
* @param <E>
103104
*/
104105
static class GeneratorState<E> {
@@ -235,6 +236,10 @@ private void calculateAllGradientScores() {
235236
@Nonnull
236237
private <M extends AbstractNeuronEntity, T extends AbstractNeuronEntity>
237238
List<CDMatchEntity<M, T>> startAllGradientScores() {
239+
LOG.info("Calculate gradient scores using: top {} / {} / {} best lines / best samples per line / best matches per sample, " +
240+
"percentPositivePixels > {}%, negative radius = {}, mask threshold = {}, mirror mask = {}",
241+
args.numberOfBestLines, args.numberOfBestSamplesPerLine, args.numberOfBestMatchesPerSample,
242+
args.pctPositivePixels, args.negativeRadius, args.maskThreshold, args.mirrorMask);
238243
ImageRegionDefinition excludedRegions = args.getRegionGeneratorForTextLabels();
239244
NeuronMatchesReader<CDMatchEntity<M, T>> cdMatchesReader = getCDMatchesReader();
240245
Collection<String> maskIdsToProcess = cdMatchesReader.listMatchesLocations(
@@ -583,7 +588,7 @@ private <M extends AbstractNeuronEntity, T extends AbstractNeuronEntity> void no
583588
(s1, s2) -> new CombinedMatchScore(
584589
Math.max(s1.getPixelMatches(), s2.getPixelMatches()),
585590
Math.max(s1.getGradScore(), s2.getGradScore())));
586-
LOG.info("Max scores for {} matches is {}", matchesByMask.getKey(), maxScores);
591+
LOG.info("Max scores for {} matches with {} targets is {}", matchesByMask.getKey(), matchesByMask.getItemsCount(), maxScores);
587592
// update normalized scores for all matches for this mask
588593
matchesByMask.getItems().forEach(m -> {
589594
double normalizedScore = GradientAreaGapUtils.calculateNormalizedScore(

colormipsearch-tools/src/main/java/org/janelia/colormipsearch/cmd/jacsdata/ColorDepthMIP.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.apache.commons.collections4.CollectionUtils;
1212
import org.apache.commons.lang3.StringUtils;
13+
import org.apache.commons.lang3.Strings;
1314
import org.apache.commons.lang3.builder.ToStringBuilder;
1415
import org.janelia.colormipsearch.dto.AbstractNeuronMetadata;
1516
import org.janelia.colormipsearch.dto.EMNeuronMetadata;
@@ -175,6 +176,7 @@ public String emAnatomicalArea() {
175176
? emBody.emDataSet.anatomicalArea
176177
: anatomicalArea;
177178
}
179+
178180
public String em3DFilename(String prefix, String em3DFile, String ext) {
179181
if (StringUtils.isBlank(em3DFile)) {
180182
return null;
@@ -252,7 +254,14 @@ public void updateEMNeuron(EMNeuronMetadata emNeuron, NeuronPublishedURLs neuron
252254

253255
emNeuron.setPublishedName(emBodyId());
254256
emNeuron.setFullPublishedName(emPublishedName());
255-
emNeuron.setAnatomicalArea(emAnatomicalArea());
257+
// this is to handle cases where anatomical area is not set as expected
258+
// this happens for CNS for example where the anatomical area is set to CNS
259+
String anatomicalArea = emAnatomicalArea();
260+
if (Strings.CI.equals("brain", anatomicalArea) || Strings.CI.equals("vnc", anatomicalArea)) {
261+
emNeuron.setAnatomicalArea(anatomicalArea);
262+
} else {
263+
emNeuron.setAnatomicalArea(getAnatomicalAreaFromAlignmentSpace(emNeuron.getAlignmentSpace()));
264+
}
256265
emNeuron.setNeuronInstance(neuronInstance);
257266
emNeuron.setNeuronType(neuronType);
258267
emNeuron.setGender(Gender.fromVal(emGender()));
@@ -269,6 +278,14 @@ public void updateEMNeuron(EMNeuronMetadata emNeuron, NeuronPublishedURLs neuron
269278
}
270279
}
271280

281+
private String getAnatomicalAreaFromAlignmentSpace(String alignmentSpace) {
282+
switch (alignmentSpace) {
283+
case "JRC2018_Unisex_20x_HR": return "Brain";
284+
case "JRC2018_VNC_Unisex_40x_DS": return "VNC";
285+
default: throw new IllegalArgumentException("Invalid alignmentSpace " + alignmentSpace);
286+
}
287+
}
288+
272289
private String getNeuronURL(NeuronPublishedURLs neuronURLs, String fileType) {
273290
if (neuronURLs == null) {
274291
return null;

0 commit comments

Comments
 (0)