Skip to content

Commit

Permalink
Improve output/serialization of shading correction models
Browse files Browse the repository at this point in the history
  • Loading branch information
minnerbe committed Nov 27, 2024
1 parent 4030556 commit 0192c72
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class ShadingCorrectionFilter implements Filter {

Expand Down Expand Up @@ -74,7 +75,7 @@ public void init(final Map<String, String> params) {
public Map<String, String> toParametersMap() {
final Map<String, String> map = new LinkedHashMap<>();
map.put("correctionMethod", correctionMethod.name());
map.put("coefficients", Arrays.toString(coefficients));
map.put("coefficients", Arrays.stream(coefficients).mapToObj(String::valueOf).collect(Collectors.joining(",")));
return map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ public static void fit(final int type, final List<Roi> rois, final boolean showB
IJ.log("Fitting with " + fitTypes[type] + " model...");

final ShadingModel shadingModel;
final String modelType;
if (fitTypes[type].equals("Quadratic")) {
shadingModel = new QuadraticShading();
modelType = "quadratic";
} else if (fitTypes[type].equals("Fourth Order")) {
shadingModel = new FourthOrderShading();
modelType = "fourthOrder";
} else {
throw new IllegalArgumentException("Unknown fit type: " + fitTypes[type]);
}
Expand All @@ -128,7 +131,8 @@ public static void fit(final int type, final List<Roi> rois, final boolean showB
CorrectShading.fitBackgroundModel(rois, img, shadingModel);
IJ.log("Fitted shading model: " + shadingModel);
IJ.log("Fitting took " + (System.currentTimeMillis() - start) + "ms.");
IJ.log("Raw coefficients: " + Arrays.toString(shadingModel.getCoefficients()));
IJ.log("\"modelType\": \"" + modelType + "\",");
IJ.log("\"coefficients\": " + Arrays.toString(shadingModel.getCoefficients()));

final RandomAccessibleInterval<FloatType> shading = CorrectShading.createBackgroundImage(shadingModel, img);
final RandomAccessibleInterval<UnsignedShortType> corrected = CorrectShading.correctBackground(img, shading, new UnsignedShortType());
Expand Down

0 comments on commit 0192c72

Please sign in to comment.