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:
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 |
up vote
3
down vote
favorite
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 |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
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 yesterday
avocado_gradient
405
405
add a comment |
add a comment |
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"]
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 |
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]
add a comment |
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"]
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 |
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"]
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 |
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"]
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 yesterday
answered yesterday
Vitaliy Kaurov
56.8k6158276
56.8k6158276
add a comment |
add a comment |
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]
add a comment |
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]
add a comment |
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]
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 yesterday
Alex Trounev
4,6401418
4,6401418
add a comment |
add a comment |
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