How to export return value of bwboundaries to DXF file format?

4 views (last 30 days)
Hey guys,
i am new to MatLab and I got a problem.
I wrote a little function to trace boundaries in a 2D scan picture. Now my problem is, that I dont understand the format of the return value of the bwboundaries function.
The documentation says the following about the return value of bwboundaries(): bwboundaries returns B, a P-by-1 cell array, where P is the number of objects and holes. Each cell in the cell array contains a Q-by-2 matrix. Each row in the matrix contains the row and column coordinates of a boundary pixel. Q is the number of boundary pixels for the corresponding region.
Now, my question is, how can I access the coordinates stored in this array/Matrix combination to export the data into a DXF-File format?
Thanks in advance.
greetz, Marcel
**************************
EDIT
I need to ask another question.
I got this code snippet:
I just customized the second example of the DXF_Test function from the DXFLib to my needs. I need to export multiple polyline objects from the boundary trace algorithm to a DXF file. This code should loop through all the boundaries and collect the needed coordinates from the current object (as commented in the code)
%testing DXFLib
FID = dxf_open('myFirstExport.dxf');
FID = dxf_set(FID,'color',[0,1,0],'Layer',1);
%k is initialized by k = length(B)
%loop through all object boundaries
parfor j = 1:k
%get number of coordinates of the current object
X = zeros(length(B{j,1}));
Y = X; Z = X;
%gather all coordinates of the current object in a vector
for i = 1:size(B{j,1})
X(i+1) = B{i,1}(i,1)
Y(i+1) = B{i,1}(i,2)
end
%export polyline of the current object into the dxf file
dxf_polyline(FID,X,Y,Z);
end
dxf_close(FID);
Now my problem is as follows: I get these 2 errors
  • Error using dxf_polyline (line 45)Invalid file identifier. Use fopen to generate a valid file identifier.
  • Error in bounds (line 24)parfor j = 1:k
Does anyone have any experience with these 2 errors? To the first error, I think it could be, that my input to the function dxf_polyline could cause this error.. but I am not sure due to my little experience with MatLab and the DXFLib ...
Obviously, the second error must be hidden anywhere inside the parfor loop, because the loop head should be ok as it is :(
Thanks a lot for your help,
Best Regards, Marcel

Answers (1)

Steve Eddins
Steve Eddins on 8 Oct 2015
B{1} returns a matrix containing the coordinate values of the first boundary. B{2} returns a matrix containing the coordinate values of the second boundary.
As for creating a DXF file, you might try the DXFLib submission on the File Exchange.
  3 Comments
jahanzaib ahmad
jahanzaib ahmad on 30 Apr 2019
i also have the data in cell array can u please explain how u have done it in loop and store them . i have multiple polygons in cell .
jahanzaib ahmad
jahanzaib ahmad on 30 Apr 2019
i also have the same problem with the polygons ..can u please explain how this can be done ?.
boundaries cell array attached

Sign in to comment.

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!