How to create meshes with multiple regions from 2D images?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I would like to import 2D images to Mathematica and to use them to create meshed regions which can then be used for FEM. I create the images in Adobe illustrator so can either import a vector based image or a bitmap/raster image. Importantly I need to provide different materials properties to the different regions meaning that I need to keep track of which boundary is which.
A typical image would be as follows where we have 3 different regions, and we need to track boundaries between light and medium, light and dark and dark and medium grey. To be consistent of course the boundaries need to match.
Vector graphics can be imported and visualised, however from illustrator I get spline objects which I cannot seem to mesh correctly.
Alternatively I can import bitmap images and then use these together with
ImageMesh
however this doesn't seem to work for multiple regions? I only get one region and not multiple ones.
At the moment am stuck and would appreciate any hints about how to solve this.
image-processing mesh finite-element-method
add a comment |Â
up vote
1
down vote
favorite
I would like to import 2D images to Mathematica and to use them to create meshed regions which can then be used for FEM. I create the images in Adobe illustrator so can either import a vector based image or a bitmap/raster image. Importantly I need to provide different materials properties to the different regions meaning that I need to keep track of which boundary is which.
A typical image would be as follows where we have 3 different regions, and we need to track boundaries between light and medium, light and dark and dark and medium grey. To be consistent of course the boundaries need to match.
Vector graphics can be imported and visualised, however from illustrator I get spline objects which I cannot seem to mesh correctly.
Alternatively I can import bitmap images and then use these together with
ImageMesh
however this doesn't seem to work for multiple regions? I only get one region and not multiple ones.
At the moment am stuck and would appreciate any hints about how to solve this.
image-processing mesh finite-element-method
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I would like to import 2D images to Mathematica and to use them to create meshed regions which can then be used for FEM. I create the images in Adobe illustrator so can either import a vector based image or a bitmap/raster image. Importantly I need to provide different materials properties to the different regions meaning that I need to keep track of which boundary is which.
A typical image would be as follows where we have 3 different regions, and we need to track boundaries between light and medium, light and dark and dark and medium grey. To be consistent of course the boundaries need to match.
Vector graphics can be imported and visualised, however from illustrator I get spline objects which I cannot seem to mesh correctly.
Alternatively I can import bitmap images and then use these together with
ImageMesh
however this doesn't seem to work for multiple regions? I only get one region and not multiple ones.
At the moment am stuck and would appreciate any hints about how to solve this.
image-processing mesh finite-element-method
I would like to import 2D images to Mathematica and to use them to create meshed regions which can then be used for FEM. I create the images in Adobe illustrator so can either import a vector based image or a bitmap/raster image. Importantly I need to provide different materials properties to the different regions meaning that I need to keep track of which boundary is which.
A typical image would be as follows where we have 3 different regions, and we need to track boundaries between light and medium, light and dark and dark and medium grey. To be consistent of course the boundaries need to match.
Vector graphics can be imported and visualised, however from illustrator I get spline objects which I cannot seem to mesh correctly.
Alternatively I can import bitmap images and then use these together with
ImageMesh
however this doesn't seem to work for multiple regions? I only get one region and not multiple ones.
At the moment am stuck and would appreciate any hints about how to solve this.
image-processing mesh finite-element-method
image-processing mesh finite-element-method
edited 1 hour ago
asked 3 hours ago
Dunlop
2,02421134
2,02421134
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
If you don't mind using ImageMesh
, you can use simple image processing operations to split the bitmap into separate binary mask images for each shape:
img = Import["https://i.stack.imgur.com/NRoOd.png"];
components =
ComponentMeasurements[ArrayComponents[ImageData@img, 2],
"Mask", #Area > 10000 &];
Explanation: ArrayComponents
assigns identical labels to connected components with the same color. ComponentMeasurements
can then calculate measurements for each label, and the mask
measurement simply returns a binary 1/0 mask. Your image is anti-aliased, so I get a lot of small components at the edges of each shape - that's why I need the #Area>10000 &
filter.
This returns a list of labelIndex -> mask
elements, which we can then turn into separate meshes:
meshes = components /. (idx_ -> mask_) :> ImageMesh[Image[mask]]
Vector graphics can be imported and visualised, however from illustrator I get spline objects which I cannot seem to mesh correctly.
Can you post a sample spline? This is taken more or less from the documentation and seems to work fine:
g = Graphics[BSplineCurve[0, 0, 1, -1, 2, -1, 3,
0, 4, -2, 5, 0, SplineClosed -> True], Circle[2, 1]]
BoundaryDiscretizeGraphics[g]
Do you mean from Adobe Illustrator software?
– Jose E Calderon
2 hours ago
@JoseECalderon Yes, edited now in the question.
– Dunlop
1 hour ago
@Niki Estner - I understand now Anti-Aliasing I should turn off when exporting a bitmap (forgot about that). In terms of vector images, I see that it works well now, but not when the lines overlap e.g. `g = Graphics[BSplineCurve[0, 0, 1, -1, 2, -1, 3, 0, 4, -2, 5, 0, SplineClosed -> True], Circle[2, 0]] BoundaryDiscretizeGraphics[g]'. I guess I need to separate the regions. I will have a bit more of a play and see what I can come up with. Thanks for your help!
– Dunlop
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
If you don't mind using ImageMesh
, you can use simple image processing operations to split the bitmap into separate binary mask images for each shape:
img = Import["https://i.stack.imgur.com/NRoOd.png"];
components =
ComponentMeasurements[ArrayComponents[ImageData@img, 2],
"Mask", #Area > 10000 &];
Explanation: ArrayComponents
assigns identical labels to connected components with the same color. ComponentMeasurements
can then calculate measurements for each label, and the mask
measurement simply returns a binary 1/0 mask. Your image is anti-aliased, so I get a lot of small components at the edges of each shape - that's why I need the #Area>10000 &
filter.
This returns a list of labelIndex -> mask
elements, which we can then turn into separate meshes:
meshes = components /. (idx_ -> mask_) :> ImageMesh[Image[mask]]
Vector graphics can be imported and visualised, however from illustrator I get spline objects which I cannot seem to mesh correctly.
Can you post a sample spline? This is taken more or less from the documentation and seems to work fine:
g = Graphics[BSplineCurve[0, 0, 1, -1, 2, -1, 3,
0, 4, -2, 5, 0, SplineClosed -> True], Circle[2, 1]]
BoundaryDiscretizeGraphics[g]
Do you mean from Adobe Illustrator software?
– Jose E Calderon
2 hours ago
@JoseECalderon Yes, edited now in the question.
– Dunlop
1 hour ago
@Niki Estner - I understand now Anti-Aliasing I should turn off when exporting a bitmap (forgot about that). In terms of vector images, I see that it works well now, but not when the lines overlap e.g. `g = Graphics[BSplineCurve[0, 0, 1, -1, 2, -1, 3, 0, 4, -2, 5, 0, SplineClosed -> True], Circle[2, 0]] BoundaryDiscretizeGraphics[g]'. I guess I need to separate the regions. I will have a bit more of a play and see what I can come up with. Thanks for your help!
– Dunlop
1 hour ago
add a comment |Â
up vote
3
down vote
If you don't mind using ImageMesh
, you can use simple image processing operations to split the bitmap into separate binary mask images for each shape:
img = Import["https://i.stack.imgur.com/NRoOd.png"];
components =
ComponentMeasurements[ArrayComponents[ImageData@img, 2],
"Mask", #Area > 10000 &];
Explanation: ArrayComponents
assigns identical labels to connected components with the same color. ComponentMeasurements
can then calculate measurements for each label, and the mask
measurement simply returns a binary 1/0 mask. Your image is anti-aliased, so I get a lot of small components at the edges of each shape - that's why I need the #Area>10000 &
filter.
This returns a list of labelIndex -> mask
elements, which we can then turn into separate meshes:
meshes = components /. (idx_ -> mask_) :> ImageMesh[Image[mask]]
Vector graphics can be imported and visualised, however from illustrator I get spline objects which I cannot seem to mesh correctly.
Can you post a sample spline? This is taken more or less from the documentation and seems to work fine:
g = Graphics[BSplineCurve[0, 0, 1, -1, 2, -1, 3,
0, 4, -2, 5, 0, SplineClosed -> True], Circle[2, 1]]
BoundaryDiscretizeGraphics[g]
Do you mean from Adobe Illustrator software?
– Jose E Calderon
2 hours ago
@JoseECalderon Yes, edited now in the question.
– Dunlop
1 hour ago
@Niki Estner - I understand now Anti-Aliasing I should turn off when exporting a bitmap (forgot about that). In terms of vector images, I see that it works well now, but not when the lines overlap e.g. `g = Graphics[BSplineCurve[0, 0, 1, -1, 2, -1, 3, 0, 4, -2, 5, 0, SplineClosed -> True], Circle[2, 0]] BoundaryDiscretizeGraphics[g]'. I guess I need to separate the regions. I will have a bit more of a play and see what I can come up with. Thanks for your help!
– Dunlop
1 hour ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
If you don't mind using ImageMesh
, you can use simple image processing operations to split the bitmap into separate binary mask images for each shape:
img = Import["https://i.stack.imgur.com/NRoOd.png"];
components =
ComponentMeasurements[ArrayComponents[ImageData@img, 2],
"Mask", #Area > 10000 &];
Explanation: ArrayComponents
assigns identical labels to connected components with the same color. ComponentMeasurements
can then calculate measurements for each label, and the mask
measurement simply returns a binary 1/0 mask. Your image is anti-aliased, so I get a lot of small components at the edges of each shape - that's why I need the #Area>10000 &
filter.
This returns a list of labelIndex -> mask
elements, which we can then turn into separate meshes:
meshes = components /. (idx_ -> mask_) :> ImageMesh[Image[mask]]
Vector graphics can be imported and visualised, however from illustrator I get spline objects which I cannot seem to mesh correctly.
Can you post a sample spline? This is taken more or less from the documentation and seems to work fine:
g = Graphics[BSplineCurve[0, 0, 1, -1, 2, -1, 3,
0, 4, -2, 5, 0, SplineClosed -> True], Circle[2, 1]]
BoundaryDiscretizeGraphics[g]
If you don't mind using ImageMesh
, you can use simple image processing operations to split the bitmap into separate binary mask images for each shape:
img = Import["https://i.stack.imgur.com/NRoOd.png"];
components =
ComponentMeasurements[ArrayComponents[ImageData@img, 2],
"Mask", #Area > 10000 &];
Explanation: ArrayComponents
assigns identical labels to connected components with the same color. ComponentMeasurements
can then calculate measurements for each label, and the mask
measurement simply returns a binary 1/0 mask. Your image is anti-aliased, so I get a lot of small components at the edges of each shape - that's why I need the #Area>10000 &
filter.
This returns a list of labelIndex -> mask
elements, which we can then turn into separate meshes:
meshes = components /. (idx_ -> mask_) :> ImageMesh[Image[mask]]
Vector graphics can be imported and visualised, however from illustrator I get spline objects which I cannot seem to mesh correctly.
Can you post a sample spline? This is taken more or less from the documentation and seems to work fine:
g = Graphics[BSplineCurve[0, 0, 1, -1, 2, -1, 3,
0, 4, -2, 5, 0, SplineClosed -> True], Circle[2, 1]]
BoundaryDiscretizeGraphics[g]
edited 2 hours ago
answered 3 hours ago
Niki Estner
30k373130
30k373130
Do you mean from Adobe Illustrator software?
– Jose E Calderon
2 hours ago
@JoseECalderon Yes, edited now in the question.
– Dunlop
1 hour ago
@Niki Estner - I understand now Anti-Aliasing I should turn off when exporting a bitmap (forgot about that). In terms of vector images, I see that it works well now, but not when the lines overlap e.g. `g = Graphics[BSplineCurve[0, 0, 1, -1, 2, -1, 3, 0, 4, -2, 5, 0, SplineClosed -> True], Circle[2, 0]] BoundaryDiscretizeGraphics[g]'. I guess I need to separate the regions. I will have a bit more of a play and see what I can come up with. Thanks for your help!
– Dunlop
1 hour ago
add a comment |Â
Do you mean from Adobe Illustrator software?
– Jose E Calderon
2 hours ago
@JoseECalderon Yes, edited now in the question.
– Dunlop
1 hour ago
@Niki Estner - I understand now Anti-Aliasing I should turn off when exporting a bitmap (forgot about that). In terms of vector images, I see that it works well now, but not when the lines overlap e.g. `g = Graphics[BSplineCurve[0, 0, 1, -1, 2, -1, 3, 0, 4, -2, 5, 0, SplineClosed -> True], Circle[2, 0]] BoundaryDiscretizeGraphics[g]'. I guess I need to separate the regions. I will have a bit more of a play and see what I can come up with. Thanks for your help!
– Dunlop
1 hour ago
Do you mean from Adobe Illustrator software?
– Jose E Calderon
2 hours ago
Do you mean from Adobe Illustrator software?
– Jose E Calderon
2 hours ago
@JoseECalderon Yes, edited now in the question.
– Dunlop
1 hour ago
@JoseECalderon Yes, edited now in the question.
– Dunlop
1 hour ago
@Niki Estner - I understand now Anti-Aliasing I should turn off when exporting a bitmap (forgot about that). In terms of vector images, I see that it works well now, but not when the lines overlap e.g. `g = Graphics[BSplineCurve[0, 0, 1, -1, 2, -1, 3, 0, 4, -2, 5, 0, SplineClosed -> True], Circle[2, 0]] BoundaryDiscretizeGraphics[g]'. I guess I need to separate the regions. I will have a bit more of a play and see what I can come up with. Thanks for your help!
– Dunlop
1 hour ago
@Niki Estner - I understand now Anti-Aliasing I should turn off when exporting a bitmap (forgot about that). In terms of vector images, I see that it works well now, but not when the lines overlap e.g. `g = Graphics[BSplineCurve[0, 0, 1, -1, 2, -1, 3, 0, 4, -2, 5, 0, SplineClosed -> True], Circle[2, 0]] BoundaryDiscretizeGraphics[g]'. I guess I need to separate the regions. I will have a bit more of a play and see what I can come up with. Thanks for your help!
– Dunlop
1 hour ago
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185064%2fhow-to-create-meshes-with-multiple-regions-from-2d-images%23new-answer', 'question_page');
);
Post as a guest
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
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
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