Recognize MRI images based on CNN

Introduction

The schizophrenia is a mental disorder characterized by abnormal social behavior and failure to understand reality. Common symptoms include false beliefs, unclear or confused thinking, hearing voices that others do not, reduced social engagement and emotional expression, and a lack of motivation.
When looking at the MRI images, it usually easy to find the difference between healthy people and older people or dementia. However, it is hard for even professional doctors to tell the difference between healthy people and people who have schizophrenia. Therefore, I am considering to use the supervised learning to train a model recognize the MRI images.

Data

I found images from patients that 20 of them are healthy people and 20 are Schizophrenia. Each data has 91 layers of images in the size of 101x91. The same as the work of written numbers I have done before, it also contains a grey threshold between 0 and 1.
这里写图片描述

Preprocess

In order to save the memory and use the max pooling later, I am considering reshape the images in order to get the best performance. Here, because the dataset is the form of .mat, I just use the Matlab to process the data. In order to keep the image as the size of square, I reshape the raw images into 90x90 squares

image = aimg(6:85,16:95,1:75)
implay(image)

Also, not all of the layers of the data has valid feature, because some are totally dark and some have few pixels on them.

Just like shown below
这里写图片描述

Therefore, I decide to exclude several layers for saving the resource. Here, I just keep 75 layers which seems like have useful features for the machine to learn.

Then, we import all the 40 data into MATLAB first and give them a sequence:

filepath = 'd:\桌面\Havard\MACHINE LEARNING\Healthy';
    %read all files
    for i= 1:1:9
        load([num2str(i) '.mat']) 
        b = ['a', num2str(i)];
        eval([b,'=aimg'])
    end
    for i= 10:1:20
        load([num2str(i) '.mat'])
        b = ['a', num2str(i)];
        eval([b,'=aimg'])
    end
%% 
filepath = 'd:\桌面\Havard\MACHINE LEARNING\Schizophrenia';
    for i= 1:1:9
        load([num2str(i) '.mat']) 
        b = ['s', num2str(i)];
        eval([b,'=aimg'])
    end
    for i= 10:1:20
        load([num2str(i) '.mat'])
        b = ['s', num2str(i)];
        eval([b,'=aimg'])
    end

Plan

The network I choose is the Convolutional Neural Network because it is good at processing the images like this. Also, based on the performance in classifying the written numbers, CNN is a pretty great choice for this work. A common image usually have RGB three channels so that we can treat the MRI scanning as 91 channels.

Structure

In last blog, I have introduced the CNN in recognition of 2D images. However, because the medical images like CT or MRI have several channels, it is more like a video rather than several individual images. Therefore, I am gonna use the 3D CNN here.

  • The network will contain 2 hidden layers. The first layer contains 32 convolutional kernels while the second layer contains 64 where each has a 8x8x1 convolutional kernel.
  • The max pooling will be a size of 2x2x1. After every time max pooling, the size of the image will be half while the depth will not change.
  • The fully-connected layer contains 1024 neurons which would connect all the 64 images gained from former layer.
  • The Softmax layer contains 2 neurons which stands for the healthy and schizophrenia. In this way, all the input will be calculated into 2 different possibility which means two different label of the data.

Code

Because I haven’t done the preprocess yet, so I will put the main code here without the training part. I will update the blog as soon as I have handled the dataset.

import tensorflow as tf
sess = tf.InteractiveSession()

def weight_variable(shape):
  initial = tf.truncated_normal(shape, stddev=0.1)
  return tf.Variable(initial)

def bias_variable(shape):
  initial = tf.constant(0.1, shape=shape)
  return tf.Variable(initial)

def conv3d(x, W):
  return tf.nn.conv3d(x, W, strides=[1, 1, 1, 1, 1], padding='SAME')

def max_pool_2x2(x):
  return tf.nn.max_pool3d(x, ksize=[1, 2, 2, 2, 1],
                        strides=[1, 1, 2, 2, 1], padding='SAME')


#first
W_conv1 = weight_variable([1, 8, 8, 1, 32])
b_conv1 = bias_variable([32])


x_image = tf.reshape(x, [-1,75,80,80,1])

h_conv1 = tf.nn.relu(conv3d(x_image, W_conv1) + b_conv1)
h_pool1 = max_pool_2x2(h_conv1)

#second
W_conv2 = weight_variable([1,8,8, 32, 64])
b_conv2 = bias_variable([64])

h_conv2 = tf.nn.relu(conv3d(h_pool1, W_conv2) + b_conv2)
h_pool2 = max_pool_2x2(h_conv2)


#

W_fc1 = weight_variable([7 * 7 * 64, 1024])
b_fc1 = bias_variable([1024])

h_pool2_flat = tf.reshape(h_pool2, [-1, 7*7*64])
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)



#dropout

keep_prob = tf.placeholder("float")
h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)


#softmax

W_fc2 = weight_variable([1024, 2])
b_fc2 = bias_variable([2])

y_conv=tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值