Skip to content

Commit

Permalink
measure/region2d: fix computation of BinaryConfigurationsHistogram2D …
Browse files Browse the repository at this point in the history
…for a selection of labels within the input image
  • Loading branch information
dlegland committed Sep 29, 2024
1 parent f8e3cc5 commit a5a21d2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,11 @@ public int[][] process(ImageProcessor labelImage, int[] labels)
localLabels.clear();
for (int label : configValues)
{
if (label == 0)
continue;
// do not consider background
if (label == 0) continue;
// do not consider labels not in the requested list
if (!labelIndices.containsKey(label)) continue;

// keep only one instance of each label
if (!localLabels.contains(label))
localLabels.add(label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,53 @@
*/
package inra.ijpb.measure.region2d;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

import ij.process.ByteProcessor;
import ij.process.ImageProcessor;
import inra.ijpb.label.LabelImages;

/**
* @author dlegland
*
*/
public class BinaryConfigurationsHistogram2DTest
{

/**
* Test method for {@link inra.ijpb.measure.region2d.BinaryConfigurationsHistogram2D#process(ij.process.ImageProcessor, int[])}.
*/
@Test
public final void test_processImageProcessor_allLabels()
{
ImageProcessor image = createFourRegionsLabelMap();
int[] labels = LabelImages.findAllLabels(image);

int[][] histo = new BinaryConfigurationsHistogram2D().process(image, labels);

// check size of histograms
assertEquals(histo.length, labels.length);
assertEquals(histo[0].length, 16);
}

/**
* Test method for {@link inra.ijpb.measure.region2d.BinaryConfigurationsHistogram2D#process(ij.process.ImageProcessor, int[])}.
*/
@Test
public final void test_processImageProcessor_selectedLabels()
{
ImageProcessor image = createFourRegionsLabelMap();
int[] labels = new int[] {5, 8, 9};

int[][] histo = new BinaryConfigurationsHistogram2D().process(image, labels);

// check size of histograms
assertEquals(histo.length, labels.length);
assertEquals(histo[0].length, 16);
}

/**
* Test method for {@link inra.ijpb.measure.region2d.BinaryConfigurationsHistogram2D#processInnerFrame(ij.process.ImageProcessor)}.
*/
Expand Down Expand Up @@ -93,4 +128,27 @@ public final void testProcessInnerFrame_OhserMuecklich()
}
}

/**
* Creates a label map containing four regions.
*
* @return a label map containing four regions.
*/
private static final ImageProcessor createFourRegionsLabelMap()
{
ImageProcessor array = new ByteProcessor(8, 8);
array.set(1, 1, 3);
for (int i = 3; i < 7; i++)
{
array.set(i, 1, 5);
array.set(1, i, 8);
}
for (int i = 3; i < 7; i++)
{
for (int j = 3; j < 7; j++)
{
array.set(i, j, 9);
}
}
return array;
}
}

0 comments on commit a5a21d2

Please # to comment.