I have 2d images in JPEG format created by matlab program and I want to convert them into .STL files using matlab code
66 次查看(过去 30 天)
显示 更早的评论
What is the approach needed in Matlab to convert 2d image in JPEG format into a simple .STL file (2D) for 3D printing ? Which function can I use to automate the conversion of images from jpeg to .STL?
For Example The output I got from Matlab code was the Image "MATLAB_Example.jpg" I want to extract the boundaries and convert it to .STL file to 3D print the Topology with a minumum thickness example 1mm looking exactly like the MATLAB_Example.jpg image. I can do this using the websites like https://anyconv.com/jpg-to-stl-converter/ (and obtain the boundaries eg. AnyConv.com__MATLAB_Example.stl) but I want to do it using Matlab as I have many images like this that I want to convert to .STL and print.
5 个评论
Bashar Shami
2022-1-22
移动:DGM
2024-1-17
Hello Airesh Kindly come back and talk again , your task is image processing task acquire segmentation of desired region mainly threshold segmentation then giving it dimension in z axis then triangulate for STL Facebook @Basharbme
采纳的回答
DGM
2022-1-16
Well, here's a half-baked answer, but anyone is free to do better.
I just grabbed this mesh tool from the FEX and gutted it to avoid the PDE toolbox dependency and change the binarization behavior.
% parameters
prescale = 0.1; % this scales the contours prior to simplification
simplify_tol = 0.1;
% transform the image into binary
A = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/863735/MATLAB_Example.jpg');
A = ~imbinarize(rgb2gray(A));
A = bwareafilt(A,1);
% rotate coordinate
A = fliplr(A.');
% get the contours of the image
% find boundary
bnd = bwboundaries(A);
% parse the contours
for i=1:length(bnd)
bnd_tmp = bnd{i};
assert(all(bnd_tmp(1,:)==bnd_tmp(end,:)), 'contour is not closed')
c_cell{i} = prescale.*bnd_tmp;
end
% simplify all the contours
c_cell_out = {};
for i=1:length(c_cell)
c_tmp = c_cell{i};
[x_tmp, y_tmp] = reducem(c_tmp(:,1), c_tmp(:,2), simplify_tol);
if (nnz(x_tmp)>0)&&(nnz(y_tmp)>0)
c_cell_out{end+1} = [x_tmp, y_tmp];
end
end
% create the 2d triangulation
% for each contour, prepare the polygons
for i=1:length(c_cell_out)
c_tmp = c_cell_out{i};
x_vec{i} = c_tmp(:,1).';
y_vec{i} = c_tmp(:,2).';
end
% get the polygon and make the triangulation
poly = polyshape(x_vec, y_vec, 'Simplify', false);
tr = triangulation(poly);
triplot(tr)
axis equal
% write to stl
stlwrite(tr,'mything.stl','text')
Note that the part has arbitrary scale and offset. You'll have to figure out how you want to manage scale and offset, perhaps modifying the simplified contours prior to triangulation or something. The prescale parameter scales the contours prior to simplification and will change the number of vertices, so it's probably best treated as a simplification parameter rather than being used for scaling the output geometry.
2 个评论
DGM
2022-1-16
I'm sure it could be done, but like I said, I am totally unfamiliar with this process and how the extruded point list would need to be generated.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!