Labview中BCD转7段数码管解码器设计与Proteus仿真

版权申诉
0 下载量 172 浏览量 更新于2024-10-17 收藏 2KB RAR 举报
资源摘要信息:"bcd-7seg.rar_bcd_in_labview BCD" BCD(二进制编码的十进制)是一种数字编码方式,用于将十进制数转换为二进制形式,但每个十进制数字用四位二进制数表示。这种编码在数字电子学中非常常见,尤其是在需要将人可读的数字显示到电子显示屏上的场合,如七段显示器。 在数字电子设计中,BCD到七段译码器是一种常用电路,其目的是将BCD编码的数字转换为七段显示器所需的控制信号,以便在七段显示器上正确显示对应的数字。七段显示器由七个发光二极管(LED)或液晶段组成,排列成类似“8”字形的结构。每个段被标记为A到G,通过点亮特定的段组合,可以显示出0到9的数字。 本资源所涉及的是在LabVIEW环境下设计的BCD到七段译码器。LabVIEW(Laboratory Virtual Instrument Engineering Workbench)是由美国国家仪器(National Instruments)开发的一种图形化编程语言,它广泛应用于数据采集、仪器控制以及工业自动化等领域。LabVIEW使用图形化编程的概念,通过连线的方式来编写程序,非常适合快速开发原型和数据采集系统。 在LabVIEW中实现BCD到七段译码器,意味着用户需要在LabVIEW的开发环境中构建一个程序,该程序能够接收BCD输入,并将这些输入转换为对七段显示器的控制信号。当输入变化时,程序应当能够更新输出信号,以反映正确的数字显示。 而在Proteus中实现BCD到七段译码器,Proteus是一个电子电路仿真软件,它允许用户设计电路并进行模拟测试。在Proteus中搭建BCD到七段译码器的模拟,可以提供一个可视化的界面来观察和验证电路设计是否正确实现了功能。 "bcd 7seg.pdsprj" 文件是一个Proteus项目文件,这个文件包含了设计好的BCD到七段译码器的电路布局、元件连接和属性设置等信息,可以直接在Proteus软件中打开和运行。通过这种方式,设计者可以直观地看到自己的设计在软件中的表现,包括逻辑功能的正确性以及可能存在的问题。 综上所述,该资源是一个结合了LabVIEW和Proteus的电子设计项目,它涵盖了从编写BCD到七段译码器的逻辑代码,到在电子仿真软件中进行验证的整个流程。对于学习和掌握数字电子设计、LabVIEW编程以及电路仿真分析的人来说,这个资源是一个非常实用的教学案例和实践平台。

import os import numpy as np import nibabel as nib import imageio import cv2 def read_niifile(niifilepath): # 读取niifile文件 img = nib.load(niifilepath) # 提取niifile文件 img_fdata = img.get_fdata(dtype='float32') return img_fdata def save_fig(niifilepath, savepath, num, name): # 保存为图片 name = name.split('-')[1] filepath_seg = niifilepath + "segmentation" + "segmentation-" + name filepath_vol = niifilepath + "volume" + "volume-" + name savepath_seg = savepath + "segmentation" savepath_vol = savepath + "volume" if not os.path.exists(savepath_seg): os.makedirs(savepath_seg) if not os.path.exists(savepath_vol): os.makedirs(savepath_vol) fdata_vol = read_niifile(filepath_vol) fdata_seg = read_niifile(filepath_seg) (x, y, z) = fdata_seg.shape total = x * y for k in range(z): silce_seg = fdata_seg[:, :, k] # 三个位置表示三个不同角度的切片 if silce_seg.max() == 0: continue else: silce_seg = (silce_seg - silce_seg.min()) / (silce_seg.max() - silce_seg.min()) * 255 silce_seg = cv2.threshold(silce_seg, 1, 255, cv2.THRESH_BINARY)[1] if (np.sum(silce_seg == 255) / total) > 0.015: silce_vol = fdata_vol[:, :, k] silce_vol = (silce_vol - silce_vol.min()) / (silce_vol.max() - silce_vol.min()) * 255 imageio.imwrite(os.path.join(savepath_seg, '{}.png'.format(num)), silce_seg) imageio.imwrite(os.path.join(savepath_vol, '{}.png'.format(num)), silce_vol) num += 1 # 将切片信息保存为png格式 return num if name == 'main': path = r"C:\Users\Administrator\Desktop\LiTS2017" savepath = r"C:\Users\Administrator\Desktop\2D-LiTS2017" filenames = os.listdir(path + "segmentation") num = 0 for filename in filenames: num = save_fig(path, savepath, num, filename) 将代码中的 使用cv2模块的代码替换掉,给出一整段完整代码,实现相同功能

2023-05-25 上传

