Skip to content

Using Distance Transform Watershed without a GUI / UI #79

@satorstefan

Description

@satorstefan

Hello David,

I would like to use MorphoLibJ without any UI. For the moment I am focused on DistanceTransformWatershed().

Currently it seems to me the code assumes a UI is present.

Could you add a constructor to DistanceTransformWatershed() so I can pass all mandatory arguments?
Or using some sort of builder pattern for DistanceTransformWatershed() would also be nice.

What I tried, but it did not work because of java.awt.HeadlessException: null:

webcam.addValueChangeListener(e -> {
            value = e.getValue();

            String[] split = value.split(",");

            data = Base64.getDecoder().decode(split[1]);

            BufferedImage img = null;
            try {
                img = ImageIO.read(new ByteArrayInputStream(data));
            } catch (IOException ex) {

            }

            ImagePlus imp = new ImagePlus("test", img);

            var watershed = new DistanceTransformWatershed();
            watershed.setup("", imp);

            ImageProcessor processor =  imp.getProcessor();
            processor.autoThreshold();

            //this is false
            BinaryImages.isBinaryImage(imp);

            GenericDialog gd = new GenericDialog("Distance Transform Watershed");
            gd.setInsets(0, 0, 0);
            gd.addMessage("Distance map options:", new Font("SansSerif", 1, 12));
            gd.addChoice("Distances", ChamferWeights.getAllLabels(), "Chessboard (1,1)");
            String[] outputTypes = new String[]{"32 bits", "16 bits"};

            boolean floatProcessing = true;
            gd.addChoice("Output Type", outputTypes, outputTypes[floatProcessing ? 0 : 1]);

            gd.setInsets(0, 0, 0);
            gd.addCheckbox("Normalize weights", false);
            gd.setInsets(20, 0, 0);
            gd.addMessage("Watershed options:", new Font("SansSerif", 1, 12));
            gd.addNumericField("Dynamic", (double)2, 2);


            String[] connectivity = {"4", "8"};
            gd.addChoice("Connectivity", connectivity, "4");
            gd.setInsets(20, 0, 0);

            watershed.dialogItemChanged(gd, null);
            watershed.run(processor);


            FileSaver fileSaver = new FileSaver(imp);

            fileSaver.saveAsBmp("...");
        });

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions