ysbecca/py-wsi

Issues with Processing Images with different labels.

Closed this issue · 4 comments

           ##Patches with Different Labels do not get Processed Correctly.

I have tried to process images with different labels. The image patches that are generated belong to single default label of type 0. I have tried customizing the code but to no avail. Also I have tried running the program at various levels from Level 1 to Level 16 that is the maximum number of levels which exist for the image I am processing. However I get image patches or tiles with only default label 0.

Please could you suggest what can be done so that all the patches belonging to different labels are extracted correctly rather just going into the default Normal or Label 0. I have tried my level best to resolve it, however I wasn't able to extract image patches with valid labels correctly.

@ysbecca Please could let me know I am stuck up in the middle of my research.

Hi Rebecca,

I am extremely thankful to you for your amazing work. I am attaching a sample of my xml annotation file for the above mentioned issue. Please go through it and suggest accordingly. This is a part of my research work.

Awaiting your reply.
annotationxml

Hi @hitesha14, I would suggest debugging this in the following way:

Copy the function get_regions(path) in the file patch_reader.py into a separate Python file or Jupyter notebook. This function takes an absolute path to an XML annotation file.

Find out exactly what this function is returning when you give it your XML. It returns a tuple of regions and region_labels.

region_labels should exactly match what you have specified in your label dictionary. In my Jupyter notebook example, I call it label_map in cell [2].

You can get an error either because your label_map dict is NOT matching what is in region_labels so it's returning the default label, OR because your XML is not in the expected format (although it looks ok to me from your image above) and the regions and/or labels are not read correctly.

Tried all Means of Debugging, Labels are not getting generated

Hii @ysbecca, I have tried all possible means of debugging. However I feel there is some flaw in the logic. label_map dict is exactly matching the region_label. Regions or Labels are read correctly. I have checked all the possibilities.

My regions_labels are according to the regions in the xml which is matching with the variable label_map in the cell 2 of notebook. However it seems following piece of code never gets executed for all possible level of the image. I have tried different zooming level to make the following if conditions to work but it did not work at all.
if poly.contains(Point(point[0], point[1])): if check_label_exists(region_labels[i], label_map): return label_map[region_labels[i]] else: return -1
The above prices of code checks the following converted_coordinates to be part of ploygon, do I need to modify following lines of code to get appropriate points so that above lines of codes gets execute successfully and generates some labels?

if xml_dir:
converted_coords = tiles.get_tile_coordinates(level, (x, y))[0]
labels.append(generate_label(regions, region_labels, converted_coords, label_map))
x += 1`

Instead of using the Shapely module (poly, Point, etc) to check whether a point is in a region, you could instead use the annotations to generate binary PNG images, with a unique integer for each region and a separate unique integer for background. Then you can label your patches by comparing with the binary mask.

I would suggest generating at least a few of these binary masks regardless to double check that your annotations are valid, if you say it is reading in correctly.