Can Mathematica be used to create an Artistic 3D extrusion from a 2D image and wrap a line pattern around it?












8












$begingroup$


So here's somewhat of the general goal first: Here's an example of image-based line patterns
Here is an example of an artists work in creating imagery using only lines
bent as though distorted by an actual 3D form.



Seemed to me that something like this could be accomplished in Mathematica using a 2D image and a line pattern.



Processing the 2D image in such a way as to maintain the edges then use some of the original pixel luminance to extrude a depth map. Then use this new 3D form to deform the line pattern and create this artistic effect.



Here's an image to begin with:link



Here's some code that may (or may not) get the creative juices flowing.
converting Images



In my application, I will need to use a second image to warp over the new 3D form because the pattern effect is going to be very different than this example image.










share|improve this question











$endgroup$








  • 2




    $begingroup$
    Depth map is also easily done via resources.wolframcloud.com/NeuralNetRepository/resources/…
    $endgroup$
    – Carl Lange
    9 hours ago










  • $begingroup$
    and this can be done for the edge details: Manipulate[EdgeDetect[image, r, t], {{r, 2, "radius"}, 1, 10}, {{t, 0.1, "threshold"}, 0, 0.5}]
    $endgroup$
    – R Hall
    9 hours ago










  • $begingroup$
    I do need to be able to convolve an image of lines because although the example image is nice, the use case is different and thus the line pattern would have to be different.
    $endgroup$
    – R Hall
    8 hours ago






  • 1




    $begingroup$
    You should also give ImageRestyle a shot. If it has enough time I think it could do a really nice job of this.
    $endgroup$
    – Carl Lange
    8 hours ago
















8












$begingroup$


So here's somewhat of the general goal first: Here's an example of image-based line patterns
Here is an example of an artists work in creating imagery using only lines
bent as though distorted by an actual 3D form.



Seemed to me that something like this could be accomplished in Mathematica using a 2D image and a line pattern.



Processing the 2D image in such a way as to maintain the edges then use some of the original pixel luminance to extrude a depth map. Then use this new 3D form to deform the line pattern and create this artistic effect.



Here's an image to begin with:link



Here's some code that may (or may not) get the creative juices flowing.
converting Images



In my application, I will need to use a second image to warp over the new 3D form because the pattern effect is going to be very different than this example image.










share|improve this question











$endgroup$








  • 2




    $begingroup$
    Depth map is also easily done via resources.wolframcloud.com/NeuralNetRepository/resources/…
    $endgroup$
    – Carl Lange
    9 hours ago










  • $begingroup$
    and this can be done for the edge details: Manipulate[EdgeDetect[image, r, t], {{r, 2, "radius"}, 1, 10}, {{t, 0.1, "threshold"}, 0, 0.5}]
    $endgroup$
    – R Hall
    9 hours ago










  • $begingroup$
    I do need to be able to convolve an image of lines because although the example image is nice, the use case is different and thus the line pattern would have to be different.
    $endgroup$
    – R Hall
    8 hours ago






  • 1




    $begingroup$
    You should also give ImageRestyle a shot. If it has enough time I think it could do a really nice job of this.
    $endgroup$
    – Carl Lange
    8 hours ago














8












8








8


4



$begingroup$


So here's somewhat of the general goal first: Here's an example of image-based line patterns
Here is an example of an artists work in creating imagery using only lines
bent as though distorted by an actual 3D form.



Seemed to me that something like this could be accomplished in Mathematica using a 2D image and a line pattern.



Processing the 2D image in such a way as to maintain the edges then use some of the original pixel luminance to extrude a depth map. Then use this new 3D form to deform the line pattern and create this artistic effect.



Here's an image to begin with:link



Here's some code that may (or may not) get the creative juices flowing.
converting Images



In my application, I will need to use a second image to warp over the new 3D form because the pattern effect is going to be very different than this example image.










share|improve this question











$endgroup$




So here's somewhat of the general goal first: Here's an example of image-based line patterns
Here is an example of an artists work in creating imagery using only lines
bent as though distorted by an actual 3D form.



Seemed to me that something like this could be accomplished in Mathematica using a 2D image and a line pattern.



Processing the 2D image in such a way as to maintain the edges then use some of the original pixel luminance to extrude a depth map. Then use this new 3D form to deform the line pattern and create this artistic effect.



Here's an image to begin with:link



Here's some code that may (or may not) get the creative juices flowing.
converting Images



In my application, I will need to use a second image to warp over the new 3D form because the pattern effect is going to be very different than this example image.







image-processing imagerestyle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 hours ago







R Hall

















asked 9 hours ago









R HallR Hall

1,97912346




1,97912346








  • 2




    $begingroup$
    Depth map is also easily done via resources.wolframcloud.com/NeuralNetRepository/resources/…
    $endgroup$
    – Carl Lange
    9 hours ago










  • $begingroup$
    and this can be done for the edge details: Manipulate[EdgeDetect[image, r, t], {{r, 2, "radius"}, 1, 10}, {{t, 0.1, "threshold"}, 0, 0.5}]
    $endgroup$
    – R Hall
    9 hours ago










  • $begingroup$
    I do need to be able to convolve an image of lines because although the example image is nice, the use case is different and thus the line pattern would have to be different.
    $endgroup$
    – R Hall
    8 hours ago






  • 1




    $begingroup$
    You should also give ImageRestyle a shot. If it has enough time I think it could do a really nice job of this.
    $endgroup$
    – Carl Lange
    8 hours ago














  • 2




    $begingroup$
    Depth map is also easily done via resources.wolframcloud.com/NeuralNetRepository/resources/…
    $endgroup$
    – Carl Lange
    9 hours ago










  • $begingroup$
    and this can be done for the edge details: Manipulate[EdgeDetect[image, r, t], {{r, 2, "radius"}, 1, 10}, {{t, 0.1, "threshold"}, 0, 0.5}]
    $endgroup$
    – R Hall
    9 hours ago










  • $begingroup$
    I do need to be able to convolve an image of lines because although the example image is nice, the use case is different and thus the line pattern would have to be different.
    $endgroup$
    – R Hall
    8 hours ago






  • 1




    $begingroup$
    You should also give ImageRestyle a shot. If it has enough time I think it could do a really nice job of this.
    $endgroup$
    – Carl Lange
    8 hours ago








