【图像分割】基于形态学算法实现原子力显微镜图像分析含Matlab源码

该博客介绍了基于MATLAB的医学图像处理技术,通过图像预处理、分割等步骤实现血液显微图像中红细胞的自动统计。设计了一个包括图像预处理、二值化、形态学处理和细胞计数的系统,能够处理染色条件和光照条件变化导致的图像差异,有效地分割和计数红细胞。
摘要由CSDN通过智能技术生成

1 简介

很多临床病症表现为白细胞数目增多、肿大或者白细胞中细胞核形状与数目发生变化,所以对白细胞数目和形状的研究有着重要意义。但是由于染色条件、涂片制备、图像来源、采样光照条件的差异以及细胞间相互重叠、粘连情况的发生,使得对白细胞的计数和识别等后续分析变得困难。为此,将粘连细胞分割成为单个细胞,就成为医学图像处理中必须解决的问题。本文基于MATLAB语言进行图像的处理以及分割,准确的处理图片,采用分水岭算法和阈值分割来实现,在现有研究基础之上,重点基于数字图像处理技术解决显微图像细胞计数这一思路,结合血液红细胞的主要特点,设定所要达到的目标和要求,设计和实现一个快速有效的血液显微图像红细胞数量自动统计系统。

1 课程设计任务 细胞数目检测在现实生活中的意义主要体现在医学上的作用,可通过细胞数目的检测来查看并估计病人或动物的血液中细胞数,如估测血液中红细胞、白细胞、血小板、淋巴细胞等细胞的数目,同时也可检测癌细胞的数目来查看医疗效果,根据这一系列的指标来对病人或动物进行治疗。 (1)对细胞图像进行预处理; (2)进行图像分割; (3)统计细胞数目; (4)要求自行设计方案,编写代码实现上述功能,并设计细胞统计的软件界面。

2 设计原理 图像分割是根据医学图像的某个可以处理的特性(如光学密度值、灰度值、CT值、频谱等),利用医学图像区域内的相似性和区域间的差异性将医学图像分割成若干个互不连通区域的过程。 将图像表示为物理上有意义的连通区域的集合,也就是根据目标与背景的先验知识,对图像中的目标、背景进行标记、定位,然后将目标从背景或其他伪目标中分离出来。由于这些被分割的区域在某些特性上相近,因而,图像分割常用于模式识别与图像理解以及图像压缩与编码两大类不同的应用目的。

3 设计流程 流程:首先将图像依次转化为灰度图像,二值图像。然后对二值图像进行中值滤波,并删除小面积对象(删除白色底面里面的黑色小点)。 其次,将图像反相,并删除小面积对象(相当于删除了二值图像里面黑色底面的白色小点)。 再次,对图像进行形态学运算处理。最后,标记红细胞,用贴标签的方法统计红细胞数目,目标实现。

2 部分代码

