(tile, threshold_white=20)
| 422 | return filtered_tiles |
| 423 | |
| 424 | def tile_is_not_empty(tile, threshold_white=20): |
| 425 | histogram = tile.histogram() |
| 426 | |
| 427 | # Take the median of each RGB channel. Alpha channel is not of interest. |
| 428 | # If roughly each chanel median is below a threshold, i.e close to 0 till color value around 250 (white reference) then tile mostly white. |
| 429 | whiteness_check = [0, 0, 0] |
| 430 | for channel_id in (0, 1, 2): |
| 431 | whiteness_check[channel_id] = np.median( |
| 432 | histogram[256 * channel_id : 256 * (channel_id + 1)][100:200] |
| 433 | ) |
| 434 | |
| 435 | if all(c <= threshold_white for c in whiteness_check): |
| 436 | # exclude tile |
| 437 | return False |
| 438 | |
| 439 | # keep tile |
| 440 | return True |
| 441 | |
| 442 | def crop_rect_from_slide(slide, rect): |
| 443 | minx, miny, maxx, maxy = rect.bounds |
nothing calls this directly
no outgoing calls
no test coverage detected