Skip to content

Commit

Permalink
remove threshold in countTissuePieces, fix the typo and add stats int…
Browse files Browse the repository at this point in the history
…o the print list
  • Loading branch information
nanli-emory committed May 16, 2024
1 parent 4a3ad98 commit 222c372
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
6 changes: 3 additions & 3 deletions histoqc/BaseImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions histoqc/BasicModule.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)))
12 changes: 6 additions & 6 deletions histoqc/BlurDetectionModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions histoqc/MorphologyModule.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion histoqc/config/config_v2.1.ini
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,3 @@ upper_threshold: 210
invert: True

[BasicModule.countTissuePieces]
area_threshold: 500

0 comments on commit 222c372

Please sign in to comment.