Using image data to create a 3D Histogram
![Multi tool use Multi tool use](http://sgv.ssvwv.com/sg/ssvwvcomimagb.png)
Multi tool use
I have a black and white .tiff file of a beam spot:
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
add a comment |
I have a black and white .tiff file of a beam spot:
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
add a comment |
I have a black and white .tiff file of a beam spot:
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
I have a black and white .tiff file of a beam spot:
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
plotting image-processing histograms
asked Nov 20 '18 at 18:31
avocado_gradient
405
405
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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"]
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"]
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]
add a comment |
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]
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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"]
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"]
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]
add a comment |
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"]
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"]
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]
add a comment |
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"]
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"]
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]
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"]
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"]
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]
edited Nov 20 '18 at 20:56
answered Nov 20 '18 at 19:59
Vitaliy Kaurov
57k6158278
57k6158278
add a comment |
add a comment |
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]
add a comment |
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]
add a comment |
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]
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]
answered Nov 20 '18 at 21:17
![](https://i.stack.imgur.com/5xbWG.jpg?s=32&g=1)
![](https://i.stack.imgur.com/5xbWG.jpg?s=32&g=1)
Alex Trounev
6,1201419
6,1201419
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Nyq n fFYlVJeUR2rJHABK2Z,uigByB9X4vt3W2scMLN9,g