Using image data to create a 3D Histogram











up vote
3
down vote

favorite












I have a black and white .tiff file of a beam spot:



Beam profile



I am trying to characterize the source in a Monte Carlo program, to do this I want to convert the image into a 3D Histogram with controllable bin size.



Haven't been able to figure out how to convert the image data to match Histogram3D input parameters, closest I've gotten so far are 3D plots using:



ListPlot3D[Reverse@ImageData@RemoveAlphaChannel@ColorConvert[beam1, "Grayscale"], AxesLabel -> {"x", "y", "intensity"}, PlotRange -> All]



Any pointers on how to go about this? Thanks!










share|improve this question


























    up vote
    3
    down vote

    favorite












    I have a black and white .tiff file of a beam spot:



    Beam profile



    I am trying to characterize the source in a Monte Carlo program, to do this I want to convert the image into a 3D Histogram with controllable bin size.



    Haven't been able to figure out how to convert the image data to match Histogram3D input parameters, closest I've gotten so far are 3D plots using:



    ListPlot3D[Reverse@ImageData@RemoveAlphaChannel@ColorConvert[beam1, "Grayscale"], AxesLabel -> {"x", "y", "intensity"}, PlotRange -> All]



    Any pointers on how to go about this? Thanks!










    share|improve this question
























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I have a black and white .tiff file of a beam spot:



      Beam profile



      I am trying to characterize the source in a Monte Carlo program, to do this I want to convert the image into a 3D Histogram with controllable bin size.



      Haven't been able to figure out how to convert the image data to match Histogram3D input parameters, closest I've gotten so far are 3D plots using:



      ListPlot3D[Reverse@ImageData@RemoveAlphaChannel@ColorConvert[beam1, "Grayscale"], AxesLabel -> {"x", "y", "intensity"}, PlotRange -> All]



      Any pointers on how to go about this? Thanks!










      share|improve this question













      I have a black and white .tiff file of a beam spot:



      Beam profile



      I am trying to characterize the source in a Monte Carlo program, to do this I want to convert the image into a 3D Histogram with controllable bin size.



      Haven't been able to figure out how to convert the image data to match Histogram3D input parameters, closest I've gotten so far are 3D plots using:



      ListPlot3D[Reverse@ImageData@RemoveAlphaChannel@ColorConvert[beam1, "Grayscale"], AxesLabel -> {"x", "y", "intensity"}, PlotRange -> All]



      Any pointers on how to go about this? Thanks!







      plotting image-processing histograms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 18:31









      avocado_gradient

      405




      405






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          5
          down vote



          accepted










          Method 1: Histogram3D



          Import and clean the image:



          i = Import["https://i.stack.imgur.com/uGWn6.jpg"];
          i = RemoveAlphaChannel@ColorConvert[i, "Grayscale"]


          Histogram3D looks at the number of points in the bins, but that is uniform for an image as indexes of pixels are uniform. So I guess besides that you want data weighted by pixel values:



          dataW=
          WeightedData[
          Flatten[Array[List,Reverse@ImageDimensions[i]],1],
          Flatten[ImageData[i],1]
          ]


          Now you can bin in a custom way:



          Histogram3D[dataW, {50, 60}, ColorFunction -> "Rainbow"]


          enter image description here



          With a little bit of style you can get it looking quite any way you want:



          Histogram3D[dataW,{30,35},
          ChartElementFunction->
          ChartElementDataFunction["ProfileCube","Profile"->2.,"TaperRatio"->0.6],
          ColorFunction->"Rainbow",ChartStyle->Opacity[.5],PlotTheme->"Marketing"]


          enter image description here



          Method 2: ListPlot3D



          You could achieve a similar result differently, in a bit hack-ish way. Define data as:



          data = ImageData[ImageResize[i, {30, 30}]];


          so ImageResize spec 30x30 gives effective number of bins in X and Y directions. Resizing an image is effectively binning (in your specific case).



          ListPlot3D[data,PlotRange->{{5,25},{10,25},All},InterpolationOrder->0,
          ColorFunction->"Rainbow",Filling->Bottom,Mesh->None]


          enter image description here






          share|improve this answer






























            up vote
            2
            down vote













            Add another data processing method



            im1=RemoveAlphaChannel[
            ColorConvert[Import["https://i.stack.imgur.com/uGWn6.jpg"],
            "Grayscale"]];
            data = ImageData[im1];
            dim = Dimensions[data];
            A = Flatten[
            Table[{i, j}, {i, dim[[2]]}, {j, dim[[1]]}, {k,
            PixelValue[im1, {i, j}, "Byte"]}], 2];

            Histogram3D[A, {{.5}, {2}}, ColorFunction -> Hue]


            fig1






            share|improve this answer





















              Your Answer





              StackExchange.ifUsing("editor", function () {
              return StackExchange.using("mathjaxEditing", function () {
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
              });
              });
              }, "mathjax-editing");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "387"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f186385%2fusing-image-data-to-create-a-3d-histogram%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              5
              down vote



              accepted










              Method 1: Histogram3D



              Import and clean the image:



              i = Import["https://i.stack.imgur.com/uGWn6.jpg"];
              i = RemoveAlphaChannel@ColorConvert[i, "Grayscale"]


              Histogram3D looks at the number of points in the bins, but that is uniform for an image as indexes of pixels are uniform. So I guess besides that you want data weighted by pixel values:



              dataW=
              WeightedData[
              Flatten[Array[List,Reverse@ImageDimensions[i]],1],
              Flatten[ImageData[i],1]
              ]


              Now you can bin in a custom way:



              Histogram3D[dataW, {50, 60}, ColorFunction -> "Rainbow"]


              enter image description here



              With a little bit of style you can get it looking quite any way you want:



              Histogram3D[dataW,{30,35},
              ChartElementFunction->
              ChartElementDataFunction["ProfileCube","Profile"->2.,"TaperRatio"->0.6],
              ColorFunction->"Rainbow",ChartStyle->Opacity[.5],PlotTheme->"Marketing"]


              enter image description here



              Method 2: ListPlot3D



              You could achieve a similar result differently, in a bit hack-ish way. Define data as:



              data = ImageData[ImageResize[i, {30, 30}]];


              so ImageResize spec 30x30 gives effective number of bins in X and Y directions. Resizing an image is effectively binning (in your specific case).



              ListPlot3D[data,PlotRange->{{5,25},{10,25},All},InterpolationOrder->0,
              ColorFunction->"Rainbow",Filling->Bottom,Mesh->None]


              enter image description here






              share|improve this answer



























                up vote
                5
                down vote



                accepted










                Method 1: Histogram3D



                Import and clean the image:



                i = Import["https://i.stack.imgur.com/uGWn6.jpg"];
                i = RemoveAlphaChannel@ColorConvert[i, "Grayscale"]


                Histogram3D looks at the number of points in the bins, but that is uniform for an image as indexes of pixels are uniform. So I guess besides that you want data weighted by pixel values:



                dataW=
                WeightedData[
                Flatten[Array[List,Reverse@ImageDimensions[i]],1],
                Flatten[ImageData[i],1]
                ]


                Now you can bin in a custom way:



                Histogram3D[dataW, {50, 60}, ColorFunction -> "Rainbow"]


                enter image description here



                With a little bit of style you can get it looking quite any way you want:



                Histogram3D[dataW,{30,35},
                ChartElementFunction->
                ChartElementDataFunction["ProfileCube","Profile"->2.,"TaperRatio"->0.6],
                ColorFunction->"Rainbow",ChartStyle->Opacity[.5],PlotTheme->"Marketing"]


                enter image description here



                Method 2: ListPlot3D



                You could achieve a similar result differently, in a bit hack-ish way. Define data as:



                data = ImageData[ImageResize[i, {30, 30}]];


                so ImageResize spec 30x30 gives effective number of bins in X and Y directions. Resizing an image is effectively binning (in your specific case).



                ListPlot3D[data,PlotRange->{{5,25},{10,25},All},InterpolationOrder->0,
                ColorFunction->"Rainbow",Filling->Bottom,Mesh->None]


                enter image description here






                share|improve this answer

























                  up vote
                  5
                  down vote



                  accepted







                  up vote
                  5
                  down vote



                  accepted






                  Method 1: Histogram3D



                  Import and clean the image:



                  i = Import["https://i.stack.imgur.com/uGWn6.jpg"];
                  i = RemoveAlphaChannel@ColorConvert[i, "Grayscale"]


                  Histogram3D looks at the number of points in the bins, but that is uniform for an image as indexes of pixels are uniform. So I guess besides that you want data weighted by pixel values:



                  dataW=
                  WeightedData[
                  Flatten[Array[List,Reverse@ImageDimensions[i]],1],
                  Flatten[ImageData[i],1]
                  ]


                  Now you can bin in a custom way:



                  Histogram3D[dataW, {50, 60}, ColorFunction -> "Rainbow"]


                  enter image description here



                  With a little bit of style you can get it looking quite any way you want:



                  Histogram3D[dataW,{30,35},
                  ChartElementFunction->
                  ChartElementDataFunction["ProfileCube","Profile"->2.,"TaperRatio"->0.6],
                  ColorFunction->"Rainbow",ChartStyle->Opacity[.5],PlotTheme->"Marketing"]


                  enter image description here



                  Method 2: ListPlot3D



                  You could achieve a similar result differently, in a bit hack-ish way. Define data as:



                  data = ImageData[ImageResize[i, {30, 30}]];


                  so ImageResize spec 30x30 gives effective number of bins in X and Y directions. Resizing an image is effectively binning (in your specific case).



                  ListPlot3D[data,PlotRange->{{5,25},{10,25},All},InterpolationOrder->0,
                  ColorFunction->"Rainbow",Filling->Bottom,Mesh->None]


                  enter image description here






                  share|improve this answer














                  Method 1: Histogram3D



                  Import and clean the image:



                  i = Import["https://i.stack.imgur.com/uGWn6.jpg"];
                  i = RemoveAlphaChannel@ColorConvert[i, "Grayscale"]


                  Histogram3D looks at the number of points in the bins, but that is uniform for an image as indexes of pixels are uniform. So I guess besides that you want data weighted by pixel values:



                  dataW=
                  WeightedData[
                  Flatten[Array[List,Reverse@ImageDimensions[i]],1],
                  Flatten[ImageData[i],1]
                  ]


                  Now you can bin in a custom way:



                  Histogram3D[dataW, {50, 60}, ColorFunction -> "Rainbow"]


                  enter image description here



                  With a little bit of style you can get it looking quite any way you want:



                  Histogram3D[dataW,{30,35},
                  ChartElementFunction->
                  ChartElementDataFunction["ProfileCube","Profile"->2.,"TaperRatio"->0.6],
                  ColorFunction->"Rainbow",ChartStyle->Opacity[.5],PlotTheme->"Marketing"]


                  enter image description here



                  Method 2: ListPlot3D



                  You could achieve a similar result differently, in a bit hack-ish way. Define data as:



                  data = ImageData[ImageResize[i, {30, 30}]];


                  so ImageResize spec 30x30 gives effective number of bins in X and Y directions. Resizing an image is effectively binning (in your specific case).



                  ListPlot3D[data,PlotRange->{{5,25},{10,25},All},InterpolationOrder->0,
                  ColorFunction->"Rainbow",Filling->Bottom,Mesh->None]


                  enter image description here







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 20 at 20:56

























                  answered Nov 20 at 19:59









                  Vitaliy Kaurov

                  56.8k6158276




                  56.8k6158276






















                      up vote
                      2
                      down vote













                      Add another data processing method



                      im1=RemoveAlphaChannel[
                      ColorConvert[Import["https://i.stack.imgur.com/uGWn6.jpg"],
                      "Grayscale"]];
                      data = ImageData[im1];
                      dim = Dimensions[data];
                      A = Flatten[
                      Table[{i, j}, {i, dim[[2]]}, {j, dim[[1]]}, {k,
                      PixelValue[im1, {i, j}, "Byte"]}], 2];

                      Histogram3D[A, {{.5}, {2}}, ColorFunction -> Hue]


                      fig1






                      share|improve this answer

























                        up vote
                        2
                        down vote













                        Add another data processing method



                        im1=RemoveAlphaChannel[
                        ColorConvert[Import["https://i.stack.imgur.com/uGWn6.jpg"],
                        "Grayscale"]];
                        data = ImageData[im1];
                        dim = Dimensions[data];
                        A = Flatten[
                        Table[{i, j}, {i, dim[[2]]}, {j, dim[[1]]}, {k,
                        PixelValue[im1, {i, j}, "Byte"]}], 2];

                        Histogram3D[A, {{.5}, {2}}, ColorFunction -> Hue]


                        fig1






                        share|improve this answer























                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          Add another data processing method



                          im1=RemoveAlphaChannel[
                          ColorConvert[Import["https://i.stack.imgur.com/uGWn6.jpg"],
                          "Grayscale"]];
                          data = ImageData[im1];
                          dim = Dimensions[data];
                          A = Flatten[
                          Table[{i, j}, {i, dim[[2]]}, {j, dim[[1]]}, {k,
                          PixelValue[im1, {i, j}, "Byte"]}], 2];

                          Histogram3D[A, {{.5}, {2}}, ColorFunction -> Hue]


                          fig1






                          share|improve this answer












                          Add another data processing method



                          im1=RemoveAlphaChannel[
                          ColorConvert[Import["https://i.stack.imgur.com/uGWn6.jpg"],
                          "Grayscale"]];
                          data = ImageData[im1];
                          dim = Dimensions[data];
                          A = Flatten[
                          Table[{i, j}, {i, dim[[2]]}, {j, dim[[1]]}, {k,
                          PixelValue[im1, {i, j}, "Byte"]}], 2];

                          Histogram3D[A, {{.5}, {2}}, ColorFunction -> Hue]


                          fig1







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 20 at 21:17









                          Alex Trounev

                          4,8601418




                          4,8601418






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f186385%2fusing-image-data-to-create-a-3d-histogram%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Сан-Квентин

                              Алькесар

                              Josef Freinademetz