今日计划

  • 准备和刘越老师讨论的PPT,主要整理计算建模的思路以及难点
  • 提取单张脑片的脑区轮廓
  • BrainPy环境搭建
  • 整理计算神经科学领域比较有名的实验室和科学家

提取脑区轮廓

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package I.plugin;

import ij.ImagePlus;
import ij.ImageStack;
import ij.gui.NewImage;
import ij.io.FileSaver;
import ij.plugin.RGBStackMerge;
import ij.process.ImageProcessor;

public class Test06 {

public ImageProcessor getLineImg(ImageProcessor ip, ImageProcessor op) {
int lenX = ip.getWidth();
int lenY = ip.getHeight();
for(int i = 0; i < lenX; i ++) { //按列
int begin = 0; //初始像素值为黑色
for(int j = 0; j < lenY; j ++) {
int temp = (int)ip.getPixelValue(i, j);
if(temp != begin) {
op.set(i, j, 255);
begin = temp;
}
}
}
for(int j = 0; j < lenY; j ++) {
int begin = 0; //初始像素值为黑色
for(int i = 0; i < lenX; i ++) {
int temp = (int)ip.getPixelValue(i, j);
if(temp != begin) {
op.set(i, j, 255);
begin = temp;
}
}
}
return op;
}

public static void main(String[] args) {
ImagePlus brainImage = new ImagePlus("D:/Desktop/downSampleImage0160.tif");
ImageStack brainStack = brainImage.getStack();

ImagePlus annoImage = new ImagePlus("D:/Desktop/anno_output/result0160.tif");
ImageProcessor ap = annoImage.getProcessor();
int width = ap.getWidth();
int height = ap.getHeight();

ImagePlus lineImage = NewImage.createByteImage("lineImage", width, height, 0, NewImage.FILL_BLACK);
ImageStack lineStack = lineImage.getStack();
ImageProcessor lp = lineImage.getProcessor();

ImageProcessor op = new Test06().getLineImg(ap, lp);

lineImage.setProcessor(op);
lineImage.show();

ImagePlus fuseImage = NewImage.createByteImage("fuseImage", width, height, 0, NewImage.FILL_BLACK);

ImageStack fuseStack = RGBStackMerge.mergeStacks(brainStack, lineStack, null, true);

fuseImage.setStack(fuseStack);
fuseImage.show();
// 保存图片
new FileSaver(fuseImage).saveAsTiff("D:/Desktop/fuseImage.tif");
}
}

细胞计数

没想到BIRDS里细胞计数是通过调用Imaris的方法实现的,看来还是要学一下这个软件的用法🥲运行Imaris前记得先运行license server.bat~
.tif → .ims可以通过ImarisFileConverter.exe实现,Imaris默认安装在C盘。
没有找到很方便的API,看代码似乎是要现在Imaris里面操作完成之后,Java再获取对应的数据,这好像和我想要达到的效果不一样。
👻不想动脑子,怎么办!!!

流程测试

⭐脑片与标准脑模板的尺寸要大致相同,为了不过度损失脑片分辨率,此处对标准脑模板进行上采样
elastix.exe配准的参数使用para-Standard_bspline.txtpara-Standard_affine.txtpara-Standard_rigid.txt(去掉了对图片维度的限制)效果比较好
👻不知道为什么提取的脑区轮廓有很明显的锯齿,难道是因为我把注释图片分辨率调高了?不过问题不大~
👻由于原始脑片本身边缘有破损,因此与轮廓边缘处会出现明显的变形

  1. 将标准脑模板和注释图片的分辨率提高至与脑片匹配的程度(尽量不损失原始脑片的图像分辨率)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    from PIL import Image

    Image.MAX_IMAGE_PIXELS = None
    raw = Image.open(r"D:/Desktop/elastix-5.1.0-win64/input/result1.tif")
    img = Image.open(r"D:/Desktop/elastix-5.1.0-win64/out_anno/annotationImage0270.tif")
    # img = Image.open(r"D:/Desktop/elastix-5.1.0-win64/out_temp/tempImage0270.tif")

    target_width = raw.size[0]
    scale = round(target_width/img.size[0],1)
    width = int(img.size[0]*scale)
    height = int(img.size[1]*scale)

    out = img.resize((width, height))
    type = img.format
    out.save('D:/Desktop/elastix-5.1.0-win64/out_anno/annotationImage0270-1.tif',type)
    # out.save('D:/Desktop/elastix-5.1.0-win64/out_temp/tempImage0270-1.tif',type)
  2. 脑片与图谱配准
    1
    2
    3
    elastix -f input/result1.tif -m out_temp/tempImage0270-1.tif -out output -p input/para-Standard_rigid.txt -p input/para-Standard_affine.txt -p input/para-Standard_bspline_2.txt

    transformix -in out_anno/annotationImage0270-1.tif -out result -tp output/TransformParameters.2.txt

参考文章