2




2




$begingroup$
Depth map is also easily done via resources.wolframcloud.com/NeuralNetRepository/resources/…
$endgroup$
– Carl Lange
9 hours ago




$begingroup$
Depth map is also easily done via resources.wolframcloud.com/NeuralNetRepository/resources/…
$endgroup$
– Carl Lange
9 hours ago












$begingroup$
and this can be done for the edge details: Manipulate[EdgeDetect[image, r, t], {{r, 2, "radius"}, 1, 10}, {{t, 0.1, "threshold"}, 0, 0.5}]
$endgroup$
– R Hall
9 hours ago




$begingroup$
and this can be done for the edge details: Manipulate[EdgeDetect[image, r, t], {{r, 2, "radius"}, 1, 10}, {{t, 0.1, "threshold"}, 0, 0.5}]
$endgroup$
– R Hall
9 hours ago












$begingroup$
I do need to be able to convolve an image of lines because although the example image is nice, the use case is different and thus the line pattern would have to be different.
$endgroup$
– R Hall
8 hours ago




$begingroup$
I do need to be able to convolve an image of lines because although the example image is nice, the use case is different and thus the line pattern would have to be different.
$endgroup$
– R Hall
8 hours ago




1




1




$begingroup$
You should also give ImageRestyle a shot. If it has enough time I think it could do a really nice job of this.
$endgroup$
– Carl Lange
8 hours ago




$begingroup$
You should also give ImageRestyle a shot. If it has enough time I think it could do a really nice job of this.
$endgroup$
– Carl Lange
8 hours ago










4 Answers
4






active

oldest

votes


















10












$begingroup$

Other approach using NetModel:



