{
  "id": 218281,
  "title": "Converting dicom to jpeg in R",
  "url": "/competitions/vinbigdata-chest-xray-abnormalities-detection/discussion/218281",
  "author_name": "Gayathri Nagarajan",
  "post_date": "2021-02-10T02:58:06",
  "votes": 4,
  "comment_count": 4,
  "views": 0,
  "content": "<p>Hi Team</p>\n<p>I see a lot of python notebooks here ,but Iam familiar with R and would want to convert all my train and test images into jpeg.Can someone help me with reference articles or steps I can follow?</p>\n<p>Thanks in advance for your time</p>\n<p>Regards<br>\nGayathri</p>",
  "messages": [
    {
      "id": 1194022,
      "postDate": "2021-02-10T02:58:06Z",
      "content": "<p>Hi Team</p>\n<p>I see a lot of python notebooks here ,but Iam familiar with R and would want to convert all my train and test images into jpeg.Can someone help me with reference articles or steps I can follow?</p>\n<p>Thanks in advance for your time</p>\n<p>Regards<br>\nGayathri</p>",
      "rawMarkdown": "Hi Team\n\nI see a lot of python notebooks here ,but Iam familiar with R and would want to convert all my train and test images into jpeg.Can someone help me with reference articles or steps I can follow?\n\nThanks in advance for your time\n\nRegards\nGayathri",
      "votes": 4
    },
    {
      "id": 1194932,
      "postDate": "2021-02-10T13:15:18.870Z",
      "content": "<p>There's a R Task View for <a href=\"https://cran.r-project.org/web/views/MedicalImaging.html\" target=\"_blank\">Medical Image Analysis</a>. As that task view points out, there's several packages that can read dicom files: oro.dicom, divest, fmri and tractor.base (I've also heard of <code>Radtools</code> (but know next to nothing about it). E.g. the oro.dicom package comes with a nice introductory <a href=\"https://cran.r-project.org/web/packages/oro.dicom/vignettes/dicom.pdf\" target=\"_blank\">vignette</a> that explains how to get started and also shows how to visualize plots. Once you have the array that defines the image in a dicom, that is essentially the same thing as a bmp image - sure, you may have to rescale it to 0:255 and may want to normalize it, but you can more or less hand it to the <code>image</code> function (see e.g. <a href=\"https://www.rdocumentation.org/packages/graphics/versions/3.6.2/topics/image\" target=\"_blank\">here</a> and <a href=\"https://stackoverflow.com/questions/59023354/how-do-i-write-a-matrix-as-a-raw-bitmap-in-r\" target=\"_blank\">here</a>). You should be able to save that by enclosing printing that image in <code>jpeg(...)</code> with the desired options and <code>dev.off()</code>.</p>\n<p>You may also want to do <a href=\"https://www.kaggle.com/search?q=VinBigData+in%3Adatasets\" target=\"_blank\">a search</a> whether someone else has already done all of this for you (assuming you like/trust their work).</p>",
      "rawMarkdown": "There's a R Task View for [Medical Image Analysis](https://cran.r-project.org/web/views/MedicalImaging.html). As that task view points out, there's several packages that can read dicom files: oro.dicom, divest, fmri and tractor.base (I've also heard of `Radtools` (but know next to nothing about it). E.g. the oro.dicom package comes with a nice introductory [vignette](https://cran.r-project.org/web/packages/oro.dicom/vignettes/dicom.pdf) that explains how to get started and also shows how to visualize plots. Once you have the array that defines the image in a dicom, that is essentially the same thing as a bmp image - sure, you may have to rescale it to 0:255 and may want to normalize it, but you can more or less hand it to the `image` function (see e.g. [here](https://www.rdocumentation.org/packages/graphics/versions/3.6.2/topics/image) and [here](https://stackoverflow.com/questions/59023354/how-do-i-write-a-matrix-as-a-raw-bitmap-in-r)). You should be able to save that by enclosing printing that image in `jpeg(...)` with the desired options and `dev.off()`.\n\nYou may also want to do [a search](https://www.kaggle.com/search?q=VinBigData+in%3Adatasets) whether someone else has already done all of this for you (assuming you like/trust their work).",
      "replies": [
        {
          "id": 1195176,
          "postDate": "2021-02-10T15:42:59.577Z",
          "content": "<p>Thanks a lot Bjorn.I will check them out. </p>",
          "rawMarkdown": "Thanks a lot Bjorn.I will check them out. "
        }
      ]
    },
    {
      "id": 1194811,
      "postDate": "2021-02-10T11:36:06.393Z",
      "content": "<p>Hi, I suggest you to take a look to the R package \"jpeg\" which contains the function \"writeJPEG\". Here there is the documentation with examples: <a href=\"https://cran.r-project.org/web/packages/jpeg/jpeg.pdf\" target=\"_blank\">https://cran.r-project.org/web/packages/jpeg/jpeg.pdf</a> Good luck!</p>",
      "rawMarkdown": "Hi, I suggest you to take a look to the R package \"jpeg\" which contains the function \"writeJPEG\". Here there is the documentation with examples: https://cran.r-project.org/web/packages/jpeg/jpeg.pdf Good luck!",
      "replies": [
        {
          "id": 1195177,
          "postDate": "2021-02-10T15:43:13.967Z",
          "content": "<p>Thanks Jorge.</p>",
          "rawMarkdown": "Thanks Jorge."
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 1194932,
      "author_name": "Björn",
      "author_url": "",
      "post_date": "2021-02-10T13:15:18.870000",
      "content": "<p>There's a R Task View for <a href=\"https://cran.r-project.org/web/views/MedicalImaging.html\" target=\"_blank\">Medical Image Analysis</a>. As that task view points out, there's several packages that can read dicom files: oro.dicom, divest, fmri and tractor.base (I've also heard of <code>Radtools</code> (but know next to nothing about it). E.g. the oro.dicom package comes with a nice introductory <a href=\"https://cran.r-project.org/web/packages/oro.dicom/vignettes/dicom.pdf\" target=\"_blank\">vignette</a> that explains how to get started and also shows how to visualize plots. Once you have the array that defines the image in a dicom, that is essentially the same thing as a bmp image - sure, you may have to rescale it to 0:255 and may want to normalize it, but you can more or less hand it to the <code>image</code> function (see e.g. <a href=\"https://www.rdocumentation.org/packages/graphics/versions/3.6.2/topics/image\" target=\"_blank\">here</a> and <a href=\"https://stackoverflow.com/questions/59023354/how-do-i-write-a-matrix-as-a-raw-bitmap-in-r\" target=\"_blank\">here</a>). You should be able to save that by enclosing printing that image in <code>jpeg(...)</code> with the desired options and <code>dev.off()</code>.</p>\n<p>You may also want to do <a href=\"https://www.kaggle.com/search?q=VinBigData+in%3Adatasets\" target=\"_blank\">a search</a> whether someone else has already done all of this for you (assuming you like/trust their work).</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1195176,
          "author_name": "Gayathri Nagarajan",
          "author_url": "",
          "post_date": "2021-02-10T15:42:59.577000",
          "content": "<p>Thanks a lot Bjorn.I will check them out. </p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1194811,
      "author_name": "Jorge Bueno Perez",
      "author_url": "",
      "post_date": "2021-02-10T11:36:06.393000",
      "content": "<p>Hi, I suggest you to take a look to the R package \"jpeg\" which contains the function \"writeJPEG\". Here there is the documentation with examples: <a href=\"https://cran.r-project.org/web/packages/jpeg/jpeg.pdf\" target=\"_blank\">https://cran.r-project.org/web/packages/jpeg/jpeg.pdf</a> Good luck!</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1195177,
          "author_name": "Gayathri Nagarajan",
          "author_url": "",
          "post_date": "2021-02-10T15:43:13.967000",
          "content": "<p>Thanks Jorge.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1194022": "Hi Team\n\nI see a lot of python notebooks here ,but Iam familiar with R and would want to convert all my train and test images into jpeg.Can someone help me with reference articles or steps I can follow?\n\nThanks in advance for your time\n\nRegards\nGayathri",
    "1194932": "There's a R Task View for [Medical Image Analysis](https://cran.r-project.org/web/views/MedicalImaging.html). As that task view points out, there's several packages that can read dicom files: oro.dicom, divest, fmri and tractor.base (I've also heard of `Radtools` (but know next to nothing about it). E.g. the oro.dicom package comes with a nice introductory [vignette](https://cran.r-project.org/web/packages/oro.dicom/vignettes/dicom.pdf) that explains how to get started and also shows how to visualize plots. Once you have the array that defines the image in a dicom, that is essentially the same thing as a bmp image - sure, you may have to rescale it to 0:255 and may want to normalize it, but you can more or less hand it to the `image` function (see e.g. [here](https://www.rdocumentation.org/packages/graphics/versions/3.6.2/topics/image) and [here](https://stackoverflow.com/questions/59023354/how-do-i-write-a-matrix-as-a-raw-bitmap-in-r)). You should be able to save that by enclosing printing that image in `jpeg(...)` with the desired options and `dev.off()`.\n\nYou may also want to do [a search](https://www.kaggle.com/search?q=VinBigData+in%3Adatasets) whether someone else has already done all of this for you (assuming you like/trust their work).",
    "1194811": "Hi, I suggest you to take a look to the R package \"jpeg\" which contains the function \"writeJPEG\". Here there is the documentation with examples: https://cran.r-project.org/web/packages/jpeg/jpeg.pdf Good luck!"
  }
}