1

I'm trying to use R to annotate images (as either png or tiff) of tumor samples with a value according to where the corresponding region number is on the image. The numbers next to the circles represent certain regions where protein expression was taken. Here is an example of what I'm trying to do that I did by hand in powerpoint:

Photo of a tumor sample with values next to specific numbers on the sample

I have a dataframe (could be a named list) of values with the region number and value for the protein of interest. Here is a snippet of the data:

        Patient1_001    Patient1_002    Patient1_003
Ki-67         0.0162          0.0707           0.177

I could just keep annotating these images in powerpoint by hand, but that would be very inefficient as I will eventually have hundreds of these images. Is there a way in R to add the values next to their corresponding region without knowing the coordinates of the region? Is there a package/function/etc to just identify the number and put the correct value next to it? For example: recognize "001" in the image and add "0.0162" onto the image next to the "001"

I know a bit of python too so if this would be easier in python I'm open to that.

mfeldbauer
  • 132
  • 1
  • 9
  • 3
    Interesting, but you may be looking at the problem backwards. How did you plot the overlaid circles and their indices (numbers) in the first place? Whatever you did, save the coordinates used (or created) to place the circles and use them to locate the new text strings, using `graphics::text` – Carl Witthoft Jun 20 '23 at 17:46
  • you could try to use `tesseract::ocr_data()` to get the bounding boxes of the labels and the use a lookup table which annotation should be palced and place them using `magick` however maybe the person providing ypu those images has info on the positions of the labels anyways – user12256545 Jun 20 '23 at 17:54
  • @CarlWitthoft Oh that's a good point! The circles were drawn in with a software called GeoMx but I can check to see if I can export their coordinates – mfeldbauer Jun 20 '23 at 18:41

0 Answers0