0

I have a stack of CT-scan images. After processing (one image from those stack) CT-scan image using Matlab, I saved XY coordinates for each different boundary region in different Excel sheets as follows:

I = imread('myCTscan.jpeg');
BW = im2bw(I);
[coords, labeledImg] = bwboundaries(BW, 4, 'holes'); 
sheet = 1;
for n=1:length(coords);
    xlswrite('fig.xlsx',coords{n,1},sheet,'A1');
    sheet = sheet+1;
end

The next step is then to import this set of coordinates and plot it into Abaqus CAE Sketch for finite element analysis. I figure out that my workflow is something like this:

  1. Import Excel workbook
  2. For each sheet in workbook:
    2.1. For each row: read both column to get xy coordinates (each row has two column, x and y coordinate)
    2.2. Put each xy coordinates inside a list
    2.3. From list, sketch using spline method
  3. Repeat step 2 for other sheets within the workbook

I searched for a while and found something like this:

from abaqus import *
lines= open('fig.xlsx', 'r').readlines()
pointList= []
for line in lines:
    pointList.append(eval('(%s)' %line.strip()))
s1= mdb.models['Model-1'].ConstrainedSketch(name='mySketch', sheetSize=500.0)
s1.Spline(points= pointList)

But this only read XY coordinates from only one sheet and I'm stuck at step 3 above. Thus my problem is that how to read these coordinates in different sheets using Abaqus/Python (Abaqus 6.14, Python 2.7) script?

I'm new to Python programming, I can read and understand the syntax but can't write very well (I'm still struggling on how to import Python module in Abaqus). Manually type each coordinates (like in Abaqus' modelAExample.py tutorial) is practically impossible since each of my CT-scan image can have 100++ of boundary regions and 10k++ points.

I'm using:
Windows 7 x64
Abaqus 6.14 (with built in Python 2.7)
Excel 2013
Matlab 2016a with Image Processing Toolbox

Max Mijot
  • 1
  • 3

1 Answers1

1

You are attempting to read excel files as comma separated files. CSV files by definition can not have more than one tab. Your read command is interpreting the file as a csv and not allowing you to iterate over the tabs in your file (though it begs the question how your file is opening properly in the first place as you are saving an xlsx and reading a csv).

There are numerous python libraries that will parse and process XLS/XLSX files.

Take a look at pyxl and use it to read your file in. You would likely use something like

from openpyxl import Workbook
(some commands to open the workbook)

listofnames=wb.sheetnames
for k in listofnames:
    ws=wb.worksheets(k)

and then input your remaining commands.

zglin
  • 2,891
  • 2
  • 15
  • 26