ludvigla / semla

Other
56 stars 5 forks source link

Error loading image #1

Closed TeodoraTockovska closed 1 year ago

TeodoraTockovska commented 1 year ago

Hi! I have run into an error when loading an image. Selma loads the high resolution image for a Seurat object found in the spatial directory (tissue_hires_image.png). However, it does not load the following image for a Seurat object within the spatial directory: detected_tissue_image.jpg. I also converted the image to PNG format but again won't load it.

Below is my error. I believe that the code is breaking at this line: https://github.com/ludvigla/semla/blob/main/R/load_images.R#L78.

! White space will be added to H&E images to fit all spots on the images
── Loading H&E images ──

ℹ Loading image from ../spatial/detected_tissue_image.png
Error in if (any(as.numeric(pad_info[i, c("before_x", "before_y"), drop = TRUE]) >  : 
  missing value where TRUE/FALSE needed
In addition: Warning message:
There were 2 warnings in `mutate()`.
The first warning was:
ℹ In argument: `after_x = .Primitive("as.integer")(after_x)`.
Caused by warning:
! NAs introduced by coercion
ℹ Run dplyr::last_dplyr_warnings() to see the 1 remaining warning.

The following is my image characteristics:

>read_image <- magick::image_read("../spatial/detected_tissue_image.png")
>info <- magick::image_info(read_image)
>info
# A tibble: 1 × 7
  format width height colorspace matte filesize density
  <chr>  <int>  <int> <chr>      <lgl>    <int> <chr>  
1 PNG     1971   2000 sRGB       TRUE   6635124 28x28 

I noticed that the image values are not being saved in my Staffli object (as shown below).

>spatial_data <- GetStaffli(se)
>spatial_data@image_info
# A tibble: 1 × 11
  format width height full_width full_height colorspace filesize density sampleID type    pad      
  <chr>  <dbl>  <dbl>      <dbl>       <dbl> <chr>         <int> <chr>   <chr>    <chr>   <chr>    
1 PNG       NA     NA         NA          NA sRGB        6635124 28x28   1        unknown 0xNAx0xNA

Do you have advice how I can load my image? Could it be possible that the function isn't detecting that I have a Seurat object? The error is found on line 78 which belongs to LoadImages.default, and not LoadImages.Seurat (https://github.com/ludvigla/semla/blob/main/R/load_images.R#L126).

Thanks in advance!

ludvigla commented 1 year ago

Hey,

You have to chose either tissue_lowres or tissue_hires for the 'imgs' column in the infoTable when running ReadVisiumData. If you want to use another image, you need to provide another column called 'scalefactor' with scale factors. You will need to update the package to use this option.

However, I believe the detected_tissue_image.jpg will not be compatible anyways because the spot coordinates in tissue_positions.csv are only compatible with tissue_hires_image.png. May I ask why you want to use this image? :-)

Cheers, Ludvig

TeodoraTockovska commented 1 year ago

Hi Ludvig! Thank you so much for your quick reply!

I am running an analysis where specific spots on the image (detected_tissue_image.png) are highlighted. Those spots are selected for further analysis instead of performing a ST analysis on the entire tissue. I already finished the analysis entirely using Seurat, but I found your package the other day and I really liked the visualization methods that semla has to offer! I wanted to create some visualizations that I can show my team to compare gene expression profiles between 2 samples by using the MapFeatures function.

Would it be possible to use the image in the future? I think it would be very beneficial if any image from the spatial/ directory could be accessed but I also see that it might not be possible given that the spot coordinates aren't compatible.

ludvigla commented 1 year ago

Ok I see. Well you can actually make the image compatible if you just crop it and remove the white margins. Haven't tried it myself but I think it should work.

But I'm not planning to implement new functionality to load these other images unless many people want to use it for some reason. You can take any image and modify it a bit in Photoshop (or something similar) and it should work fine in semla, and it'll not take much time at all. If you can come up with a good way to convert the spot coordinates to fit all of these images, I can add this functionality, but right now I don't see a simple solution for it :-) I have never heard anyone using the other images before btw, so I never really thought much about it.

TeodoraTockovska commented 1 year ago

Thanks for your reply! I will try it out and see if I can add that functionality and notify you (if I can figure it out!). Have a great day! :)

By the way, the error that I encountered still stands when loading images that are not the high or low-resolution images. I cropped my image and I still encountered the same issue. Why does that error occur?

lfranzen commented 1 year ago

Hi @TeodoraTockovska – Thank you for trying out semla! Do you still get errors when loading your images? Otherwise I'll close this issue :)

/Lovisa

TeodoraTockovska commented 1 year ago

Hi @TeodoraTockovska – Thank you for trying out semla! Do you still get errors when loading your images? Otherwise I'll close this issue :)

/Lovisa

Hi Lovisa! I can close this issue. Have a nice day.