Add thresholding

This commit is contained in:
2026-09-29 12:35:26 +02:00
parent 2d417990ec
commit b8544b8f46
11 changed files with 647 additions and 2 deletions

View File

@@ -58,6 +58,8 @@ public class NavPresenter {
public void goToNonLinearOutline() { navigator.showNonLinearOutline(); }
public void goToThresholding() { navigator.showThresholding(); }
public GrayScaleMatrix getImageGrayMatrix() { return appState.getImage().toGrayScale(); }
public void setMode(Mode mode) { modeService.setMode(mode); }

View File

@@ -0,0 +1,12 @@
package presenters.threshold;
import domain.image.Image;
public interface ThresholdingListener {
void onSimpleThresholdChanged(Image image);
void onDoubleThresholdChanged(Image image);
void onAutomaticThresholdChanged(Image image);
}

View File

@@ -0,0 +1,94 @@
package presenters.threshold;
import app.state.AppState;
import app.state.ThresholdingState;
import domain.image.Image;
import jakarta.inject.Inject;
import services.ThresholdingService;
import ui.abstractions.IThresholdingView;
public class ThresholdingPresenter implements ThresholdingListener {
private final AppState appState;
private final ThresholdingState thresholdingState;
private final ThresholdingService thresholdingService;
private IThresholdingView view;
@Inject
public ThresholdingPresenter(
AppState appState,
ThresholdingState thresholdingState,
ThresholdingService thresholdingService
) {
this.appState = appState;
this.thresholdingState = thresholdingState;
this.thresholdingService = thresholdingService;
thresholdingState.subscribe(this);
}
public void setView(IThresholdingView view) {
this.view = view;
}
public void dispose() {
view = null;
thresholdingState.unsubscribe(this);
}
public void computeSimpleThreshold(int threshold) {
Image image = appState.getImage();
Image result = thresholdingService.simpleThreshold(
image,
threshold
);
thresholdingState.setSimpleThreshold(result);
}
public void computeDoubleThreshold(
int threshold1,
int threshold2
) {
Image image = appState.getImage();
Image result = thresholdingService.doubleThreshold(
image,
threshold1,
threshold2
);
thresholdingState.setDoubleThreshold(result);
}
public void computeAutomaticThreshold() {
Image image = appState.getImage();
Image result = thresholdingService.automaticThreshold(image);
thresholdingState.setAutomaticThreshold(result);
}
@Override
public void onSimpleThresholdChanged(Image image) {
if (view != null) {
view.updateSimpleThreshold(image);
}
}
@Override
public void onDoubleThresholdChanged(Image image) {
if (view != null) {
view.updateDoubleThreshold(image);
}
}
@Override
public void onAutomaticThresholdChanged(Image image) {
if (view != null) {
view.updateAutomaticThreshold(image);
}
}
}