muschellij2 / papayaWidget

Widget for papaya!
6 stars 7 forks source link

Unable to read multiple dicom in papaya r #9

Open robertoromor opened 3 years ago

robertoromor commented 3 years ago

This is a question more than a bug.

I have downloaded multiple dicom images from here https://www.visus.com/en/downloads/jivex-dicom-viewer.html to a local directory now I want to read all of them into papayaWidget. When I read all of them at once by inputing a vector of directories + files into the papaya function instead of getting:

image

I got multiple layers:

image

Can someone advice in how I can read a vector of dcm, do I need to conver them to another format, can someone share an example.

I have also started trying function dcm2niir with no success I get an error like:

Error in curl::curl_fetch_disk(url, x$path, handle = handle) : Failed to open file /path_to_package/dcm2niir/dcm2nii_files.zip

robertoromor commented 3 years ago

Reproducible example:

Download one of the cases here: https://www.visus.com/en/downloads/jivex-dicom-viewer.html to a local directory and unzip them

and then upload them to this shiny app:

library(shiny)
library(papayaWidget)
shinyApp(
    ui = fluidPage(  
        fileInput("file1", "Choose DICOM File",
                  multiple = TRUE,
                  accept = c("application/dicom", "image/dicom", "video/mpeg", "video/mp4")),
        papayaOutput("contents")
        ),
    server = function(input, output) {

        output$contents<-renderPapaya({

            req(input$file1)

            papaya(input$file1$datapath)

        })

    }
)
muschellij2 commented 3 years ago

So the issue is that these slices have different series numbers and are not one contiguous series. If you want to force it, you can try this:

library(shiny)
library(RNifti)
library(papayaWidget)
library(dcm2niir)
install_dcm2nii()
shinyApp(
  ui = fluidPage(
    fileInput("file1", "Choose DICOM File",
              multiple = TRUE,
              accept = c("application/dicom", "image/dicom", "video/mpeg", "video/mp4")),
    papayaOutput("contents")
  ),
  server = function(input, output) {

    output$contents<-renderPapaya({

      req(input$file1)
      print(input$file1)
      out = dcm2nii(files = input$file1$datapath, merge_files = TRUE)
      img = RNifti::readNifti(out$nii_after)
      if (length(out) > 0) {
        temp = img[[1]]
        r = sapply(img, function(x) {
          dim(x)[1:3]
        })
        if (all(r[1,] == r[1,1]) &&
            all(r[2,] == r[2,1])) {

          r3 = sum(r[3,])
          outimg = array(NA, dim = c(r[1,1], r[2,1], r3))
          start = 1
          for (i in img) {
            print(start)
            outimg[1:nrow(i), 1:ncol(i), start:(start+dim(i)[3]-1)] =
              array(i, dim = dim(i))
            start = start+dim(i)[3]
          }
          img = asNifti(outimg, reference = temp)
          rm(outimg)
        }
      }
      tfile = tempfile(fileext = ".nii.gz")
      writeNifti(img, file = tfile)
      papaya(tfile)
    })

  }
)
robertoromor commented 3 years ago

Its a good solution, It works. Compared to just clicking inside the papaya widget: File >Add dicom folder, it actually uploads the whole thing in seconds compared to converting the whole thing to nii.gz which it just takes almost 4 minutes to visualize the whole dicom folder (31 dcm files). And it sometimes even shows partial results like:

image

compared to what papaya visualizes when you upload the dicom folder directly from the widget:

image

I guess this might be more of a feature request, to connect the papaya function to this capability that the Widget has to upload multiple, or an entire folder of dicoms, is this feasible or do you think there might be a workaround?

Roberto R.

muschellij2 commented 3 years ago

Again, I think the issue is that those DICOM folders have a mix of different viewed areas. Some coronal, some sagittal.

On Sat, Feb 13, 2021 at 1:59 AM robertoromor notifications@github.com wrote:

Its a good solution, It works. Compared to just clicking inside the papaya widget: File >Add dicom folder, it actually uploads the whole thing in seconds compared to converting the whole thing to nii.gz which it just takes almost 4 minutes to visualize the whole dicom folder (31 dcm files). And it sometimes even shows partial results like:

[image: image] https://user-images.githubusercontent.com/40498484/107844114-a1596380-6d85-11eb-9a73-e6580fe86643.png

compared to what papaya visualizes when you upload the dicom folder directly from the widget:

[image: image] https://user-images.githubusercontent.com/40498484/107844127-b8985100-6d85-11eb-905d-a3696df1cc2c.png

I guess this might be more of a feature request, to connect the papaya function to this capability that the Widget has to upload multiple, or an entire folder of dicoms, is this feasible or do you think there might be a workaround?

Roberto R.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/muschellij2/papayaWidget/issues/9#issuecomment-778574158, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIGPLTY6S4ZGMTX4M57DPLS6YPO7ANCNFSM4XP2M62Q .

-- Best, John

robertoromor commented 3 years ago

I see what you mean now with the files having different slice number. I hate to bother you some more. I have 2 questions:

1) If the DICOM folder had the a single view area will the papaya function be able to read the folder at once? 2) The image I sent where you read the folder directly from the Widget that looks better, how can it do it, even though there is a mix of views, how can it make it look kind of reasonable?

Roberto R.