ahuca 2016-07-14 08:21 采纳率: 0%
浏览 863

如何正确读取text文档之后,按要求输出一个三维矩阵,并且绘制成图

这个里面
Channel = Default Beam
Focal Law = Linear L1 : 1-1
Type = A-Scan
ScanStart (m) = 0.00
ScanQty (sample) = 151.0
ScanResol (m) = 1.00
IndexStart (m) = 0.00
IndexQty (sample) = 1.0
IndexResol (m) = 1.00
USoundStart (mm) = 0.00
USoundQty (sample) = 1484.0
USoundResol (mm) = 0.04
AmplMin (sample) = 0.0
AmplMax (sample) = 255.0
AmplStart (%) = 0.00
AmplResol (%) = 0.39
这是代表每一个channel 的信息 (总过有128个channel)
每一个channel 里面含有multiple lines of data(含有很多line of data 类似于在L1-1)
类似于在channel 1(L1-1里面)
line 1的信息始于1.1……止于0.3
line 2 的信息始于 2.7……止于0.7
line 3的信息始于 2。7……止于 0.7
line m……止于0 (我猜测每个line的长度n都是一样的)
Channel 2
……
channel i

我的思路是把每一个channel 的信息都读取并且储存起来变成一个i*m*n的矩阵,然后绘制成一个3D的图
我刚开始学用python 目前的
import numpy as np
from tifffile import imsave
import io

#number of elements in array
i = 128

#open the text file with all headers打开text file
data = io.open('BreastPhantomTest.txt','r',encoding='cp1252')

#create a list of all lines with data in them - the typical format is for 16 lines of header,
#followed by 'n' lines of data each 'm' tab delimited data points long
#where 'n' is the number of points in the scan direction and 'm' is the number of digitization points
#This repeats for each 'i element.

#line = data.readlines() ##-- this method will get slow for larger datasets I believe
datatrimmed=[]
#assume lines with data start with a non-zero number this should scale up in data size.
#We can also use this method to get other parameters out of the header.
for line in data:

#line = line.rstrip()
if not line[0].isdigit():continue #take only the digits
#if not line[0]!=0:continue #take only the lines that don't start with a zero.
#line=data.readline()
f = line.split()# I put read() in the middle of line and split, saying 'str' has no attribute 'read'
datatrimmed.append(f)

datatrimmed.append(f)
m = len(f)
volume=np.reshape(datatrimmed,(i,-1,m)) #create the volume, leaving the number of scan points to float
volume1=np.float32(volume)
imsave(‘volume.tiff',volume1)

但是这个运行起来 总是出现 volumerror:total size of new array must be unchanged
我已经被编程搞得头疼死了(哭

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-10-04 10:55
    关注

    xQty (sample) = 1.0
    IndexResol (m) = 1.00
    USoundStart (mm) = 0.00
    USoundQty (sample) = 1484.0
    USoundResol (mm) = 0.04
    AmplMin (sample) = 0.0
    AmplMax (sample) = 255.0
    AmplStart (%) = 0.00
    AmplResol (%) = 0.39
    这是代表每一个channel 的信息 (总过有128个channel)
    每一个channel 里面含有multiple lines of data(含有很多line of data 类似于在L1-1)
    类似于在channel 1(L1-1里面)
    line 1的信息始于1.1……止于0.3
    line 2 的信息始于 2.7……止于0.7

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。