将代码中的import cv2模块替换掉,import os import numpy as np import nibabel as nib import imageio import cv2 def read_niifile(niifilepath): # 读取niifile文件 img = nib.load(niifilepath) # 提取niifile文件 img_fdata = img.get_fdata(dtype='float32') return img_fdata def save_fig(niifilepath, savepath, num, name): # 保存为图片 name = name.split('-')[1] filepath_seg = niifilepath + "segmentation\\" + "segmentation-" + name filepath_vol = niifilepath + "volume\\" + "volume-" +name savepath_seg = savepath + "segmentation\\" savepath_vol = savepath + "volume\\" if not os.path.exists(savepath_seg): os.makedirs(savepath_seg) if not os.path.exists(savepath_vol): os.makedirs(savepath_vol) fdata_vol = read_niifile(filepath_vol) fdata_seg = read_niifile(filepath_seg) (x, y, z) = fdata_seg.shape total = x * y for k in range(z): silce_seg = fdata_seg[:, :, k] # 三个位置表示三个不同角度的切片 if silce_seg.max() == 0: continue else: silce_seg = (silce_seg-silce_seg.min())/(silce_seg.max() - silce_seg.min())*255 silce_seg = cv2.threshold(silce_seg, 1, 255, cv2.THRESH_BINARY)[1] if (np.sum(silce_seg == 255) / total) > 0.015: silce_vol = fdata_vol[:, :, k] silce_vol = (silce_vol - silce_vol.min()) / (silce_vol.max() - silce_vol.min()) * 255 imageio.imwrite(os.path.join(savepath_seg, '{}.png'.format(num)), silce_seg) imageio.imwrite(os.path.join(savepath_vol, '{}.png'.format(num)), silce_vol) num += 1 # 将切片信息保存为png格式 return num if __name__ == '__main__': path= 'E:\\dataset\\LiTS17\\' savepath = 'E:\\dataset\\LiTS17\\2d\\' filenames = os.listdir(path + "segmentation") num = 0 for filename in filenames: num = save_fig(path, savepath, num, filename)

2023-05-25 上传

给出相同功能的代码import os import numpy as np import nibabel as nib import imageio from PIL import Image def read_niifile(niifilepath): # 读取niifile文件 img = nib.load(niifilepath) # 提取niifile文件 img_fdata = img.get_fdata(dtype='float32') return img_fdata def save_fig(niifilepath, savepath, num, name): # 保存为图片 name = name.split('-')[1] filepath_seg = niifilepath + "segmentation\" + "segmentation-" + name filepath_vol = niifilepath + "volume\" + "volume-" + name savepath_seg = savepath + "segmentation\" savepath_vol = savepath + "volume\" if not os.path.exists(savepath_seg): os.makedirs(savepath_seg) if not os.path.exists(savepath_vol): os.makedirs(savepath_vol) fdata_vol = read_niifile(filepath_vol) fdata_seg = read_niifile(filepath_seg) (x, y, z) = fdata_seg.shape total = x * y for k in range(z): silce_seg = fdata_seg[:, :, k] if silce_seg.max() == 0: continue else: silce_seg = (silce_seg - silce_seg.min()) / (silce_seg.max() - silce_seg.min()) * 255 silce_seg = np.uint8(Image.fromarray(silce_seg).convert('L')) silce_seg = cv2.threshold(silce_seg, 1, 255, cv2.THRESH_BINARY)[1] if (np.sum(silce_seg == 255) / total) > 0.015: silce_vol = fdata_vol[:, :, k] silce_vol = (silce_vol - silce_vol.min()) / (silce_vol.max() - silce_vol.min()) * 255 silce_vol = np.uint8(Image.fromarray(silce_vol).convert('L')) imageio.imwrite(os.path.join(savepath_seg, '{}.png'.format(num)), silce_seg) imageio.imwrite(os.path.join(savepath_vol, '{}.png'.format(num)), silce_vol) num += 1 return num if name == 'main': path = r'C:\Users\Administrator\Desktop\LiTS2017' savepath = r'C:\Users\Administrator\Desktop\2D-LiTS2017' filenames = os.listdir(path + "segmentation") num = 0 for filename in filenames: num = save_fig(path, savepath, num, filename) 。用另一段代码实现相同功能

2023-05-25 上传

import os import numpy as np import nibabel as nib import imageio import cv2 def read_niifile(niifilepath): # 读取niifile文件 img = nib.load(niifilepath) # 提取niifile文件 img_fdata = img.get_fdata(dtype='float32') return img_fdata def save_fig(niifilepath, savepath, num, name): # 保存为图片 name = name.split('-')[1] filepath_seg = niifilepath + "segmentation\\" + "segmentation-" + name filepath_vol = niifilepath + "volume\\" + "volume-" + name savepath_seg = savepath + "segmentation\\" savepath_vol = savepath + "volume\\" if not os.path.exists(savepath_seg): os.makedirs(savepath_seg) if not os.path.exists(savepath_vol): os.makedirs(savepath_vol) fdata_vol = read_niifile(filepath_vol) fdata_seg = read_niifile(filepath_seg) (x, y, z) = fdata_seg.shape total = x * y for k in range(z): silce_seg = fdata_seg[:, :, k] # 三个位置表示三个不同角度的切片 if silce_seg.max() == 0: continue else: silce_seg = (silce_seg - silce_seg.min()) / (silce_seg.max() - silce_seg.min()) * 255 silce_seg = cv2.threshold(silce_seg, 1, 255, cv2.THRESH_BINARY)[1] if (np.sum(silce_seg == 255) / total) > 0.015: silce_vol = fdata_vol[:, :, k] silce_vol = (silce_vol - silce_vol.min()) / (silce_vol.max() - silce_vol.min()) * 255 imageio.imwrite(os.path.join(savepath_seg, '{}.png'.format(num)), silce_seg) imageio.imwrite(os.path.join(savepath_vol, '{}.png'.format(num)), silce_vol) num += 1 # 将切片信息保存为png格式 return num if __name__ == '__main__': path = r"C:\Users\Administrator\Desktop\LiTS2017" savepath = r"C:\Users\Administrator\Desktop\2D-LiTS2017" filenames = os.listdir(path + "segmentation") num = 0 for filename in filenames: num = save_fig(path, savepath, num, filename)替换掉代码中的cv2模块,实现相同功能

2023-05-25 上传