function varargout = AFManalysis(varargin)% AFMANALYSIS M-file for AFManalysis.fig%      AFMANALYSIS, by itself, creates a new AFMANALYSIS or raises the existing%      singleton*.%%      H = AFMANALYSIS returns the handle to a new AFMANALYSIS or the handle to%      the existing singleton*.%%      AFMANALYSIS('CALLBACK',hObject,eventData,handles,...) calls the local%      function named CALLBACK in AFMANALYSIS.M with the given input arguments.%%      AFMANALYSIS('Property','Value',...) creates a new AFMANALYSIS or raises the%      existing singleton*.  Starting from the left, property value pairs are%      applied to the GUI before AFManalysis_OpeningFcn gets called.  An%      unrecognized property name or invalid value makes property application%      stop.  All inputs are passed to AFManalysis_OpeningFcn via varargin.%%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one%      instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help AFManalysis% Last Modified by GUIDE v2.5 07-Dec-2010 22:56:55% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name',       mfilename, ...                   'gui_Singleton',  gui_Singleton, ...                   'gui_OpeningFcn', @AFManalysis_OpeningFcn, ...                   'gui_OutputFcn',  @AFManalysis_OutputFcn, ...                   'gui_LayoutFcn',  [] , ...                   'gui_Callback',   []);if nargin && ischar(varargin{1})    gui_State.gui_Callback = str2func(varargin{1});endif nargout    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else    gui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before AFManalysis is made visible.function AFManalysis_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject    handle to figure% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% varargin   command line arguments to AFManalysis (see VARARGIN)% Choose default command line output for AFManalysishandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes AFManalysis wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = AFManalysis_OutputFcn(hObject, eventdata, handles) % varargout  cell array for returning output args (see VARARGOUT);% hObject    handle to figure% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{1} = handles.output;% --- Executes on button press in pushbuttonBrowse.function pushbuttonBrowse_Callback(hObject, eventdata, handles)[FileName,PathName] = uigetfile('*.jpg','Select the image file');if PathName ~= 0    %if user not select canceladdpath(PathName);  %add path to file searchimagearray = imread(FileName);handles.imagesize = size(imagearray);axes(handles.Image);imshow(imagearray,'InitialMagnification','fit');%handles.imagegray = rgb2gray(imagearray);handles.imagearray = imagearray;guidata(hObject, handles);end% hObject    handle to pushbuttonBrowse (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% --- Executes during object creation, after setting all properties.function Image_CreateFcn(hObject, eventdata, handles)handles.Image= hObject;imshow('square.png');guidata(hObject, handles);% hObject    handle to Image (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: place code in OpeningFcn to populate Image% --- Executes on slider movement.function sliderimthreshhold_Callback(hObject, eventdata, handles)s = handles.imagesize;handles.slidervalth = get(handles.sliderth,'Value');handles.imagebin = im2bw(handles.imagearray, 1-handles.slidervalth);handles.imagebin = bwareaopen(handles.imagebin, round(s(1,1)*handles.slidervalfilter));bouparam = str2num(get(handles.boundrypara,'string')); h = fspecial('gaussian',bouparam,bouparam);handles.imagebin = imfilter(handles.imagebin,h);handles.imageedge = edge(handles.imagebin);imagewithboundry = handles.imagearray; for i = 1:1:s(1,1)    for j = 1:1:s(1,2)        if handles.imageedge(i,j) == 1            imagewithboundry(i,j,:)= 0;                end    endend%imagewithboundry = imadd(handles.imagearray(:,:,1), handles.imageedge);imshow(imagewithboundry,'InitialMagnification','fit');[L, num] = bwlabel(handles.imagebin);area = bwarea(handles.imagebin)/num;dia  = ((area*6)/pi)^(1/3); dianm = dia*(str2num(get(handles.imagesizenm,'string'))/s(1,1));num = num2str(num);set(handles.npno,'string',num)areanm = (pi/6)*((dianm)^3);areanm = num2str(areanm);set(handles.nparea,'string',area)dianm = num2str(dianm);set(handles.npdia,'string',dianm)guidata(hObject, handles); % hObject    handle to sliderimthreshhold (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'Value') returns position of slider%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider% --- Executes during object creation, after setting all properties.function sliderimthreshhold_CreateFcn(hObject, eventdata, handles)handles.sliderth = hObject;%handles.imagebin = im2bw(handles.image,0); guidata(hObject, handles);% hObject    handle to sliderimthreshhold (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: slider controls usually have a light gray background.if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))    set(hObject,'BackgroundColor',[.9 .9 .9]);end% --- Executes on slider movement.function sliderremovesmallpatch_Callback(hObject, eventdata, handles)s = handles.imagesize;handles.slidervalth = get(handles.sliderth,'Value');handles.slidervalfilter = get(handles.sliderremovesmallpatch,'Value');%handles.imagebin = im2bw(handles.imagearray, 1-handles.slidervalth);handles.imagebin2 = bwareaopen(handles.imagebin, round(s(1,1)*handles.slidervalfilter));handles.imageedge = edge(handles.imagebin2);imagewithboundry = handles.imagearray; for i = 1:1:s(1,1)    for j = 1:1:s(1,2)        if handles.imageedge(i,j) == 1            imagewithboundry(i,j,:)= 0;                end    endendimshow(imagewithboundry,'InitialMagnification','fit');[L, num] = bwlabel(handles.imagebin2);area = bwarea(handles.imagebin)/num;dia  = ((area*6)/pi)^(1/3); dianm = dia*(str2num(get(handles.imagesizenm,'string'))/s(1,1));num = num2str(num);set(handles.npno,'string',num)areanm = (pi/6)*((dianm)^3);areanm = num2str(areanm);set(handles.nparea,'string',area)dianm = num2str(dianm);set(handles.npdia,'string',dianm)guidata(hObject, handles); % hObject    handle to sliderremovesmallpatch (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'Value') returns position of slider%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider% --- Executes during object creation, after setting all properties.function sliderremovesmallpatch_CreateFcn(hObject, eventdata, handles)handles.sliderremovesmallpatch = hObject;handles.slidervalfilter = 0;guidata(hObject, handles);% hObject    handle to sliderremovesmallpatch (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: slider controls usually have a light gray background.if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))    set(hObject,'BackgroundColor',[.9 .9 .9]);%imagewithboundry = imadd(handles.imagearray(:,:,1), handles.imageedge);imshow(imagewithboundry,'InitialMagnification','fit');[L, num] = bwlabel(handles.imagebin);area = bwarea(handles.imagebin)/num;dia  = ((area*6)/pi)^(1/3); dianm = dia*(str2num(get(handles.imagesizenm,'string'))/s(1,1));num = num2str(num);set(handles.npno,'string',num)areanm = (pi/6)*((dianm)^3);areanm = num2str(areanm);set(handles.nparea,'string',area)dianm = num2str(dianm);set(handles.npdia,'string',dianm)% hObject    handle to boundrypara (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of boundrypara as text%        str2double(get(hObject,'String')) returns contents of boundrypara as a double% --- Executes during object creation, after setting all properties.function boundrypara_CreateFcn(hObject, eventdata, handles)% hObject    handle to boundrypara (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))    set(hObject,'BackgroundColor','white');end

3 仿真结果

4 参考文献

[1]陈强. 基于数学形态学图像分割算法的研究[D]. 哈尔滨理工大学.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值