最近给客户绘制脑部核磁共振图,那叫一个麻烦……标准的,确实只能使用西门子等与机器绑定的商业软件,但小编穷啊~所以只能用python了。 还好,有个python工具包看着绘图效果还不错。欣赏一下~ 本想着按照正常思路安装这个软件,没想到被耍了一个多星期,愣是没装上……不是这个工具安装难,是它需要的环境(blender软件)恶心……#github链接:https://github.com/razvanmarinescu/brain-coloring/
四年前的软件了,现在安装,各种不支持……一些功能函数都已经变了。还好小编不遗余力的,借助AI助手直接改通了
##千万别从github下载blender,根本装不上!!!##不信邪的小伙伴可以去https://download.blender.org/source/中自行下载,尝试安装一下~sudo apt-get install blender##这种安装方法,默认使用系统的python……##确认 Blender 使用的 Pythonblender --background --python-expr "import sys; print(sys.executable); print(sys.version)"##此处会显示:##Blender 4.0.2##Read prefs: "/home/suxx/.config/blender/4.0/config/userpref.blend"##/usr/bin/python3.12##3.12.3 (main, Jun 19 2026, 12:46:00) [GCC 13.3.0]sudo apt-get install python3-numpy python3-numpy-devsudo apt-get install python3-pandas
注:brain-coloring本身是基于blender 2.8做的。现在apt-get安装的是4.0.2版本的blender。下面才开始处理brain-coloring
wget https://github.com/razvanmarinescu/brain-coloring/archive/refs/heads/master.zip#wget下载不了的,那就用浏览器打开https://github.com/razvanmarinescu/brain-coloring/进行下载unzip brain-coloring-master.zipcd brain-coloring-master
#把下面的代码保存为xiugai.sh#!/bin/bashpython3 - <<'FIXSCRIPT'import reFILENAME = 'blendHelper.py'with open(FILENAME, 'r', encoding='utf-8') as f: content = f.read()original = content# === 1. .select = True/False -> .select_set(True/False) ===content = re.sub(r'(\w+(?:\[[^\]]+\])?)\.select = True', r'\1.select_set(True)', content)content = re.sub(r'(\w+(?:\[[^\]]+\])?)\.select = False', r'\1.select_set(False)', content)# === 2. scene.objects.link( -> scene.collection.objects.link( ===content = content.replace('scene.objects.link(', 'scene.collection.objects.link(')# === 3. horizon_color -> 节点系统背景色 (自动提取原行缩进) ===def fix_horizon(m): indent = m.group(1) return ( f"{indent}bpy.data.worlds['World'].use_nodes = True\n" f"{indent}bg_node = bpy.data.worlds['World'].node_tree.nodes['Background']\n" f"{indent}bg_node.inputs['Color'].default_value = (bckColor[0], bckColor[1], bckColor[2], 1.0)" )content = re.sub( r'^(\s*)bpy\.data\.worlds\[\'World\'\]\.horizon_color\s*=\s*bckColor', fix_horizon, content, flags=re.MULTILINE)# === 4. bpy.data.lamps -> bpy.data.lights ===content = content.replace('bpy.data.lamps', 'bpy.data.lights')# === 5. import_mesh.ply -> wm.ply_import ===content = content.replace('bpy.ops.import_mesh.ply', 'bpy.ops.wm.ply_import')# === 6. lamp_data.distance -> 注释掉 (废弃) ===content = re.sub( r'^(\s*)(\w+\.distance\s*=\s*distanceAll)', r'\1# \2 # Deprecated in Blender 4.0', content, flags=re.MULTILINE)# === 7. mat.diffuse_color = diffuse -> 4元素 RGBA ===content = content.replace( "mat.diffuse_color = diffuse", "mat.diffuse_color = (diffuse[0], diffuse[1], diffuse[2], 1.0)")# === 8. 3元组 diffuse_color -> 4元组 RGBA ===def fix_tuple(match): vals = match.group(1) parts = [p.strip() for p in vals.split(',')] if len(parts) >= 4: return match.group(0) return f".diffuse_color = ({vals}, 1.0)"content = re.sub(r"\.diffuse_color = \(([^)]+)\)", fix_tuple, content)# === 9. finalColor 赋值 (非元组变量) -> 4元素 ===content = content.replace( "bpy.data.materials['mat_%s' % regionName].diffuse_color = finalColor", "bpy.data.materials['mat_%s' % regionName].diffuse_color = (finalColor[0], finalColor[1], finalColor[2], 1.0)")# === 10. 删除废弃材质属性行 ===deprecated = ['mat.diffuse_shader','mat.diffuse_intensity','mat.specular_color', 'mat.specular_shader','mat.specular_intensity','mat.ambient', 'mat.use_transparency','mat.use_shadows']content = '\n'.join(line for line in content.split('\n') if not any(p in line for p in deprecated))# === 11. .alpha = X -> Principled BSDF Alpha 节点 ===lines = content.split('\n')new_lines = []for line in lines: stripped = line.lstrip() indent = line[:len(line)-len(stripped)] m = re.match(r'^(\w+(?:\[[^\]]+\])?)\.alpha = (.+)$', stripped) if m and not stripped.startswith('#'): var = m.group(1) val = m.group(2) new_lines.append(f'{indent}{var}.use_nodes = True') new_lines.append(f'{indent}if "Principled BSDF" in {var}.node_tree.nodes:') new_lines.append(f'{indent}{var}.node_tree.nodes["Principled BSDF"].inputs["Alpha"].default_value = {val}') else: new_lines.append(line)content = '\n'.join(new_lines)# === 12. makeMaterial 中添加 Base Color 节点设置 ===content = content.replace( 'mat.use_nodes = True\n if "Principled BSDF" in mat.node_tree.nodes:\n mat.node_tree.nodes["Principled BSDF"].inputs["Alpha"].default_value = alpha', 'mat.use_nodes = True\n if "Principled BSDF" in mat.node_tree.nodes:\n mat.node_tree.nodes["Principled BSDF"].inputs["Base Color"].default_value = (diffuse[0], diffuse[1], diffuse[2], 1.0)\n mat.node_tree.nodes["Principled BSDF"].inputs["Alpha"].default_value = alpha')with open(FILENAME, 'w', encoding='utf-8') as f: f.write(content)if content != original: print("=" * 60) print("blendHelper.py 一次性修复完成!") print("=" * 60) print(" 1. .select -> .select_set()") print(" 2. scene.objects.link -> scene.collection.objects.link") print(" 3. horizon_color -> 节点背景色 (缩进自适应)") print(" 4. bpy.data.lamps -> bpy.data.lights") print(" 5. import_mesh.ply -> wm.ply_import") print(" 6. lamp_data.distance -> 已注释") print(" 7. diffuse_color 3元组 -> 4元组 RGBA") print(" 8. 废弃材质属性 -> 已删除") print(" 9. .alpha -> Principled BSDF Alpha 节点") print(" 10. makeMaterial Base Color 节点") print("=" * 60)else: print("文件已是最新状态,无需修改。")FIXSCRIPT
在brain-coloring-master下运行:sh xiufu.sh============================================================blendHelper.py 一次性修复完成!============================================================ 1. .select -> .select_set() 2. scene.objects.link -> scene.collection.objects.link 3. horizon_color -> 节点背景色 (缩进自适应) 4. bpy.data.lamps -> bpy.data.lights 5. import_mesh.ply -> wm.ply_import 6. lamp_data.distance -> 已注释 7. diffuse_color 3元组 -> 4元组 RGBA 8. 废弃材质属性 -> 已删除 9. .alpha -> Principled BSDF Alpha 节点 10. makeMaterial Base Color 节点============================================================
继续在brain-coloring-master下执行:make PREFIX=/path/brain-coloring-master/
注:“/path/brain-coloring-master/”为brain-coloring-master的绝对路径。make PREFIX=/path/brain-coloring-masterconfigFile=config.py blender --background --python blendCreateSnapshot.pyBlender 4.0.2Read prefs: "/home/XXXX/.config/blender/4.0/config/userpref.blend"blender python: /usrinput/DK_template.csv{'Left-pericalcarine', 'Left-lateraloccipital', 'Left-superiortemporal', 'Left-rostralanteriorcingulate', 'Left-caudalanteriorcingulate', 'Right-caudalanteriorcingulate', 'Right-medialorbitofrontal', 'Left-entorhinal', 'Left-lateralorbitofrontal', 'Left-posteriorcingulate', 'Right-inferiortemporal', 'Right-rostralmiddlefrontal', 'Right-isthmuscingulate', 'Left-parstriangularis', 'Right-inferiorparietal', 'Left-bankssts', 'Right-superiorfrontal', 'Left-isthmuscingulate', 'Left-parahippocampal', 'Right-postcentral', 'Right-pericalcarine', 'Left-superiorfrontal', 'Left-fusiform', 'Right-middletemporal', 'Left-rostralmiddlefrontal', 'Right-frontalpole', 'Right-parstriangularis', 'Left-precuneus', 'Left-transversetemporal', 'Right-precentral', 'Right-cuneus', 'Right-paracentral', 'Left-supramarginal', 'Left-insula', 'Right-lateraloccipital', 'Right-superiorparietal', 'Left-frontalpole', 'Right-posteriorcingulate', 'Left-caudalmiddlefrontal', 'Left-inferiortemporal', 'Left-precentral', 'Right-caudalmiddlefrontal', 'Right-bankssts', 'Right-parahippocampal', 'Right-parsopercularis', 'Right-parsorbitalis', 'Right-precuneus', 'Left-inferiorparietal', 'Left-superiorparietal', 'Left-temporalpole', 'Right-lingual', 'Right-insula', 'Right-rostralanteriorcingulate', 'Right-lateralorbitofrontal', 'Right-supramarginal', 'Right-temporalpole', 'Left-lingual', 'Left-medialorbitofrontal', 'Left-parsopercularis', 'Right-transversetemporal', 'Left-paracentral', 'Left-parsorbitalis', 'Right-fusiform', 'Right-entorhinal', 'Left-postcentral', 'Left-cuneus', 'Right-superiortemporal', 'Left-middletemporal'}[]PLY import of 'lh.pial.DK.lateraloccipital.ply' took 17.2 msPLY import of 'rh.pial.DK.pericalcarine.ply' took 9.5 msPLY import of 'lh.pial.DK.caudalanteriorcingulate.ply' took 4.8 msPLY import of 'rh.pial.DK.transversetemporal.ply' took 5.4 msPLY import of 'lh.pial.DK.postcentral.ply' took 15.6 msPLY import of 'lh.pial.DK.transversetemporal.ply' took 5.9 msPLY import of 'rh.pial.DK.superiortemporal.ply' took 14.1 msPLY import of 'lh.pial.DK.frontalpole.ply' took 4.8 msPLY import of 'rh.pial.DK.caudalanteriorcingulate.ply' took 7.9 msPLY import of 'lh.pial.DK.bankssts.ply' took 10.0 msPLY import of 'lh.pial.DK.parsopercularis.ply' took 8.7 msPLY import of 'rh.pial.DK.bankssts.ply' took 7.1 msPLY import of 'lh.pial.DK.inferiortemporal.ply' took 14.2 msPLY import of 'rh.pial.DK.paracentral.ply' took 9.3 msPLY import of 'rh.pial.DK.precentral.ply' took 16.5 msPLY import of 'lh.pial.DK.precentral.ply' took 19.8 msPLY import of 'rh.pial.DK.superiorfrontal.ply' took 23.1 msPLY import of 'rh.pial.DK.superiorparietal.ply' took 21.1 msPLY import of 'lh.pial.DK.parahippocampal.ply' took 8.0 msPLY import of 'lh.pial.DK.parstriangularis.ply' took 10.1 msPLY import of 'rh.pial.DK.parahippocampal.ply' took 7.9 msPLY import of 'rh.pial.DK.caudalmiddlefrontal.ply' took 11.1 msPLY import of 'rh.pial.DK.rostralmiddlefrontal.ply' took 24.7 msPLY import of 'rh.pial.DK.supramarginal.ply' took 15.8 msPLY import of 'rh.pial.DK.insula.ply' took 12.0 msPLY import of 'lh.pial.DK.rostralmiddlefrontal.ply' took 21.7 msPLY import of 'rh.pial.DK.entorhinal.ply' took 6.4 msPLY import of 'lh.pial.DK.medialorbitofrontal.ply' took 10.9 msPLY import of 'lh.pial.DK.unknown.ply' took 18.0 msPLY import of 'lh.pial.DK.entorhinal.ply' took 5.5 msPLY import of 'rh.pial.DK.frontalpole.ply' took 5.1 msPLY import of 'rh.pial.DK.lingual.ply' took 12.8 msPLY import of 'lh.pial.DK.pericalcarine.ply' took 9.0 msPLY import of 'rh.pial.DK.cuneus.ply' took 9.3 msPLY import of 'lh.pial.DK.supramarginal.ply' took 17.5 msPLY import of 'rh.pial.DK.posteriorcingulate.ply' took 8.9 msPLY import of 'lh.pial.DK.cuneus.ply' took 9.0 msPLY import of 'rh.pial.DK.rostralanteriorcingulate.ply' took 7.3 msPLY import of 'lh.pial.DK.isthmuscingulate.ply' took 8.0 msPLY import of 'rh.pial.DK.parsopercularis.ply' took 8.5 msPLY import of 'rh.pial.DK.parsorbitalis.ply' took 6.3 msPLY import of 'rh.pial.DK.parstriangularis.ply' took 11.7 msPLY import of 'lh.pial.DK.insula.ply' took 9.8 msPLY import of 'lh.pial.DK.temporalpole.ply' took 4.6 msPLY import of 'lh.pial.DK.lingual.ply' took 13.6 msPLY import of 'rh.pial.DK.precuneus.ply' took 15.2 msPLY import of 'rh.pial.DK.fusiform.ply' took 13.8 msPLY import of 'lh.pial.DK.fusiform.ply' took 14.5 msPLY import of 'rh.pial.DK.temporalpole.ply' took 5.3 msPLY import of 'lh.pial.DK.caudalmiddlefrontal.ply' took 14.3 msPLY import of 'lh.pial.DK.superiortemporal.ply' took 16.1 msPLY import of 'lh.pial.DK.superiorfrontal.ply' took 25.1 msPLY import of 'rh.pial.DK.lateraloccipital.ply' took 15.7 msPLY import of 'rh.pial.DK.inferiortemporal.ply' took 15.1 msPLY import of 'rh.pial.DK.postcentral.ply' took 17.6 msPLY import of 'rh.pial.DK.unknown.ply' took 18.4 msPLY import of 'lh.pial.DK.parsorbitalis.ply' took 6.5 msPLY import of 'lh.pial.DK.lateralorbitofrontal.ply' took 14.2 msPLY import of 'lh.pial.DK.superiorparietal.ply' took 19.7 msPLY import of 'lh.pial.DK.posteriorcingulate.ply' took 8.8 msPLY import of 'lh.pial.DK.precuneus.ply' took 18.3 msPLY import of 'rh.pial.DK.medialorbitofrontal.ply' took 11.3 msPLY import of 'rh.pial.DK.lateralorbitofrontal.ply' took 16.6 msPLY import of 'rh.pial.DK.isthmuscingulate.ply' took 7.6 msPLY import of 'lh.pial.DK.paracentral.ply' took 9.9 msPLY import of 'lh.pial.DK.inferiorparietal.ply' took 19.6 msPLY import of 'rh.pial.DK.middletemporal.ply' took 15.8 msPLY import of 'lh.pial.DK.rostralanteriorcingulate.ply' took 7.3 msPLY import of 'lh.pial.DK.middletemporal.ply' took 15.8 msPLY import of 'rh.pial.DK.inferiorparietal.ply' took 21.2 msPLY import of 'Left-Accumbens-area.ply' took 4.8 msPLY import of 'Left-Caudate.ply' took 7.6 msPLY import of 'Left-Cerebellum-White-Matter.ply' took 19.3 msPLY import of 'Left-Inf-Lat-Vent.ply' took 4.4 msPLY import of 'Left-Pallidum.ply' took 7.3 msPLY import of 'Left-Thalamus-Proper.ply' took 10.4 msPLY import of 'Left-Amygdala.ply' took 6.8 msPLY import of 'Left-Cerebellum-Cortex.ply' took 46.0 msPLY import of 'Left-Hippocampus.ply' took 8.6 msPLY import of 'Left-Lateral-Ventricle.ply' took 11.3 msPLY import of 'Left-Putamen.ply' took 9.5 msPLY import of 'Left-VentralDC.ply' took 8.8 msPLY import of 'Right-Accumbens-area.ply' took 5.2 msPLY import of 'Right-Caudate.ply' took 7.8 msPLY import of 'Right-Cerebellum-White-Matter.ply' took 18.9 msPLY import of 'Right-Inf-Lat-Vent.ply' took 5.0 msPLY import of 'Right-Pallidum.ply' took 6.0 msPLY import of 'Right-Thalamus-Proper.ply' took 9.0 msPLY import of 'Right-Amygdala.ply' took 6.3 msPLY import of 'Right-Cerebellum-Cortex.ply' took 42.5 msPLY import of 'Right-Hippocampus.ply' took 10.2 msPLY import of 'Right-Lateral-Ventricle.ply' took 11.0 msPLY import of 'Right-Putamen.ply' took 10.2 msPLY import of 'Right-VentralDC.ply' took 7.7 ms-------------input/DK_template.csv-------------rendering file output/DK_output/top_Image_0.pngFra:1 Mem:141.40M (Peak 142.49M) | Time:00:00.63 | Syncing CameraFra:1 Mem:141.40M (Peak 142.49M) | Time:00:00.63 | Syncing lh.pial.DK.lateraloccipitalFra:1 Mem:142.71M (Peak 142.71M) | Time:00:00.67 | Syncing rh.pial.DK.pericalcarineFra:1 Mem:143.08M (Peak 143.08M) | Time:00:00.67 | Syncing lh.pial.DK.caudalanteriorcingulatFra:1 Mem:143.25M (Peak 143.25M) | Time:00:00.67 | Syncing rh.pial.DK.transversetemporalFra:1 Mem:143.40M (Peak 143.40M) | Time:00:00.67 | Syncing lh.pial.DK.postcentralFra:1 Mem:144.63M (Peak 144.63M) | Time:00:00.67 | Syncing lh.pial.DK.transversetemporalFra:1 Mem:144.77M (Peak 144.77M) | Time:00:00.67 | Syncing rh.pial.DK.superiortemporalFra:1 Mem:145.75M (Peak 145.80M) | Time:00:00.68 | Syncing lh.pial.DK.frontalpoleFra:1 Mem:145.83M (Peak 145.83M) | Time:00:00.68 | Syncing rh.pial.DK.caudalanteriorcingulatFra:1 Mem:146.11M (Peak 146.11M) | Time:00:00.68 | Syncing lh.pial.DK.banksstsFra:1 Mem:146.51M (Peak 146.51M) | Time:00:00.68 | Syncing lh.pial.DK.parsopercularisFra:1 Mem:146.98M (Peak 146.98M) | Time:00:00.68 | Syncing rh.pial.DK.banksstsFra:1 Mem:147.27M (Peak 147.27M) | Time:00:00.68 | Syncing lh.pial.DK.inferiortemporalFra:1 Mem:148.26M (Peak 148.31M) | Time:00:00.68 | Syncing rh.pial.DK.paracentralFra:1 Mem:148.80M (Peak 148.80M) | Time:00:00.68 | Syncing rh.pial.DK.precentralFra:1 Mem:150.11M (Peak 150.11M) | Time:00:00.68 | Syncing lh.pial.DK.precentralFra:1 Mem:151.71M (Peak 151.71M) | Time:00:00.69 | Syncing rh.pial.DK.superiorfrontalFra:1 Mem:153.73M (Peak 153.73M) | Time:00:00.69 | Syncing rh.pial.DK.superiorparietalFra:1 Mem:155.21M (Peak 155.21M) | Time:00:00.69 | Syncing lh.pial.DK.parahippocampalFra:1 Mem:155.51M (Peak 155.51M) | Time:00:00.69 | Syncing lh.pial.DK.parstriangularisFra:1 Mem:155.89M (Peak 155.89M) | Time:00:00.69 | Syncing rh.pial.DK.parahippocampalFra:1 Mem:156.12M (Peak 156.12M) | Time:00:00.69 | Syncing rh.pial.DK.caudalmiddlefrontalFra:1 Mem:156.80M (Peak 156.80M) | Time:00:00.69 | Syncing rh.pial.DK.rostralmiddlefrontalFra:1 Mem:158.61M (Peak 158.61M) | Time:00:00.70 | Syncing rh.pial.DK.supramarginalFra:1 Mem:159.68M (Peak 159.73M) | Time:00:00.70 | Syncing rh.pial.DK.insulaFra:1 Mem:160.29M (Peak 160.29M) | Time:00:00.70 | Syncing lh.pial.DK.rostralmiddlefrontalFra:1 Mem:161.84M (Peak 161.84M) | Time:00:00.70 | Syncing rh.pial.DK.entorhinalFra:1 Mem:161.95M (Peak 161.95M) | Time:00:00.70 | Syncing lh.pial.DK.medialorbitofrontalFra:1 Mem:162.53M (Peak 162.53M) | Time:00:00.70 | Syncing lh.pial.DK.unknownFra:1 Mem:163.93M (Peak 163.93M) | Time:00:00.71 | Syncing lh.pial.DK.entorhinalFra:1 Mem:164.08M (Peak 164.08M) | Time:00:00.71 | Syncing rh.pial.DK.frontalpoleFra:1 Mem:164.15M (Peak 164.15M) | Time:00:00.71 | Syncing rh.pial.DK.lingualFra:1 Mem:164.96M (Peak 164.96M) | Time:00:00.71 | Syncing lh.pial.DK.pericalcarineFra:1 Mem:165.34M (Peak 165.34M) | Time:00:00.71 | Syncing rh.pial.DK.cuneusFra:1 Mem:165.78M (Peak 165.78M) | Time:00:00.71 | Syncing lh.pial.DK.supramarginalFra:1 Mem:167.01M (Peak 167.01M) | Time:00:00.71 | Syncing rh.pial.DK.posteriorcingulateFra:1 Mem:167.43M (Peak 167.43M) | Time:00:00.71 | Syncing lh.pial.DK.cuneusFra:1 Mem:167.87M (Peak 167.87M) | Time:00:00.71 | Syncing rh.pial.DK.rostralanteriorcingulaFra:1 Mem:168.06M (Peak 168.06M) | Time:00:00.71 | Syncing lh.pial.DK.isthmuscingulateFra:1 Mem:168.39M (Peak 168.39M) | Time:00:00.72 | Syncing rh.pial.DK.parsopercularisFra:1 Mem:168.82M (Peak 168.82M) | Time:00:00.72 | Syncing rh.pial.DK.parsorbitalisFra:1 Mem:169.10M (Peak 169.10M) | Time:00:00.72 | Syncing rh.pial.DK.parstriangularisFra:1 Mem:169.74M (Peak 169.74M) | Time:00:00.72 | Syncing lh.pial.DK.insulaFra:1 Mem:170.39M (Peak 170.39M) | Time:00:00.72 | Syncing lh.pial.DK.temporalpoleFra:1 Mem:170.53M (Peak 170.53M) | Time:00:00.72 | Syncing lh.pial.DK.lingualFra:1 Mem:171.41M (Peak 171.41M) | Time:00:00.72 | Syncing rh.pial.DK.precuneusFra:1 Mem:172.56M (Peak 172.56M) | Time:00:00.73 | Syncing rh.pial.DK.fusiformFra:1 Mem:173.47M (Peak 173.47M) | Time:00:00.73 | Syncing lh.pial.DK.fusiformFra:1 Mem:174.39M (Peak 174.39M) | Time:00:00.73 | Syncing rh.pial.DK.temporalpoleFra:1 Mem:174.52M (Peak 174.52M) | Time:00:00.73 | Syncing lh.pial.DK.caudalmiddlefrontalFra:1 Mem:175.27M (Peak 175.27M) | Time:00:00.73 | Syncing lh.pial.DK.superiortemporalFra:1 Mem:176.36M (Peak 176.41M) | Time:00:00.73 | Syncing lh.pial.DK.superiorfrontalFra:1 Mem:178.53M (Peak 178.53M) | Time:00:00.74 | Syncing rh.pial.DK.lateraloccipitalFra:1 Mem:179.69M (Peak 179.69M) | Time:00:00.74 | Syncing rh.pial.DK.inferiortemporalFra:1 Mem:180.70M (Peak 180.75M) | Time:00:00.74 | Syncing rh.pial.DK.postcentralFra:1 Mem:181.96M (Peak 181.96M) | Time:00:00.74 | Syncing rh.pial.DK.unknownFra:1 Mem:183.36M (Peak 183.36M) | Time:00:00.74 | Syncing lh.pial.DK.parsorbitalisFra:1 Mem:183.54M (Peak 183.54M) | Time:00:00.74 | Syncing lh.pial.DK.lateralorbitofrontalFra:1 Mem:184.47M (Peak 184.47M) | Time:00:00.74 | Syncing lh.pial.DK.superiorparietalFra:1 Mem:185.90M (Peak 185.90M) | Time:00:00.75 | Syncing lh.pial.DK.posteriorcingulateFra:1 Mem:186.24M (Peak 186.24M) | Time:00:00.75 | Syncing lh.pial.DK.precuneusFra:1 Mem:187.30M (Peak 187.35M) | Time:00:00.75 | Syncing rh.pial.DK.medialorbitofrontalFra:1 Mem:187.93M (Peak 187.93M) | Time:00:00.75 | Syncing rh.pial.DK.lateralorbitofrontalFra:1 Mem:188.82M (Peak 188.82M) | Time:00:00.75 | Syncing rh.pial.DK.isthmuscingulateFra:1 Mem:189.12M (Peak 189.12M) | Time:00:00.75 | Syncing lh.pial.DK.paracentralFra:1 Mem:189.60M (Peak 189.60M) | Time:00:00.75 | Syncing lh.pial.DK.inferiorparietalFra:1 Mem:191.00M (Peak 191.00M) | Time:00:00.76 | Syncing rh.pial.DK.middletemporalFra:1 Mem:192.11M (Peak 192.11M) | Time:00:00.76 | Syncing lh.pial.DK.rostralanteriorcingulaFra:1 Mem:192.37M (Peak 192.37M) | Time:00:00.76 | Syncing lh.pial.DK.middletemporalFra:1 Mem:193.37M (Peak 193.42M) | Time:00:00.76 | Syncing rh.pial.DK.inferiorparietalFra:1 Mem:195.09M (Peak 195.09M) | Time:00:00.76 | Syncing Left-Accumbens-areaFra:1 Mem:195.21M (Peak 195.21M) | Time:00:00.76 | Syncing Left-CaudateFra:1 Mem:195.70M (Peak 195.70M) | Time:00:00.76 | Syncing Left-Cerebellum-White-MatterFra:1 Mem:197.66M (Peak 197.66M) | Time:00:00.77 | Syncing Left-Inf-Lat-VentFra:1 Mem:197.71M (Peak 197.71M) | Time:00:00.77 | Syncing Left-PallidumFra:1 Mem:197.96M (Peak 197.96M) | Time:00:00.77 | Syncing Left-Thalamus-ProperFra:1 Mem:198.60M (Peak 198.60M) | Time:00:00.77 | Syncing Left-AmygdalaFra:1 Mem:198.80M (Peak 198.80M) | Time:00:00.77 | Syncing Left-Cerebellum-CortexFra:1 Mem:203.93M (Peak 204.15M) | Time:00:00.77 | Syncing Left-HippocampusFra:1 Mem:204.51M (Peak 204.51M) | Time:00:00.78 | Syncing Left-Lateral-VentricleFra:1 Mem:205.40M (Peak 205.40M) | Time:00:00.78 | Syncing Left-PutamenFra:1 Mem:205.99M (Peak 205.99M) | Time:00:00.78 | Syncing Left-VentralDCFra:1 Mem:206.53M (Peak 206.53M) | Time:00:00.78 | Syncing Right-Accumbens-areaFra:1 Mem:206.67M (Peak 206.67M) | Time:00:00.78 | Syncing Right-CaudateFra:1 Mem:207.18M (Peak 207.18M) | Time:00:00.78 | Syncing Right-Cerebellum-White-MatterFra:1 Mem:208.97M (Peak 208.97M) | Time:00:00.79 | Syncing Right-Inf-Lat-VentFra:1 Mem:209.05M (Peak 209.05M) | Time:00:00.79 | Syncing Right-PallidumFra:1 Mem:209.26M (Peak 209.26M) | Time:00:00.80 | Syncing Right-Thalamus-ProperFra:1 Mem:209.83M (Peak 209.83M) | Time:00:00.80 | Syncing Right-AmygdalaFra:1 Mem:210.03M (Peak 210.03M) | Time:00:00.80 | Syncing Right-Cerebellum-CortexFra:1 Mem:214.69M (Peak 214.89M) | Time:00:00.80 | Syncing Right-HippocampusFra:1 Mem:215.28M (Peak 215.28M) | Time:00:00.80 | Syncing Right-Lateral-VentricleFra:1 Mem:216.00M (Peak 216.00M) | Time:00:00.80 | Syncing Right-PutamenFra:1 Mem:216.54M (Peak 216.54M) | Time:00:00.80 | Syncing Right-VentralDCFra:1 Mem:217.06M (Peak 217.06M) | Time:00:00.81 | Syncing Lamp1Fra:1 Mem:217.06M (Peak 217.06M) | Time:00:00.81 | Syncing Lamp2Fra:1 Mem:217.06M (Peak 217.06M) | Time:00:00.81 | Syncing Lamp3Fra:1 Mem:217.06M (Peak 217.06M) | Time:00:00.81 | Syncing Lamp4Fra:1 Mem:217.01M (Peak 217.06M) | Time:00:01.00 | Rendering 1 / 64 samplesFra:1 Mem:155.70M (Peak 217.06M) | Time:00:15.70 | Rendering 26 / 64 samplesFra:1 Mem:155.70M (Peak 217.06M) | Time:00:27.95 | Rendering 51 / 64 samplesFra:1 Mem:155.70M (Peak 217.06M) | Time:00:35.46 | Rendering 64 / 64 samplesSaved: 'output/DK_output/top_Image_0.png'Time: 00:37.11 (Saving: 00:00.81)rendering file output/DK_output/top_Image_1.pngFra:1 Mem:155.06M (Peak 155.06M) | Time:00:00.19 | Syncing CameraFra:1 Mem:155.06M (Peak 155.06M) | Time:00:00.19 | Syncing lh.pial.DK.lateraloccipitalFra:1 Mem:156.11M (Peak 156.17M) | Time:00:00.19 | Syncing rh.pial.DK.pericalcarineFra:1 Mem:156.41M (Peak 156.41M) | Time:00:00.19 | Syncing lh.pial.DK.caudalanteriorcingulatFra:1 Mem:156.56M (Peak 156.56M) | Time:00:00.19 | Syncing rh.pial.DK.transversetemporalFra:1 Mem:156.68M (Peak 156.68M) | Time:00:00.19 | Syncing lh.pial.DK.postcentralFra:1 Mem:157.68M (Peak 157.74M) | Time:00:00.19 | Syncing lh.pial.DK.transversetemporalFra:1 Mem:157.80M (Peak 157.80M) | Time:00:00.19 | Syncing rh.pial.DK.superiortemporalFra:1 Mem:158.61M (Peak 158.61M) | Time:00:00.19 | Syncing lh.pial.DK.frontalpoleFra:1 Mem:158.67M (Peak 158.67M) | Time:00:00.19 | Syncing rh.pial.DK.caudalanteriorcingulatFra:1 Mem:158.90M (Peak 158.90M) | Time:00:00.19 | Syncing lh.pial.DK.banksstsFra:1 Mem:159.23M (Peak 159.23M) | Time:00:00.19 | Syncing lh.pial.DK.parsopercularisFra:1 Mem:159.62M (Peak 159.62M) | Time:00:00.19 | Syncing rh.pial.DK.banksstsFra:1 Mem:159.85M (Peak 159.85M) | Time:00:00.19 | Syncing lh.pial.DK.inferiortemporalFra:1 Mem:160.67M (Peak 160.67M) | Time:00:00.19 | Syncing rh.pial.DK.paracentralFra:1 Mem:161.11M (Peak 161.11M) | Time:00:00.19 | Syncing rh.pial.DK.precentralFra:1 Mem:162.18M (Peak 162.25M) | Time:00:00.20 | Syncing lh.pial.DK.precentralFra:1 Mem:163.50M (Peak 163.50M) | Time:00:00.20 | Syncing rh.pial.DK.superiorfrontalFra:1 Mem:165.15M (Peak 165.15M) | Time:00:00.20 | Syncing rh.pial.DK.superiorparietalFra:1 Mem:166.36M (Peak 166.36M) | Time:00:00.20 | Syncing lh.pial.DK.parahippocampalFra:1 Mem:166.61M (Peak 166.61M) | Time:00:00.20 | Syncing lh.pial.DK.parstriangularisFra:1 Mem:166.92M (Peak 166.92M) | Time:00:00.20 | Syncing rh.pial.DK.parahippocampalFra:1 Mem:167.11M (Peak 167.11M) | Time:00:00.20 | Syncing rh.pial.DK.caudalmiddlefrontalFra:1 Mem:167.67M (Peak 167.67M) | Time:00:00.20 | Syncing rh.pial.DK.rostralmiddlefrontalFra:1 Mem:169.15M (Peak 169.15M) | Time:00:00.20 | Syncing rh.pial.DK.supramarginalFra:1 Mem:170.03M (Peak 170.03M) | Time:00:00.20 | Syncing rh.pial.DK.insulaFra:1 Mem:170.52M (Peak 170.52M) | Time:00:00.20 | Syncing lh.pial.DK.rostralmiddlefrontalFra:1 Mem:171.80M (Peak 171.80M) | Time:00:00.20 | Syncing rh.pial.DK.entorhinalFra:1 Mem:171.89M (Peak 171.89M) | Time:00:00.20 | Syncing lh.pial.DK.medialorbitofrontalFra:1 Mem:172.36M (Peak 172.36M) | Time:00:00.20 | Syncing lh.pial.DK.unknownFra:1 Mem:173.51M (Peak 173.51M) | Time:00:00.21 | Syncing lh.pial.DK.entorhinalFra:1 Mem:173.63M (Peak 173.63M) | Time:00:00.21 | Syncing rh.pial.DK.frontalpoleFra:1 Mem:173.69M (Peak 173.69M) | Time:00:00.21 | Syncing rh.pial.DK.lingualFra:1 Mem:174.36M (Peak 174.36M) | Time:00:00.21 | Syncing lh.pial.DK.pericalcarineFra:1 Mem:174.67M (Peak 174.67M) | Time:00:00.21 | Syncing rh.pial.DK.cuneusFra:1 Mem:175.03M (Peak 175.03M) | Time:00:00.21 | Syncing lh.pial.DK.supramarginalFra:1 Mem:176.03M (Peak 176.09M) | Time:00:00.21 | Syncing rh.pial.DK.posteriorcingulateFra:1 Mem:176.38M (Peak 176.38M) | Time:00:00.21 | Syncing lh.pial.DK.cuneusFra:1 Mem:176.74M (Peak 176.74M) | Time:00:00.21 | Syncing rh.pial.DK.rostralanteriorcingulaFra:1 Mem:176.90M (Peak 176.90M) | Time:00:00.21 | Syncing lh.pial.DK.isthmuscingulateFra:1 Mem:177.17M (Peak 177.17M) | Time:00:00.21 | Syncing rh.pial.DK.parsopercularisFra:1 Mem:177.53M (Peak 177.53M) | Time:00:00.21 | Syncing rh.pial.DK.parsorbitalisFra:1 Mem:177.76M (Peak 177.76M) | Time:00:00.21 | Syncing rh.pial.DK.parstriangularisFra:1 Mem:178.28M (Peak 178.28M) | Time:00:00.21 | Syncing lh.pial.DK.insulaFra:1 Mem:178.81M (Peak 178.81M) | Time:00:00.22 | Syncing lh.pial.DK.temporalpoleFra:1 Mem:178.93M (Peak 178.93M) | Time:00:00.22 | Syncing lh.pial.DK.lingualFra:1 Mem:179.65M (Peak 179.65M) | Time:00:00.22 | Syncing rh.pial.DK.precuneusFra:1 Mem:180.60M (Peak 180.65M) | Time:00:00.22 | Syncing rh.pial.DK.fusiformFra:1 Mem:181.34M (Peak 181.34M) | Time:00:00.22 | Syncing lh.pial.DK.fusiformFra:1 Mem:182.10M (Peak 182.10M) | Time:00:00.22 | Syncing rh.pial.DK.temporalpoleFra:1 Mem:182.20M (Peak 182.20M) | Time:00:00.22 | Syncing lh.pial.DK.caudalmiddlefrontalFra:1 Mem:182.82M (Peak 182.82M) | Time:00:00.22 | Syncing lh.pial.DK.superiortemporalFra:1 Mem:183.71M (Peak 183.71M) | Time:00:00.22 | Syncing lh.pial.DK.superiorfrontalFra:1 Mem:185.49M (Peak 185.49M) | Time:00:00.22 | Syncing rh.pial.DK.lateraloccipitalFra:1 Mem:186.44M (Peak 186.49M) | Time:00:00.22 | Syncing rh.pial.DK.inferiortemporalFra:1 Mem:187.26M (Peak 187.26M) | Time:00:00.23 | Syncing rh.pial.DK.postcentralFra:1 Mem:188.29M (Peak 188.36M) | Time:00:00.23 | Syncing rh.pial.DK.unknownFra:1 Mem:189.44M (Peak 189.44M) | Time:00:00.23 | Syncing lh.pial.DK.parsorbitalisFra:1 Mem:189.59M (Peak 189.59M) | Time:00:00.23 | Syncing lh.pial.DK.lateralorbitofrontalFra:1 Mem:190.35M (Peak 190.35M) | Time:00:00.23 | Syncing lh.pial.DK.superiorparietalFra:1 Mem:191.52M (Peak 191.52M) | Time:00:00.23 | Syncing lh.pial.DK.posteriorcingulateFra:1 Mem:191.80M (Peak 191.80M) | Time:00:00.23 | Syncing lh.pial.DK.precuneusFra:1 Mem:192.67M (Peak 192.67M) | Time:00:00.23 | Syncing rh.pial.DK.medialorbitofrontalFra:1 Mem:193.19M (Peak 193.19M) | Time:00:00.23 | Syncing rh.pial.DK.lateralorbitofrontalFra:1 Mem:193.92M (Peak 193.92M) | Time:00:00.23 | Syncing rh.pial.DK.isthmuscingulateFra:1 Mem:194.17M (Peak 194.17M) | Time:00:00.23 | Syncing lh.pial.DK.paracentralFra:1 Mem:194.57M (Peak 194.57M) | Time:00:00.23 | Syncing lh.pial.DK.inferiorparietalFra:1 Mem:195.71M (Peak 195.71M) | Time:00:00.24 | Syncing rh.pial.DK.middletemporalFra:1 Mem:196.61M (Peak 196.61M) | Time:00:00.24 | Syncing lh.pial.DK.rostralanteriorcingulaFra:1 Mem:196.83M (Peak 196.83M) | Time:00:00.24 | Syncing lh.pial.DK.middletemporalFra:1 Mem:197.65M (Peak 197.65M) | Time:00:00.24 | Syncing rh.pial.DK.inferiorparietalFra:1 Mem:199.06M (Peak 199.06M) | Time:00:00.24 | Syncing Left-Accumbens-areaFra:1 Mem:199.16M (Peak 199.16M) | Time:00:00.24 | Syncing Left-CaudateFra:1 Mem:199.56M (Peak 199.56M) | Time:00:00.24 | Syncing Left-Cerebellum-White-MatterFra:1 Mem:201.16M (Peak 201.16M) | Time:00:00.24 | Syncing Left-Inf-Lat-VentFra:1 Mem:201.21M (Peak 201.21M) | Time:00:00.24 | Syncing Left-PallidumFra:1 Mem:201.42M (Peak 201.42M) | Time:00:00.24 | Syncing Left-Thalamus-ProperFra:1 Mem:201.94M (Peak 201.94M) | Time:00:00.24 | Syncing Left-AmygdalaFra:1 Mem:202.11M (Peak 202.11M) | Time:00:00.24 | Syncing Left-Cerebellum-CortexFra:1 Mem:206.30M (Peak 206.53M) | Time:00:00.25 | Syncing Left-HippocampusFra:1 Mem:206.78M (Peak 206.78M) | Time:00:00.25 | Syncing Left-Lateral-VentricleFra:1 Mem:207.51M (Peak 207.51M) | Time:00:00.25 | Syncing Left-PutamenFra:1 Mem:208.00M (Peak 208.00M) | Time:00:00.25 | Syncing Left-VentralDCFra:1 Mem:208.44M (Peak 208.44M) | Time:00:00.25 | Syncing Right-Accumbens-areaFra:1 Mem:208.56M (Peak 208.56M) | Time:00:00.25 | Syncing Right-CaudateFra:1 Mem:208.97M (Peak 208.97M) | Time:00:00.25 | Syncing Right-Cerebellum-White-MatterFra:1 Mem:210.44M (Peak 210.44M) | Time:00:00.25 | Syncing Right-Inf-Lat-VentFra:1 Mem:210.50M (Peak 210.50M) | Time:00:00.25 | Syncing Right-PallidumFra:1 Mem:210.67M (Peak 210.67M) | Time:00:00.25 | Syncing Right-Thalamus-ProperFra:1 Mem:211.15M (Peak 211.15M) | Time:00:00.25 | Syncing Right-AmygdalaFra:1 Mem:211.31M (Peak 211.31M) | Time:00:00.25 | Syncing Right-Cerebellum-CortexFra:1 Mem:215.12M (Peak 215.33M) | Time:00:00.26 | Syncing Right-HippocampusFra:1 Mem:215.61M (Peak 215.61M) | Time:00:00.26 | Syncing Right-Lateral-VentricleFra:1 Mem:216.20M (Peak 216.20M) | Time:00:00.26 | Syncing Right-PutamenFra:1 Mem:216.64M (Peak 216.64M) | Time:00:00.26 | Syncing Right-VentralDCFra:1 Mem:217.07M (Peak 217.07M) | Time:00:00.26 | Syncing Lamp1Fra:1 Mem:217.07M (Peak 217.07M) | Time:00:00.26 | Syncing Lamp2Fra:1 Mem:217.07M (Peak 217.07M) | Time:00:00.26 | Syncing Lamp3Fra:1 Mem:217.07M (Peak 217.07M) | Time:00:00.26 | Syncing Lamp4Fra:1 Mem:217.01M (Peak 217.07M) | Time:00:00.39 | Rendering 1 / 64 samplesFra:1 Mem:155.70M (Peak 217.07M) | Time:00:15.20 | Rendering 26 / 64 samplesFra:1 Mem:155.70M (Peak 217.07M) | Time:00:29.60 | Rendering 51 / 64 samplesFra:1 Mem:155.70M (Peak 217.07M) | Time:00:38.17 | Rendering 64 / 64 samplesSaved: 'output/DK_output/top_Image_1.png'Time: 00:39.67 (Saving: 00:00.60)Blender quit
在执行命令之前,需要将config.py代码中,红色框内的参数进行调整。由于原始命令总要修改config.py,太麻烦了,小编结合AI助手写了一个run.py,更方便使用~#将该脚本保存为run.py,与blendHelper.py在同一个目录下#!/usr/bin/env python3"""Wrapper script for brain-coloring pipeline.Overrides config.py settings via command-line arguments and runs blendCreateSnapshot.py.Optionally compiles report.tex to PDF using pdflatex."""import argparseimport osimport sysimport subprocessdef main(): parser = argparse.ArgumentParser( description="Run brain coloring with custom parameters.", epilog="Any parameter not provided will use the value from the base config.py." ) parser.add_argument('--input', help='INPUT_FILE path (CSV with region values)') parser.add_argument('--output', help='OUTPUT_FOLDER path') parser.add_argument('--atlas', choices=['DK', 'Destrieux', 'Tourville', 'Mice', 'Dorr', 'Dsurque', 'Custom'], help='ATLAS name') parser.add_argument('--brain_type', choices=['pial', 'inflated', 'white'], help='BRAIN_TYPE (pial/inflated/white)') parser.add_argument('--img_type', help='IMG_TYPE, e.g. cortical-inner-right-hemisphere, top, bottom, etc.') parser.add_argument('--colors', nargs='+', help='Color stops as R,G B tuples, e.g. --colors "1,1,1" "1,1,0" "1,0.4,0" "1,0,0"') parser.add_argument('--resolution', help='WIDTH,HEIGHT, e.g. 1200,900') parser.add_argument('--background', help='R,G,B background color, e.g. 1,1,1') parser.add_argument('--base_config', default='config.py', help='Path to base config file (default: config.py)') parser.add_argument('--pdf', action='store_true', help='Automatically compile report.tex to PDF with pdflatex (requires pdflatex installed)') args = parser.parse_args() # If --pdf is used, --output must be provided (to locate report.tex) if args.pdf and not args.output: parser.error("--pdf requires --output to locate the report.tex file.") # Build override lines: import everything from base config, then override specified variables. override_lines = [f"from {args.base_config.replace('.py', '')} import *"] if args.input: override_lines.append(f"INPUT_FILE = {repr(args.input)}") if args.output: override_lines.append(f"OUTPUT_FOLDER = {repr(args.output)}") if args.atlas: override_lines.append(f"ATLAS = {repr(args.atlas)}") if args.brain_type: override_lines.append(f"BRAIN_TYPE = {repr(args.brain_type)}") if args.img_type: override_lines.append(f"IMG_TYPE = {repr(args.img_type)}") if args.colors: colors_list = [] for c in args.colors: parts = c.split(',') if len(parts) != 3: raise ValueError(f"Invalid color format: {c}, expected R,G,B") colors_list.append(tuple(float(x.strip()) for x in parts)) override_lines.append(f"COLORS_RGB = {repr(colors_list)}") if args.resolution: w, h = args.resolution.split(',') override_lines.append(f"RESOLUTION = ({int(w)}, {int(h)})") if args.background: r, g, b = args.background.split(',') override_lines.append(f"BACKGROUND_COLOR = ({float(r)}, {float(g)}, {float(b)})") # Write the override file (config_override.py) in the current directory. override_path = 'config_override.py' with open(override_path, 'w', encoding='utf-8') as f: f.write('\n'.join(override_lines)) # Set environment variable so blendCreateSnapshot.py uses this override. env = os.environ.copy() env['configFile'] = override_path # Run blendCreateSnapshot.py with the same Python interpreter. cmd = [sys.executable, 'blendCreateSnapshot.py'] result = subprocess.run(cmd, env=env) # If PDF generation requested and main script succeeded, compile report.tex if args.pdf and result.returncode == 0: tex_path = os.path.join(args.output, 'report.tex') if os.path.exists(tex_path): print(f"\nCompiling {tex_path} to PDF...") # Run pdflatex twice to resolve cross-references for _ in range(2): proc = subprocess.run( ['pdflatex', '-interaction=nonstopmode', '-output-directory', args.output, tex_path], capture_output=True, text=True ) if proc.returncode != 0: print("PDF compilation failed. Check pdflatex output:") print(proc.stdout) print(proc.stderr) break else: print(f"PDF generated: {os.path.join(args.output, 'report.pdf')}") else: print(f"Warning: {tex_path} not found, skipping PDF generation.") sys.exit(result.returncode)if __name__ == '__main__': main()
/path/Python-3.11.14/bin/python3 run.py --input input/DK_template_test.csv --output output/DK_test --atlas DK --brain_type pial --img_type cortical-inner-right-hemisphere --colors "1,1,1" "1,0.8,0" "1,0.2,0" "0.5,0,0" --resolution 1200,900 --background 1,1,1 --pdf
就可以生成结果图片了,不过并没有产生与github相同的图……总是差点意思……该作者又做了brain-coloring-website(https://github.com/razvanmarinescu/brain-coloring-website)本地版BrainPainter~但只是界面出来了,也能运行,就是不出结果
还需要继续调试。这个软件整体上挺好的,就是说明书太垃圾……也没有提供best practice,差评