Skip to content

Commit

Permalink
added similarity threshold as a CLI param
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip117 committed Jan 12, 2024
1 parent 34bc44e commit 0aa6872
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions image_textRemove.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import sys
from difflib import SequenceMatcher

__version__ = '1.1.4'
__version__ = '1.1.6'

DISPLAY_TITLE = r"""
_ _ _ _ ______
Expand All @@ -38,6 +38,8 @@
help='output file type(only the extension)')
parser.add_argument('-j', '--filterTextFromJSON', default='anonymizedTags.json', type=str,
help='A dictionary of dicom tags and their values')
parser.add_argument('-t', '--threshold', default=0.8, type=float,
help='threshold of similarity ration between two words')
parser.add_argument( '--pftelDB',
dest = 'pftelDB',
default = '',
Expand Down Expand Up @@ -97,7 +99,7 @@ def main(options: Namespace, inputdir: Path, outputdir: Path):
# The code block below is a small and easy example of how to use a ``PathMapper``.
# It is recommended that you put your functionality in a helper function, so that
# it is more legible and can be unit tested.
box_list, final_image = inpaint_text(str(input_file), data, box_list)
box_list, final_image = inpaint_text(str(input_file), data, box_list, options.threshold)
img_rgb = cv2.cvtColor(final_image, cv2.COLOR_BGR2RGB)
output_file = str(output_file).replace(options.fileFilter, options.outputType)
print(f"Saving output file as ----->{output_file}<-----\n\n")
Expand All @@ -110,7 +112,7 @@ def midpoint(x1, y1, x2, y2):
return x_mid, y_mid


def inpaint_text(img_path, data, box_list):
def inpaint_text(img_path, data, box_list, similarity_threshold):
word_list = []
for item in data.keys():
if item == 'PatientName':
Expand All @@ -133,7 +135,7 @@ def inpaint_text(img_path, data, box_list):

mask = np.zeros(img.shape[:2], dtype="uint8")
for box in box_list:
if (box[0].upper() in word_list) or close_to_similar(box[0].upper(), word_list,0.8):
if (box[0].upper() in word_list) or close_to_similar(box[0].upper(), word_list, similarity_threshold):
# Remove PatientName only
print(f"Removing {box[0].upper()} from image")
x0, y0 = box[1][0]
Expand Down

0 comments on commit 0aa6872

Please sign in to comment.