I have 2d images in JPEG format created by matlab program and I want to convert them into .STL files using matlab code

조회 수: 14(최근 30일)
AARISH NAWAZ 2022년 1월 14일
댓글: Rik 2022년 1월 23일
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.
  댓글 수: 3
AARISH NAWAZ 2022년 1월 18일
Dear @Walter Roberson, You are right I would like to analyze the content of the image and figure out the edge connections and faces and so on. example: take a picture of a gear and have it create the gear. Please see my newly attached examples for reference.
Another person DGM has done half of the job but Since the thickness is zero (just one plane, only one face normal value of Z axis for all faces) im unable to print it on a 3d printer (I get an error because of zero thickness on cura), can you guide me how to replicate the same image with diffrent Z axis values (for some minimum thickness to eliminate the error)?

댓글을 달려면 로그인하십시오.

채택된 답변

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;
% 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];
% 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).';
% get the polygon and make the triangulation
poly = polyshape(x_vec, y_vec, 'Simplify', false);
tr = triangulation(poly);
axis equal
% write to stl
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.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Bashar Shami
Bashar Shami 2022년 1월 22일
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
  댓글 수: 1
Rik 2022년 1월 23일
How exactly is this an answer? Also, please only use flags to attract the attention of site admins.

댓글을 달려면 로그인하십시오.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by