net = NetModel[
"Single-Image Depth Perception Net Trained on NYU Depth V2 and
Depth in the Wild Data"];


enter image description here



Create depthMap and build an interpolation function:



depthMap = net[image];    
depthFunc =
Interpolation[
Flatten[MapIndexed[{#2, #1} &, -Reverse@depthMap, {2}], 1]];


Apply depthFunc to line segments and plot it:



lines = Table[{j, i, 7 depthFunc[i, j]}, {i, 1, 240, 4}, {j, 1, 320, 
3}];

lineart3d =
Graphics3D[{AbsoluteThickness[2],
GeometricTransformation[Line[lines],
RotationTransform[-Pi/12, {1, 0, 0}]]}, ViewPoint -> Top,
ViewProjection -> "Orthographic", Boxed -> False, ImageSize -> 500]


enter image description here



You can rasterize if you want a 2d image:



Rasterize[lineart3d, ImageResolution -> 300]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    +1 Nice work halmir! I do need to change the type of line pattern from the example image, so if you can edit your answer to allow for that we may just have a winner!
    $endgroup$
    – R Hall
    7 hours ago






  • 1




    $begingroup$
    You could modify magnifying value and allow negative.
    $endgroup$
    – halmir
    7 hours ago



















8












$begingroup$

Here's my attempt, which uses the neural net Carl Lange referred to, plots mesh lines with ListPlot3D, and finds a 'nice' view point to see the lines.



net = NetModel["Single-Image Depth Perception Net Trained on NYU Depth V2 and Depth in the Wild Data"];
img = Import["https://www.liveenhanced.com/wp-content/uploads/2017/12/Beauty-Of-Bears-Ears-National-Monument.jpg"];
{x, y} = ImageDimensions[img];

height = 1 - Rescale[ArrayResample[net[img], Round[{x, y}/4]]];

meshlines = ListPlot3D[
400 Reverse[height],
Mesh -> 100, MeshFunctions -> {#2 &},
DataRange -> {{0, x}, {0, y}}, PlotStyle -> None
];

mr = DiscretizeGraphics[meshlines,
MeshCellStyle -> {1 -> Black}, PlotTheme -> "Lines"];

M = MomentOfInertia[Point[MeshCoordinates[mr]]];

{v1, v2} = Rest[Eigenvectors[M]];

Show[mr, ViewVertical -> {0, 0, -1},
ViewPoint -> {0, 10, 10} Normalize[Cross[v1, v2]]]


enter image description here



It might be possible to accentuate the detail better by finding a suitable power to raise height to, e.g. height^2, etc.





Here's a way to project into 2D, rather than adjusting the ViewPoint in 3D:



MeshRegion[
-PrincipalComponents[MeshCoordinates[mr]][[All, 1 ;; 2]],
MeshCells[mr, 1],
PlotTheme -> "Lines", MeshCellStyle -> {1 -> Black}
]


enter image description here





Here's a way to add some smooth edge lines. There's room for improvement here -- both in the implementation and output -- and the high degree splines take some time to render.



The idea is to edge detect, break up branch points to get a collection of path curves, approximate each path with a smooth curve, then map into 3D.



boundary = Thinning[EdgeDetect[im, 10]];

brokenboundary = ImageMultiply[boundary, ColorNegate[MorphologicalBranchPoints[boundary]]];

ones = Position[Reverse[Transpose[ImageData[brokenboundary]], {2}], 1];

g = NearestNeighborGraph[ones, {All, 1.5}];

comps = WeaklyConnectedGraphComponents[g];

paths = FindHamiltonianPath /@ comps;

hmap = ListInterpolation[400 Reverse[Transpose[height], {2}], {{0, x}, {0, y}}];
paths3d = Apply[{##, hmap[##]} &, paths, {2}];

Show[
mr,
Graphics3D[{AbsoluteThickness[1], BSplineCurve[#, SplineDegree -> Length[#] - 1] & /@ paths3d}],
ViewVertical -> {0, 0, -1},
ViewPoint -> {0, 10, 10} Normalize[Cross[v1, v2]]
]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    This is really nice, great work!
    $endgroup$
    – Carl Lange
    8 hours ago










  • $begingroup$
    @CarlLange Thanks!
    $endgroup$
    – Chip Hurst
    8 hours ago










  • $begingroup$
    +1 Nice work Chip! In my case, I do need to use an image for the pattern of lines since that will need to be different. Possibly adding EdgeDetect to gain a more defined shape definition like the example image.
    $endgroup$
    – R Hall
    7 hours ago










  • $begingroup$
    @RHall do you mean have some edge lines in addition to the horizontal ones?
    $endgroup$
    – Chip Hurst
    6 hours ago










  • $begingroup$
    Yes, I have a large number of pattern images that I would use instead of the example provided.
    $endgroup$
    – R Hall
    6 hours ago



















7












$begingroup$

We can get some of the way there by using ListContourPlot.



enter image description here



Now we grab a neural network to get the depth map for us:



net = NetModel[
"Single-Image Depth Perception Net Trained on NYU Depth V2 and Depth in the Wild Data"]


Now we can see our depth map:



enter image description here



Great. Let's put that in a list, after a little bit of cajoling (Blurring, ImageAdjusting so it's all between 0 and 1)



depth = ImageData@Blur@ImageAdjust@Image@net[i]


Now we can try and ListContourPlot it:



ListContourPlot[Reverse@depth, Contours -> 25, 
ColorFunction -> (White &), Axes -> None, Frame -> None,
AspectRatio -> ImageAspectRatio@i]


enter image description here



Or, with the image you linked to:



enter image description here



Other options I thought about but didn't execute on:




  • convolving an image of lines with the depth map

  • converting the depthmap to a weighted graph and using FindShortestPath (I still like this one, but I think the output would be pretty similar to this attempt)

  • There's always good old ImageRestyle, which if given enough time might do a really nice job of this...






share|improve this answer











$endgroup$













  • $begingroup$
    I like this! I do need to be able to convolve an image of lines though because although the example image is nice, the use case is different and thus the line pattern would have to be different.
    $endgroup$
    – R Hall
    8 hours ago



















3












$begingroup$

ImageRestyle is an obvious thing to try:



Import["https://www.liveenhanced.com/wp-content/uploads/2017/12/Beauty-Of-Bears-Ears-National-Monument.jpg"];
imgBW = ColorConvert[img, "Grayscale"];
imgLines = Import["https://i.stack.imgur.com/bR9kS.png"];
ColorConvert[ImageRestyle[imgBW, imgLines], "Grayscale"]


enter image description here



If you are willing to wait a while, ImageRestyle has options:



resty = ImageRestyle[imgBW, imgLines, PerformanceGoal -> "Quality"]; 
ColorConvert[resty, "Grayscale"]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Good attempt Bill, Trying this method doesn't provide the distorted pattern only. Seems some of the first image is left to show through the effect. The line pattern should end up as a single distorted 3D object.
    $endgroup$
    – R Hall
    5 hours ago













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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f193043%2fcan-mathematica-be-used-to-create-an-artistic-3d-extrusion-from-a-2d-image-and-w%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























4 Answers
4






active

oldest

votes








4 Answers
4






active

oldest

votes









active

oldest

votes






active

oldest

votes









10












$begingroup$

Other approach using NetModel:



net = NetModel[
"Single-Image Depth Perception Net Trained on NYU Depth V2 and
Depth in the Wild Data"];


enter image description here



Create depthMap and build an interpolation function:



depthMap = net[image];    
depthFunc =
Interpolation[
Flatten[MapIndexed[{#2, #1} &, -Reverse@depthMap, {2}], 1]];


Apply depthFunc to line segments and plot it:



lines = Table[{j, i, 7 depthFunc[i, j]}, {i, 1, 240, 4}, {j, 1, 320, 
3}];

lineart3d =
Graphics3D[{AbsoluteThickness[2],
GeometricTransformation[Line[lines],
RotationTransform[-Pi/12, {1, 0, 0}]]}, ViewPoint -> Top,
ViewProjection -> "Orthographic", Boxed -> False, ImageSize -> 500]


enter image description here



You can rasterize if you want a 2d image:



Rasterize[lineart3d, ImageResolution -> 300]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    +1 Nice work halmir! I do need to change the type of line pattern from the example image, so if you can edit your answer to allow for that we may just have a winner!
    $endgroup$
    – R Hall
    7 hours ago






  • 1




    $begingroup$
    You could modify magnifying value and allow negative.
    $endgroup$
    – halmir
    7 hours ago
















10












$begingroup$

Other approach using NetModel:



net = NetModel[
"Single-Image Depth Perception Net Trained on NYU Depth V2 and
Depth in the Wild Data"];


enter image description here



Create depthMap and build an interpolation function:



depthMap = net[image];    
depthFunc =
Interpolation[
Flatten[MapIndexed[{#2, #1} &, -Reverse@depthMap, {2}], 1]];


Apply depthFunc to line segments and plot it:



lines = Table[{j, i, 7 depthFunc[i, j]}, {i, 1, 240, 4}, {j, 1, 320, 
3}];

lineart3d =
Graphics3D[{AbsoluteThickness[2],
GeometricTransformation[Line[lines],
RotationTransform[-Pi/12, {1, 0, 0}]]}, ViewPoint -> Top,
ViewProjection -> "Orthographic", Boxed -> False, ImageSize -> 500]


enter image description here



You can rasterize if you want a 2d image:



Rasterize[lineart3d, ImageResolution -> 300]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    +1 Nice work halmir! I do need to change the type of line pattern from the example image, so if you can edit your answer to allow for that we may just have a winner!
    $endgroup$
    – R Hall
    7 hours ago






  • 1




    $begingroup$
    You could modify magnifying value and allow negative.
    $endgroup$
    – halmir
    7 hours ago














10












10








10





$begingroup$

Other approach using NetModel:



net = NetModel[
"Single-Image Depth Perception Net Trained on NYU Depth V2 and
Depth in the Wild Data"];


enter image description here



Create depthMap and build an interpolation function:



depthMap = net[image];    
depthFunc =
Interpolation[
Flatten[MapIndexed[{#2, #1} &, -Reverse@depthMap, {2}], 1]];


Apply depthFunc to line segments and plot it:



lines = Table[{j, i, 7 depthFunc[i, j]}, {i, 1, 240, 4}, {j, 1, 320, 
3}];

lineart3d =
Graphics3D[{AbsoluteThickness[2],
GeometricTransformation[Line[lines],
RotationTransform[-Pi/12, {1, 0, 0}]]}, ViewPoint -> Top,
ViewProjection -> "Orthographic", Boxed -> False, ImageSize -> 500]


enter image description here



You can rasterize if you want a 2d image:



Rasterize[lineart3d, ImageResolution -> 300]


enter image description here






share|improve this answer











$endgroup$



Other approach using NetModel:



net = NetModel[
"Single-Image Depth Perception Net Trained on NYU Depth V2 and
Depth in the Wild Data"];


enter image description here



Create depthMap and build an interpolation function:



depthMap = net[image];    
depthFunc =
Interpolation[
Flatten[MapIndexed[{#2, #1} &, -Reverse@depthMap, {2}], 1]];


Apply depthFunc to line segments and plot it:



lines = Table[{j, i, 7 depthFunc[i, j]}, {i, 1, 240, 4}, {j, 1, 320, 
3}];

lineart3d =
Graphics3D[{AbsoluteThickness[2],
GeometricTransformation[Line[lines],
RotationTransform[-Pi/12, {1, 0, 0}]]}, ViewPoint -> Top,
ViewProjection -> "Orthographic", Boxed -> False, ImageSize -> 500]


enter image description here



You can rasterize if you want a 2d image:



Rasterize[lineart3d, ImageResolution -> 300]


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited 7 hours ago

























answered 7 hours ago









halmirhalmir

10.5k2544




10.5k2544












  • $begingroup$
    +1 Nice work halmir! I do need to change the type of line pattern from the example image, so if you can edit your answer to allow for that we may just have a winner!
    $endgroup$
    – R Hall
    7 hours ago






  • 1




    $begingroup$
    You could modify magnifying value and allow negative.
    $endgroup$
    – halmir
    7 hours ago


















  • $begingroup$
    +1 Nice work halmir! I do need to change the type of line pattern from the example image, so if you can edit your answer to allow for that we may just have a winner!
    $endgroup$
    – R Hall
    7 hours ago






  • 1




    $begingroup$
    You could modify magnifying value and allow negative.
    $endgroup$
    – halmir
    7 hours ago
















$begingroup$
+1 Nice work halmir! I do need to change the type of line pattern from the example image, so if you can edit your answer to allow for that we may just have a winner!
$endgroup$
– R Hall
7 hours ago




$begingroup$
+1 Nice work halmir! I do need to change the type of line pattern from the example image, so if you can edit your answer to allow for that we may just have a winner!
$endgroup$
– R Hall
7 hours ago




1




1




$begingroup$
You could modify magnifying value and allow negative.
$endgroup$
– halmir
7 hours ago




$begingroup$
You could modify magnifying value and allow negative.
$endgroup$
– halmir
7 hours ago











8












$begingroup$

Here's my attempt, which uses the neural net Carl Lange referred to, plots mesh lines with ListPlot3D, and finds a 'nice' view point to see the lines.



net = NetModel["Single-Image Depth Perception Net Trained on NYU Depth V2 and Depth in the Wild Data"];
img = Import["https://www.liveenhanced.com/wp-content/uploads/2017/12/Beauty-Of-Bears-Ears-National-Monument.jpg"];
{x, y} = ImageDimensions[img];

height = 1 - Rescale[ArrayResample[net[img], Round[{x, y}/4]]];

meshlines = ListPlot3D[
400 Reverse[height],
Mesh -> 100, MeshFunctions -> {#2 &},
DataRange -> {{0, x}, {0, y}}, PlotStyle -> None
];

mr = DiscretizeGraphics[meshlines,
MeshCellStyle -> {1 -> Black}, PlotTheme -> "Lines"];

M = MomentOfInertia[Point[MeshCoordinates[mr]]];

{v1, v2} = Rest[Eigenvectors[M]];

Show[mr, ViewVertical -> {0, 0, -1},
ViewPoint -> {0, 10, 10} Normalize[Cross[v1, v2]]]


enter image description here



It might be possible to accentuate the detail better by finding a suitable power to raise height to, e.g. height^2, etc.





Here's a way to project into 2D, rather than adjusting the ViewPoint in 3D:



MeshRegion[
-PrincipalComponents[MeshCoordinates[mr]][[All, 1 ;; 2]],
MeshCells[mr, 1],
PlotTheme -> "Lines", MeshCellStyle -> {1 -> Black}
]


enter image description here





Here's a way to add some smooth edge lines. There's room for improvement here -- both in the implementation and output -- and the high degree splines take some time to render.



The idea is to edge detect, break up branch points to get a collection of path curves, approximate each path with a smooth curve, then map into 3D.



boundary = Thinning[EdgeDetect[im, 10]];

brokenboundary = ImageMultiply[boundary, ColorNegate[MorphologicalBranchPoints[boundary]]];

ones = Position[Reverse[Transpose[ImageData[brokenboundary]], {2}], 1];

g = NearestNeighborGraph[ones, {All, 1.5}];

comps = WeaklyConnectedGraphComponents[g];

paths = FindHamiltonianPath /@ comps;

hmap = ListInterpolation[400 Reverse[Transpose[height], {2}], {{0, x}, {0, y}}];
paths3d = Apply[{##, hmap[##]} &, paths, {2}];

Show[
mr,
Graphics3D[{AbsoluteThickness[1], BSplineCurve[#, SplineDegree -> Length[#] - 1] & /@ paths3d}],
ViewVertical -> {0, 0, -1},
ViewPoint -> {0, 10, 10} Normalize[Cross[v1, v2]]
]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    This is really nice, great work!
    $endgroup$
    – Carl Lange
    8 hours ago










  • $begingroup$
    @CarlLange Thanks!
    $endgroup$
    – Chip Hurst
    8 hours ago










  • $begingroup$
    +1 Nice work Chip! In my case, I do need to use an image for the pattern of lines since that will need to be different. Possibly adding EdgeDetect to gain a more defined shape definition like the example image.
    $endgroup$
    – R Hall
    7 hours ago










  • $begingroup$
    @RHall do you mean have some edge lines in addition to the horizontal ones?
    $endgroup$
    – Chip Hurst
    6 hours ago










  • $begingroup$
    Yes, I have a large number of pattern images that I would use instead of the example provided.
    $endgroup$
    – R Hall
    6 hours ago
















8












$begingroup$

Here's my attempt, which uses the neural net Carl Lange referred to, plots mesh lines with ListPlot3D, and finds a 'nice' view point to see the lines.



net = NetModel["Single-Image Depth Perception Net Trained on NYU Depth V2 and Depth in the Wild Data"];
img = Import["https://www.liveenhanced.com/wp-content/uploads/2017/12/Beauty-Of-Bears-Ears-National-Monument.jpg"];
{x, y} = ImageDimensions[img];

height = 1 - Rescale[ArrayResample[net[img], Round[{x, y}/4]]];

meshlines = ListPlot3D[
400 Reverse[height],
Mesh -> 100, MeshFunctions -> {#2 &},
DataRange -> {{0, x}, {0, y}}, PlotStyle -> None
];

mr = DiscretizeGraphics[meshlines,
MeshCellStyle -> {1 -> Black}, PlotTheme -> "Lines"];

M = MomentOfInertia[Point[MeshCoordinates[mr]]];

{v1, v2} = Rest[Eigenvectors[M]];

Show[mr, ViewVertical -> {0, 0, -1},
ViewPoint -> {0, 10, 10} Normalize[Cross[v1, v2]]]


enter image description here



It might be possible to accentuate the detail better by finding a suitable power to raise height to, e.g. height^2, etc.





Here's a way to project into 2D, rather than adjusting the ViewPoint in 3D:



MeshRegion[
-PrincipalComponents[MeshCoordinates[mr]][[All, 1 ;; 2]],
MeshCells[mr, 1],
PlotTheme -> "Lines", MeshCellStyle -> {1 -> Black}
]


enter image description here





Here's a way to add some smooth edge lines. There's room for improvement here -- both in the implementation and output -- and the high degree splines take some time to render.



The idea is to edge detect, break up branch points to get a collection of path curves, approximate each path with a smooth curve, then map into 3D.



boundary = Thinning[EdgeDetect[im, 10]];

brokenboundary = ImageMultiply[boundary, ColorNegate[MorphologicalBranchPoints[boundary]]];

ones = Position[Reverse[Transpose[ImageData[brokenboundary]], {2}], 1];

g = NearestNeighborGraph[ones, {All, 1.5}];

comps = WeaklyConnectedGraphComponents[g];

paths = FindHamiltonianPath /@ comps;

hmap = ListInterpolation[400 Reverse[Transpose[height], {2}], {{0, x}, {0, y}}];
paths3d = Apply[{##, hmap[##]} &, paths, {2}];

Show[
mr,
Graphics3D[{AbsoluteThickness[1], BSplineCurve[#, SplineDegree -> Length[#] - 1] & /@ paths3d}],
ViewVertical -> {0, 0, -1},
ViewPoint -> {0, 10, 10} Normalize[Cross[v1, v2]]
]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    This is really nice, great work!
    $endgroup$
    – Carl Lange
    8 hours ago










  • $begingroup$
    @CarlLange Thanks!
    $endgroup$
    – Chip Hurst
    8 hours ago










  • $begingroup$
    +1 Nice work Chip! In my case, I do need to use an image for the pattern of lines since that will need to be different. Possibly adding EdgeDetect to gain a more defined shape definition like the example image.
    $endgroup$
    – R Hall
    7 hours ago










  • $begingroup$
    @RHall do you mean have some edge lines in addition to the horizontal ones?
    $endgroup$
    – Chip Hurst
    6 hours ago










  • $begingroup$
    Yes, I have a large number of pattern images that I would use instead of the example provided.
    $endgroup$
    – R Hall
    6 hours ago














8












8








8





$begingroup$

Here's my attempt, which uses the neural net Carl Lange referred to, plots mesh lines with ListPlot3D, and finds a 'nice' view point to see the lines.



net = NetModel["Single-Image Depth Perception Net Trained on NYU Depth V2 and Depth in the Wild Data"];
img = Import["https://www.liveenhanced.com/wp-content/uploads/2017/12/Beauty-Of-Bears-Ears-National-Monument.jpg"];
{x, y} = ImageDimensions[img];

height = 1 - Rescale[ArrayResample[net[img], Round[{x, y}/4]]];

meshlines = ListPlot3D[
400 Reverse[height],
Mesh -> 100, MeshFunctions -> {#2 &},
DataRange -> {{0, x}, {0, y}}, PlotStyle -> None
];

mr = DiscretizeGraphics[meshlines,
MeshCellStyle -> {1 -> Black}, PlotTheme -> "Lines"];

M = MomentOfInertia[Point[MeshCoordinates[mr]]];

{v1, v2} = Rest[Eigenvectors[M]];

Show[mr, ViewVertical -> {0, 0, -1},
ViewPoint -> {0, 10, 10} Normalize[Cross[v1, v2]]]


enter image description here



It might be possible to accentuate the detail better by finding a suitable power to raise height to, e.g. height^2, etc.





Here's a way to project into 2D, rather than adjusting the ViewPoint in 3D:



MeshRegion[
-PrincipalComponents[MeshCoordinates[mr]][[All, 1 ;; 2]],
MeshCells[mr, 1],
PlotTheme -> "Lines", MeshCellStyle -> {1 -> Black}
]


enter image description here





Here's a way to add some smooth edge lines. There's room for improvement here -- both in the implementation and output -- and the high degree splines take some time to render.



The idea is to edge detect, break up branch points to get a collection of path curves, approximate each path with a smooth curve, then map into 3D.



boundary = Thinning[EdgeDetect[im, 10]];

brokenboundary = ImageMultiply[boundary, ColorNegate[MorphologicalBranchPoints[boundary]]];

ones = Position[Reverse[Transpose[ImageData[brokenboundary]], {2}], 1];

g = NearestNeighborGraph[ones, {All, 1.5}];

comps = WeaklyConnectedGraphComponents[g];

paths = FindHamiltonianPath /@ comps;

hmap = ListInterpolation[400 Reverse[Transpose[height], {2}], {{0, x}, {0, y}}];
paths3d = Apply[{##, hmap[##]} &, paths, {2}];

Show[
mr,
Graphics3D[{AbsoluteThickness[1], BSplineCurve[#, SplineDegree -> Length[#] - 1] & /@ paths3d}],
ViewVertical -> {0, 0, -1},
ViewPoint -> {0, 10, 10} Normalize[Cross[v1, v2]]
]


enter image description here






share|improve this answer











$endgroup$



Here's my attempt, which uses the neural net Carl Lange referred to, plots mesh lines with ListPlot3D, and finds a 'nice' view point to see the lines.



net = NetModel["Single-Image Depth Perception Net Trained on NYU Depth V2 and Depth in the Wild Data"];
img = Import["https://www.liveenhanced.com/wp-content/uploads/2017/12/Beauty-Of-Bears-Ears-National-Monument.jpg"];
{x, y} = ImageDimensions[img];

height = 1 - Rescale[ArrayResample[net[img], Round[{x, y}/4]]];

meshlines = ListPlot3D[
400 Reverse[height],
Mesh -> 100, MeshFunctions -> {#2 &},
DataRange -> {{0, x}, {0, y}}, PlotStyle -> None
];

mr = DiscretizeGraphics[meshlines,
MeshCellStyle -> {1 -> Black}, PlotTheme -> "Lines"];

M = MomentOfInertia[Point[MeshCoordinates[mr]]];

{v1, v2} = Rest[Eigenvectors[M]];

Show[mr, ViewVertical -> {0, 0, -1},
ViewPoint -> {0, 10, 10} Normalize[Cross[v1, v2]]]


enter image description here



It might be possible to accentuate the detail better by finding a suitable power to raise height to, e.g. height^2, etc.





Here's a way to project into 2D, rather than adjusting the ViewPoint in 3D:



MeshRegion[
-PrincipalComponents[MeshCoordinates[mr]][[All, 1 ;; 2]],
MeshCells[mr, 1],
PlotTheme -> "Lines", MeshCellStyle -> {1 -> Black}
]


enter image description here





Here's a way to add some smooth edge lines. There's room for improvement here -- both in the implementation and output -- and the high degree splines take some time to render.



The idea is to edge detect, break up branch points to get a collection of path curves, approximate each path with a smooth curve, then map into 3D.



boundary = Thinning[EdgeDetect[im, 10]];

brokenboundary = ImageMultiply[boundary, ColorNegate[MorphologicalBranchPoints[boundary]]];

ones = Position[Reverse[Transpose[ImageData[brokenboundary]], {2}], 1];

g = NearestNeighborGraph[ones, {All, 1.5}];

comps = WeaklyConnectedGraphComponents[g];

paths = FindHamiltonianPath /@ comps;

hmap = ListInterpolation[400 Reverse[Transpose[height], {2}], {{0, x}, {0, y}}];
paths3d = Apply[{##, hmap[##]} &, paths, {2}];

Show[
mr,
Graphics3D[{AbsoluteThickness[1], BSplineCurve[#, SplineDegree -> Length[#] - 1] & /@ paths3d}],
ViewVertical -> {0, 0, -1},
ViewPoint -> {0, 10, 10} Normalize[Cross[v1, v2]]
]


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited 5 hours ago

























answered 8 hours ago









Chip HurstChip Hurst

22.1k15790




22.1k15790












  • $begingroup$
    This is really nice, great work!
    $endgroup$
    – Carl Lange
    8 hours ago










  • $begingroup$
    @CarlLange Thanks!
    $endgroup$
    – Chip Hurst
    8 hours ago










  • $begingroup$
    +1 Nice work Chip! In my case, I do need to use an image for the pattern of lines since that will need to be different. Possibly adding EdgeDetect to gain a more defined shape definition like the example image.
    $endgroup$
    – R Hall
    7 hours ago










  • $begingroup$
    @RHall do you mean have some edge lines in addition to the horizontal ones?
    $endgroup$
    – Chip Hurst
    6 hours ago










  • $begingroup$
    Yes, I have a large number of pattern images that I would use instead of the example provided.
    $endgroup$
    – R Hall
    6 hours ago


















  • $begingroup$
    This is really nice, great work!
    $endgroup$
    – Carl Lange
    8 hours ago










  • $begingroup$
    @CarlLange Thanks!
    $endgroup$
    – Chip Hurst
    8 hours ago










  • $begingroup$
    +1 Nice work Chip! In my case, I do need to use an image for the pattern of lines since that will need to be different. Possibly adding EdgeDetect to gain a more defined shape definition like the example image.
    $endgroup$
    – R Hall
    7 hours ago










  • $begingroup$
    @RHall do you mean have some edge lines in addition to the horizontal ones?
    $endgroup$
    – Chip Hurst
    6 hours ago










  • $begingroup$
    Yes, I have a large number of pattern images that I would use instead of the example provided.
    $endgroup$
    – R Hall
    6 hours ago
















$begingroup$
This is really nice, great work!
$endgroup$
– Carl Lange
8 hours ago




$begingroup$
This is really nice, great work!
$endgroup$
– Carl Lange
8 hours ago












$begingroup$
@CarlLange Thanks!
$endgroup$
– Chip Hurst
8 hours ago




$begingroup$
@CarlLange Thanks!
$endgroup$
– Chip Hurst
8 hours ago












$begingroup$
+1 Nice work Chip! In my case, I do need to use an image for the pattern of lines since that will need to be different. Possibly adding EdgeDetect to gain a more defined shape definition like the example image.
$endgroup$
– R Hall
7 hours ago




$begingroup$
+1 Nice work Chip! In my case, I do need to use an image for the pattern of lines since that will need to be different. Possibly adding EdgeDetect to gain a more defined shape definition like the example image.
$endgroup$
– R Hall
7 hours ago












$begingroup$
@RHall do you mean have some edge lines in addition to the horizontal ones?
$endgroup$
– Chip Hurst
6 hours ago




$begingroup$
@RHall do you mean have some edge lines in addition to the horizontal ones?
$endgroup$
– Chip Hurst
6 hours ago












$begingroup$
Yes, I have a large number of pattern images that I would use instead of the example provided.
$endgroup$
– R Hall
6 hours ago




$begingroup$
Yes, I have a large number of pattern images that I would use instead of the example provided.
$endgroup$
– R Hall
6 hours ago











7












$begingroup$

We can get some of the way there by using ListContourPlot.



enter image description here



Now we grab a neural network to get the depth map for us:



net = NetModel[
"Single-Image Depth Perception Net Trained on NYU Depth V2 and Depth in the Wild Data"]


Now we can see our depth map:



enter image description here



Great. Let's put that in a list, after a little bit of cajoling (Blurring, ImageAdjusting so it's all between 0 and 1)



depth = ImageData@Blur@ImageAdjust@Image@net[i]


Now we can try and ListContourPlot it:



ListContourPlot[Reverse@depth, Contours -> 25, 
ColorFunction -> (White &), Axes -> None, Frame -> None,
AspectRatio -> ImageAspectRatio@i]


enter image description here



Or, with the image you linked to:



enter image description here



Other options I thought about but didn't execute on:




  • convolving an image of lines with the depth map

  • converting the depthmap to a weighted graph and using FindShortestPath (I still like this one, but I think the output would be pretty similar to this attempt)

  • There's always good old ImageRestyle, which if given enough time might do a really nice job of this...






share|improve this answer











$endgroup$













  • $begingroup$
    I like this! I do need to be able to convolve an image of lines though because although the example image is nice, the use case is different and thus the line pattern would have to be different.
    $endgroup$
    – R Hall
    8 hours ago
















7












$begingroup$

We can get some of the way there by using ListContourPlot.



enter image description here



Now we grab a neural network to get the depth map for us:



net = NetModel[
"Single-Image Depth Perception Net Trained on NYU Depth V2 and Depth in the Wild Data"]


Now we can see our depth map:



enter image description here



Great. Let's put that in a list, after a little bit of cajoling (Blurring, ImageAdjusting so it's all between 0 and 1)



depth = ImageData@Blur@ImageAdjust@Image@net[i]


Now we can try and ListContourPlot it:



ListContourPlot[Reverse@depth, Contours -> 25, 
ColorFunction -> (White &), Axes -> None, Frame -> None,
AspectRatio -> ImageAspectRatio@i]


enter image description here



Or, with the image you linked to:



enter image description here



Other options I thought about but didn't execute on:




  • convolving an image of lines with the depth map

  • converting the depthmap to a weighted graph and using FindShortestPath (I still like this one, but I think the output would be pretty similar to this attempt)

  • There's always good old ImageRestyle, which if given enough time might do a really nice job of this...






share|improve this answer











$endgroup$













  • $begingroup$
    I like this! I do need to be able to convolve an image of lines though because although the example image is nice, the use case is different and thus the line pattern would have to be different.
    $endgroup$
    – R Hall
    8 hours ago














7












7








7





$begingroup$

We can get some of the way there by using ListContourPlot.



enter image description here



Now we grab a neural network to get the depth map for us:



net = NetModel[
"Single-Image Depth Perception Net Trained on NYU Depth V2 and Depth in the Wild Data"]


Now we can see our depth map:



enter image description here



Great. Let's put that in a list, after a little bit of cajoling (Blurring, ImageAdjusting so it's all between 0 and 1)



depth = ImageData@Blur@ImageAdjust@Image@net[i]


Now we can try and ListContourPlot it:



ListContourPlot[Reverse@depth, Contours -> 25, 
ColorFunction -> (White &), Axes -> None, Frame -> None,
AspectRatio -> ImageAspectRatio@i]


enter image description here



Or, with the image you linked to:



enter image description here



Other options I thought about but didn't execute on:




  • convolving an image of lines with the depth map

  • converting the depthmap to a weighted graph and using FindShortestPath (I still like this one, but I think the output would be pretty similar to this attempt)

  • There's always good old ImageRestyle, which if given enough time might do a really nice job of this...






share|improve this answer











$endgroup$



We can get some of the way there by using ListContourPlot.



enter image description here



Now we grab a neural network to get the depth map for us:



net = NetModel[
"Single-Image Depth Perception Net Trained on NYU Depth V2 and Depth in the Wild Data"]


Now we can see our depth map:



enter image description here



Great. Let's put that in a list, after a little bit of cajoling (Blurring, ImageAdjusting so it's all between 0 and 1)



depth = ImageData@Blur@ImageAdjust@Image@net[i]


Now we can try and ListContourPlot it:



ListContourPlot[Reverse@depth, Contours -> 25, 
ColorFunction -> (White &), Axes -> None, Frame -> None,
AspectRatio -> ImageAspectRatio@i]


enter image description here



Or, with the image you linked to:



enter image description here



Other options I thought about but didn't execute on:




  • convolving an image of lines with the depth map

  • converting the depthmap to a weighted graph and using FindShortestPath (I still like this one, but I think the output would be pretty similar to this attempt)

  • There's always good old ImageRestyle, which if given enough time might do a really nice job of this...







share|improve this answer














share|improve this answer



share|improve this answer








edited 8 hours ago

























answered 8 hours ago









Carl LangeCarl Lange

4,3881836




4,3881836












  • $begingroup$
    I like this! I do need to be able to convolve an image of lines though because although the example image is nice, the use case is different and thus the line pattern would have to be different.
    $endgroup$
    – R Hall
    8 hours ago


















  • $begingroup$
    I like this! I do need to be able to convolve an image of lines though because although the example image is nice, the use case is different and thus the line pattern would have to be different.
    $endgroup$
    – R Hall
    8 hours ago
















$begingroup$
I like this! I do need to be able to convolve an image of lines though because although the example image is nice, the use case is different and thus the line pattern would have to be different.
$endgroup$
– R Hall
8 hours ago




$begingroup$
I like this! I do need to be able to convolve an image of lines though because although the example image is nice, the use case is different and thus the line pattern would have to be different.
$endgroup$
– R Hall
8 hours ago











3












$begingroup$

ImageRestyle is an obvious thing to try:



Import["https://www.liveenhanced.com/wp-content/uploads/2017/12/Beauty-Of-Bears-Ears-National-Monument.jpg"];
imgBW = ColorConvert[img, "Grayscale"];
imgLines = Import["https://i.stack.imgur.com/bR9kS.png"];
ColorConvert[ImageRestyle[imgBW, imgLines], "Grayscale"]


enter image description here



If you are willing to wait a while, ImageRestyle has options:



resty = ImageRestyle[imgBW, imgLines, PerformanceGoal -> "Quality"]; 
ColorConvert[resty, "Grayscale"]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Good attempt Bill, Trying this method doesn't provide the distorted pattern only. Seems some of the first image is left to show through the effect. The line pattern should end up as a single distorted 3D object.
    $endgroup$
    – R Hall
    5 hours ago


















3












$begingroup$

ImageRestyle is an obvious thing to try:



Import["https://www.liveenhanced.com/wp-content/uploads/2017/12/Beauty-Of-Bears-Ears-National-Monument.jpg"];
imgBW = ColorConvert[img, "Grayscale"];
imgLines = Import["https://i.stack.imgur.com/bR9kS.png"];
ColorConvert[ImageRestyle[imgBW, imgLines], "Grayscale"]


enter image description here



If you are willing to wait a while, ImageRestyle has options:



resty = ImageRestyle[imgBW, imgLines, PerformanceGoal -> "Quality"]; 
ColorConvert[resty, "Grayscale"]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Good attempt Bill, Trying this method doesn't provide the distorted pattern only. Seems some of the first image is left to show through the effect. The line pattern should end up as a single distorted 3D object.
    $endgroup$
    – R Hall
    5 hours ago
















3












3








3





$begingroup$

ImageRestyle is an obvious thing to try:



Import["https://www.liveenhanced.com/wp-content/uploads/2017/12/Beauty-Of-Bears-Ears-National-Monument.jpg"];
imgBW = ColorConvert[img, "Grayscale"];
imgLines = Import["https://i.stack.imgur.com/bR9kS.png"];
ColorConvert[ImageRestyle[imgBW, imgLines], "Grayscale"]


enter image description here



If you are willing to wait a while, ImageRestyle has options:



resty = ImageRestyle[imgBW, imgLines, PerformanceGoal -> "Quality"]; 
ColorConvert[resty, "Grayscale"]


enter image description here






share|improve this answer











$endgroup$



ImageRestyle is an obvious thing to try:



Import["https://www.liveenhanced.com/wp-content/uploads/2017/12/Beauty-Of-Bears-Ears-National-Monument.jpg"];
imgBW = ColorConvert[img, "Grayscale"];
imgLines = Import["https://i.stack.imgur.com/bR9kS.png"];
ColorConvert[ImageRestyle[imgBW, imgLines], "Grayscale"]


enter image description here



If you are willing to wait a while, ImageRestyle has options:



resty = ImageRestyle[imgBW, imgLines, PerformanceGoal -> "Quality"]; 
ColorConvert[resty, "Grayscale"]


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 hours ago

























answered 5 hours ago









bill sbill s

54k377154




54k377154












  • $begingroup$
    Good attempt Bill, Trying this method doesn't provide the distorted pattern only. Seems some of the first image is left to show through the effect. The line pattern should end up as a single distorted 3D object.
    $endgroup$
    – R Hall
    5 hours ago




















  • $begingroup$
    Good attempt Bill, Trying this method doesn't provide the distorted pattern only. Seems some of the first image is left to show through the effect. The line pattern should end up as a single distorted 3D object.
    $endgroup$
    – R Hall
    5 hours ago


















$begingroup$
Good attempt Bill, Trying this method doesn't provide the distorted pattern only. Seems some of the first image is left to show through the effect. The line pattern should end up as a single distorted 3D object.
$endgroup$
– R Hall
5 hours ago






$begingroup$
Good attempt Bill, Trying this method doesn't provide the distorted pattern only. Seems some of the first image is left to show through the effect. The line pattern should end up as a single distorted 3D object.
$endgroup$
– R Hall
5 hours ago




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f193043%2fcan-mathematica-be-used-to-create-an-artistic-3d-extrusion-from-a-2d-image-and-w%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

Plaza Victoria

In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...