Skip to content

Commit c0f8548

Browse files
authored
enhance FilterObjects_StringMatch (#257)
add string contains option, configurable measurement selection to FilterObjects_StringMatch
1 parent 81125d0 commit c0f8548

2 files changed

Lines changed: 35 additions & 10 deletions

File tree

active_plugins/filterobjects_stringmatch.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Divider,
44
)
55
from cellprofiler_core.setting.text import Alphanumeric
6+
from cellprofiler_core.setting.choice import Choice
7+
from cellprofiler_core.setting import Measurement
68

79
__doc__ = ""
810

@@ -19,6 +21,8 @@
1921

2022
LOGGER = logging.getLogger(__name__)
2123

24+
METHOD_EXACT = "Exact match"
25+
METHOD_CONTAINS = "String contains"
2226

2327
class FilterObjects_StringMatch(ObjectProcessing):
2428
module_name = "FilterObjects_StringMatch"
@@ -46,20 +50,37 @@ def create_settings(self):
4650
self.filter_out = Alphanumeric(
4751
"What string to filter out",
4852
"AAAA",
49-
doc="""Enter a name for the measurement calculated by this module.""",
53+
doc="""Enter the string that should be used to filter objects.""",
5054
)
5155

56+
self.filter_method = Choice(
57+
"Filter method",
58+
[METHOD_EXACT, METHOD_CONTAINS],
59+
doc="""Select whether to only filter objects that are an exact match for the string entered
60+
(e.g. Object 'AAAAB' will NOT be filtered by string 'AAAA')
61+
or to filter any object that contains the string entered
62+
(e.g. Object 'AAAAB' will be filtered by string 'AAAA').""",
63+
)
64+
65+
self.filter_column = Measurement("Measurement",
66+
self.x_name.get_value,
67+
"Barcode_BarcodeCalled",
68+
doc="""Select the measurement column that will be used for filtering.""",
69+
)
70+
5271
self.rules.create_settings()
5372

5473
def settings(self):
5574
settings = super(FilterObjects_StringMatch, self).settings()
56-
settings += [self.filter_out]
75+
settings += [self.filter_out,self.filter_method, self.filter_column]
5776
return settings
5877

5978
def visible_settings(self):
6079
visible_settings = super(FilterObjects_StringMatch, self).visible_settings()
6180
visible_settings += [
62-
self.filter_out
81+
self.filter_out,
82+
self.filter_method,
83+
self.filter_column
6384
]
6485
return visible_settings
6586

@@ -164,13 +185,16 @@ def keep_by_string(self, workspace, src_objects):
164185
"""
165186
src_name = self.x_name.value
166187
m = workspace.measurements
167-
values = m.get_current_measurement(src_name, "Barcode_BarcodeCalled")
168-
# Is this structure still necessary or is it an artifact?
169-
# Could be just values == self.filter_out.value
170-
# Make an array of True
171-
hits = numpy.ones(len(values), bool)
172-
# Fill with False for those where we want to filter out
173-
hits[values == self.filter_out.value] = False
188+
values = m.get_current_measurement(src_name, self.filter_column.value)
189+
if self.filter_method == METHOD_EXACT:
190+
# Is this structure still necessary or is it an artifact?
191+
# Could be just values == self.filter_out.value
192+
# Make an array of True
193+
hits = numpy.ones(len(values), bool)
194+
# Fill with False for those where we want to filter out
195+
hits[values == self.filter_out.value] = False
196+
elif self.filter_method == METHOD_CONTAINS:
197+
hits = [self.filter_out.value in x for x in values]
174198
# Get object numbers for things that are True
175199
indexes = numpy.argwhere(hits)[:, 0]
176200
# Objects are 1 counted, Python is 0 counted

documentation/CP-plugins-documentation/supported_plugins.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Those plugins that do have extra documentation contain links below.
1717
| CompensateColors | CompensateColors determines how much signal in any given channel is because of bleed-through from another channel and removes the bleed-through. It can be performed across an image or masked to objects and provides a number of preprocessing and rescaling options to allow for troubleshooting if input image intensities are not well matched. | No | | N/A |
1818
| DistanceTransform | DistanceTransform computes the distance transform of a binary image. The distance of each foreground pixel is computed to the nearest background pixel and the resulting image is then scaled so that the largest distance is 1. | No | | N/A |
1919
| EnhancedMeasureTexture| EnhancedMeasureTexture measures the degree and nature of textures within an image or objects in a more comprehensive/tuneable manner than the MeasureTexture module native to CellProfiler. | No | | N/A |
20+
| FilterObjects_StringMatch| FilterObjects_StringMatch allows filtering of objects using exact or partial string matching in a manner similar to FilterObjects. | No | | N/A |
2021
| HistogramEqualization | HistogramEqualization increases the global contrast of a low-contrast image or volume. Histogram equalization redistributes intensities to utilize the full range of intensities, such that the most common frequencies are more distinct. This module can perform either global or local histogram equalization. | No | | N/A |
2122
| HistogramMatching | HistogramMatching manipulates the pixel intensity values an input image and matches them to the histogram of a reference image. It can be used as a way to normalize intensities across different 2D or 3D images or different frames of the same 3D image. It allows you to choose which frame to use as the reference. | No | | N/A |
2223
| PixelShuffle | PixelShuffle takes the intensity of each pixel in an image and randomly shuffles its position. | No | | N/A |

0 commit comments

Comments
 (0)