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 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考