필터 지우기
필터 지우기

Convert STL file to something I can use 'regionprops' function

조회 수: 3 (최근 30일)
Carolyn
Carolyn 2018년 3월 19일
댓글: Carolyn 2018년 3월 20일
I have to use a code that uses the 'regionprops' function. The problem is, the program that was originally used to import data as a .tif stack to use in this code is no longer available to me. I can only import as an stl (binary or ASCII). Is there a way that I can use the stl file and convert it to a format supported by the regionprops function? Here is a sample of the code that I have to use. 'bone.photo' was the original reference to the .tif stack that was used before.
LM = bwlabel(bone.photo{ind});
m = regionprops(LM==medLM,'Centroid','Area','EquivDiameter','BoundingBox','PixelList','ConvexHull','ConvexArea');
centroid = cat(1,m.Centroid);
area = cat(1,m.Area)*heightPerPixel*widthPerPixel;
equivdia = cat(1,m.EquivDiameter)*widthPerPixel;
boundingbox = cat(1,m.BoundingBox);
pixellist = cat(1,m.PixelList);
convexarea = cat(1,m.ConvexArea)*heightPerPixel*widthPerPixel;
I have tried making a couple different 'stlread' functions work, but I either get a faces matrix and vertices matrix or edge coordinates. These don't give me a binary image, so they won't work in the 'regionprops' function.

채택된 답변

Image Analyst
Image Analyst 2018년 3월 19일
I don't use STL files. Somehow you need to convert the STL file to a binary image. Perhaps you can use poly2mask() to do that.
  댓글 수: 4
Carolyn
Carolyn 2018년 3월 20일
Here is the code I have to do this:
CC = cell(1,length(movelist));
movelist1 = cell(1,length(movelist));
for n=1:length(movelist)
offsetx = min(movelist{1,n}(:,1));
offsety = min(movelist{1,n}(:,2));
CC{n}={offsetx,offsety};
bw_x = movelist{1,n}(:,1)+ceil(abs(offsetx))+1;
bw_y = movelist{1,n}(:,2)+ceil(abs(offsety))+1;
bw = [bw_x, bw_y];
movelist1{n} = bw;
xpix = ceil(max(movelist1{n}(:,1)));
ypix = ceil(max(movelist1{n}(:,2)));
bonebinary{n} = poly2mask(movelist1{n}(:,1),movelist{n}(:,2),xpix,ypix);
end
My problem is, it still isn't showing all the data in the binary conversion. Here is the x,y plot of one of the datasets originally (the data I'm trying to convert from coordinates to binary)
and the resulting binary image from this code.
Can you tell what I'm doing wrong? I just can't get it to show the top half of the original image. It seems strange that its the top half since I thought it didn't like negative numbers. I've played around with the offset values and the pixel values, but it doesn't seem to change it.
Carolyn
Carolyn 2018년 3월 20일
NEVERMIND! The last line of my code used the original list without the offset. I forgot to add the 1 to that variable. Fixed!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by