diff --git a/histoqc/BaseImage.py b/histoqc/BaseImage.py index abf3d80..93a51f4 100644 --- a/histoqc/BaseImage.py +++ b/histoqc/BaseImage.py @@ -207,7 +207,7 @@ def getImgThumb(self, size: str): return self[key] ''' -the followings are helper functions +the following are helper functions ''' def getBestThumb(s: BaseImage, x: int, y: int, dims: Tuple[int, int], target_sampling_factor: float): osh = s["os_handle"] @@ -344,11 +344,11 @@ def getDimensionsByOneDim(s: BaseImage, dim: int) -> Tuple[int, int]: return w, dim -def getMaskReginsStats(img, area_threshold: int = 0)-> dict: +def getMaskRegionsStats(img)-> dict: rps = measure.regionprops(morphology.label(img)) if rps: - areas = np.asarray([rp.area for rp in rps if rp.area > area_threshold]) + areas = np.asarray([rp.area for rp in rps]) num = len(rps) area_min = areas.min() area_max = areas.max() diff --git a/histoqc/BasicModule.py b/histoqc/BasicModule.py index 77b08f0..e426a0f 100644 --- a/histoqc/BasicModule.py +++ b/histoqc/BasicModule.py @@ -1,6 +1,6 @@ import logging import os -from histoqc.BaseImage import printMaskHelper, getMaskReginsStats +from histoqc.BaseImage import printMaskHelper, getMaskRegionsStats from skimage.morphology import remove_small_objects, binary_opening, disk from skimage import io, color, img_as_ubyte @@ -71,8 +71,7 @@ def finalProcessingArea(s, params): f"After BasicModule.finalProcessingArea NO tissue remains detectable! Downstream modules likely to be incorrect/fail") -def countTissuePieces(s, params): - area_thresh = int(params.get("area_threshold", "1000")) +def countTissuePieces(s): mask = s["img_mask_use"] - stats = getMaskReginsStats(mask, area_threshold=area_thresh) + stats = getMaskRegionsStats(mask) s.addToPrintList("#pieces_of_tissue", str(stats.get('num', 0))) \ No newline at end of file diff --git a/histoqc/BlurDetectionModule.py b/histoqc/BlurDetectionModule.py index 12d5d8d..afea9f6 100644 --- a/histoqc/BlurDetectionModule.py +++ b/histoqc/BlurDetectionModule.py @@ -2,7 +2,7 @@ import os import skimage -from histoqc.BaseImage import printMaskHelper, getMaskReginsStats +from histoqc.BaseImage import printMaskHelper, getMaskRegionsStats from skimage import io, img_as_ubyte, morphology, measure from skimage.color import rgb2gray from skimage.filters import rank @@ -45,12 +45,12 @@ def identifyBlurryRegions(s, params): # area_mean = areas.mean() # else: # nobj = area_max = area_mean = 0 - stat_rs = getMaskReginsStats(mask) + stat_rs = getMaskRegionsStats(mask) - - # s.addToPrintList("blurry_removed_num_regions", str(nobj)) - # s.addToPrintList("blurry_removed_mean_area", str(area_mean)) - # s.addToPrintList("blurry_removed_max_area", str(area_max)) + + s.addToPrintList("blurry_removed_num_regions", str(stat_rs.get('num', 0))) + s.addToPrintList("blurry_removed_mean_area", str(stat_rs.get('area_mean',0))) + s.addToPrintList("blurry_removed_max_area", str(stat_rs.get('area_max',0))) s.addToPrintList("blurry_removed_percent", diff --git a/histoqc/MorphologyModule.py b/histoqc/MorphologyModule.py index 5f715c2..9bfac7d 100644 --- a/histoqc/MorphologyModule.py +++ b/histoqc/MorphologyModule.py @@ -1,7 +1,7 @@ import logging import os import numpy as np -from histoqc.BaseImage import printMaskHelper, getMaskReginsStats +from histoqc.BaseImage import printMaskHelper, getMaskRegionsStats from skimage import io, morphology, img_as_ubyte, measure from scipy import ndimage as ndi @@ -31,7 +31,7 @@ def removeSmallObjects(s, params): # area_mean = areas.mean() # else: # nobj = area_max = area_mean = 0 - stats = getMaskReginsStats(img_small) + stats = getMaskRegionsStats(img_small) # s.addToPrintList("small_tissue_removed_num_regions", str(nobj)) @@ -99,7 +99,7 @@ def removeFatlikeTissue(s, params): # area_mean = areas.mean() # else: # nobj = area_max = area_mean = 0 - stats = getMaskReginsStats(mask_fat) + stats = getMaskRegionsStats(mask_fat) # s.addToPrintList("fatlike_tissue_removed_num_regions", str(nobj)) # s.addToPrintList("fatlike_tissue_removed_mean_area", str(area_mean)) @@ -141,7 +141,7 @@ def fillSmallHoles(s, params): # area_mean = areas.mean() # else: # nobj = area_max = area_mean = 0 - stats = getMaskReginsStats(img_small) + stats = getMaskRegionsStats(img_small) # s.addToPrintList("small_tissue_filled_num_regions", str(nobj)) # s.addToPrintList("small_tissue_filled_mean_area", str(area_mean)) diff --git a/histoqc/config/config_v2.1.ini b/histoqc/config/config_v2.1.ini index f8d01e8..5e07245 100644 --- a/histoqc/config/config_v2.1.ini +++ b/histoqc/config/config_v2.1.ini @@ -255,4 +255,3 @@ upper_threshold: 210 invert: True [BasicModule.countTissuePieces] -area_threshold: 500