【细胞分割】基于matlab GUI生物细胞计数【含Matlab源码 758期】

举报
海神之光 发表于 2022/05/29 02:25:29 2022/05/29
【摘要】 一、简介 1 GUI界面设计 2 原理 2.1 打开图像 点击打开图片的时候需要打开需要计算细胞的图片,则可以使用下面的代码来打开图片。 function pushbutton1_Callback(...

一、简介

1 GUI界面设计
在这里插入图片描述
2 原理
2.1 打开图像
点击打开图片的时候需要打开需要计算细胞的图片,则可以使用下面的代码来打开图片。

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename,pathname]=uigetfile({'*.jpg';'*.bmp, *.jpg, *.tif';'*.bmp';'*.jpg';'*.tif';},'选择图像');
if isequal(filename,0)||isequal(pathname,0)
  errordlg('您还没有选取图片!!','温馨提示');%如果没有输入,则创建错误对话框 
  return;
else
    global im; %定义全局变量将打开的照片放在该变量中。
    image=[pathname,filename];%合成路径+文件名
    im=imread(image);%读取图像
    [x,y] = size(im); %读取图片的大小
    if x>y %根据照片的长宽不同来改变图片的大小,这里定义600*800是为了减轻程序运行时电脑的压力,以及该大小取得的效果也不错。
        im = imresize(im,[600 800]);
    else
        im = imresize(im,[800 600]);
    end
    set(handles.axes1,'HandleVisibility','ON');%打开坐标,方便操作
    axes(handles.axes1);%%使用图像,操作在坐标1
    imshow(im);%在坐标axes1显示原图像 
    title('原始图像');

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

2 .2 USM锐化
本设计是使用的是灰度图以及高斯模糊的图来实现USM锐化的,因此需要将RGB三色图转换为灰度图,而MATLAB中自带的RGB转GRAY的函数十分方便,下面是代码实现。

    global gray %定义灰度图的全局变量,方便后面的函数调用
    gray= rgb2gray(im); %将RGB三色图转换成gray
    gray = imadjust(gray); %该函数是用来增强图像
    set(handles.axes2,'HandleVisibility','ON');%打开坐标,方便操作
    axes(handles.axes2);%%使用图像,操作在坐标1
    imshow(gray);%在坐标axes1显示原图像 
    title('灰度图像');

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

2.3 高斯模糊图像

    global Gauss 
    global filter
    Gauss = fspecial('gaussian',[10 10],20);%获取高斯模糊算子
    filter = imfilter(gray, Gauss); %获得高斯模糊图像
    set(handles.axes3,'HandleVisibility','ON');%打开坐标,方便操作
    axes(handles.axes3);%%使用图像,操作在坐标1
    imshow(filter);%在坐标axes1显示原图像 
    title('模糊图像');

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2.4 USM图像
有了高斯模糊和灰度图像,就可以求出USM图像,原理也不再介绍,直接放代码。

    global USM 
    weight = 0.8; 
    USM = uint8((double(gray)-weight.*double(filter))./(1-weight)); %获取USM锐化图像
    set(handles.axes4,'HandleVisibility','ON'); %打开坐标,方便操作
    axes(handles.axes4); %使用图像,操作在坐标1
    imshow(USM);%在坐标axes1显示原图像 
    title('锐化图像');

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

2.5 二值化
有了USM图像,对比度增强了许多,因此使用将图像二值化后的效果将会很好,下面是二值化函数:

function getbw(handles)
    global bw%将bw变量定义为全局变量
    global USM
    level = get(handles.slider4,'value');%获取滑杆4的值,该滑杆是控制阈值
    bw = im2bw(USM, level); %将USM锐化后图像转换为二值化图像
    imorph(3, get(handles.slider5,'value'), 
    get(handles.slider6,'value'));%该函数是自己编写的用来腐蚀或膨胀图像
    set(handles.axes5,'HandleVisibility','ON');%打开坐标,方便操作
    axes(handles.axes5);%%使用图像,操作在坐标1
    imshow(bw);%在坐标axes1显示原图像 
    title('二值化图像');

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

下面是获取细胞个数的函数,该函数的原理是计算连通区域个数来获取细胞个数,由于经过以上的步骤,已将细胞核分离出来,因此只用计算连通域便可得到细胞个数。

二、部分源代码

function varargout = GUI(varargin)
% GUI MATLAB code for GUI.fig
%      GUI, by itself, creates a new GUI or raises the existing
%      singleton*.
%
%      H = GUI returns the handle to a new GUI or the handle to
%      the existing singleton*.
%
%      GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI.M with the given input arguments.
%
%      GUI('Property','Value',...) creates a new GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GUI_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 GUI

% Last Modified by GUIDE v2.5 10-Jun-2018 19:38:29

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GUI_OpeningFcn, ...
                   'gui_OutputFcn',  @GUI_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if 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 GUI is made visible.
function GUI_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 GUI (see VARARGIN)

% Choose default command line output for GUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = GUI_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 structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename,pathname]=uigetfile({'*.jpg';'*.bmp, *.jpg, *.tif';'*.bmp';'*.jpg';'*.tif';},'选择图像');
if isequal(filename,0)||isequal(pathname,0)
  errordlg('您还没有选取图片!!','温馨提示');%如果没有输入,则创建错误对话框 
  return;
else
    global im;
    image=[pathname,filename];%合成路径+文件名
    im=imread(image);%读取图像
    [x,y] = size(im);
    if x>y
        im = imresize(im,[600 800]);
    else
        im = imresize(im,[800 600]);
    end
    set(handles.axes1,'HandleVisibility','ON');%打开坐标,方便操作
    axes(handles.axes1);%%使用图像,操作在坐标1
    imshow(im);%在坐标axes1显示原图像 
    title('原始图像');
    
    global gray
    gray= rgb2gray(im);
    gray = imadjust(gray);
    set(handles.axes2,'HandleVisibility','ON');%打开坐标,方便操作
    axes(handles.axes2);%%使用图像,操作在坐标1
    imshow(gray);%在坐标axes1显示原图像 
    title('灰度图像');
    
    global Gauss
    global filter
    Gauss = fspecial('gaussian',[10 10],20);
    filter = imfilter(gray, Gauss);
    set(handles.axes3,'HandleVisibility','ON');%打开坐标,方便操作
    axes(handles.axes3);%%使用图像,操作在坐标1
    imshow(filter);%在坐标axes1显示原图像 
    title('模糊图像');
    
    global USM
    weight = 0.8;
    USM = uint8((double(gray)-weight.*double(filter))./(1-weight));
    set(handles.axes4,'HandleVisibility','ON');%打开坐标,方便操作
    axes(handles.axes4);%%使用图像,操作在坐标1
    imshow(USM);%在坐标axes1显示原图像 
    title('锐化图像');
    
    getbw(handles);
    
end


  
 
  • 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
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128

三、运行结果

在这里插入图片描述

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
[5]赵勇,方宗德,庞辉,王侃伟.基于量子粒子群优化算法的最小交叉熵多阈值图像分割[J].计算机应用研究. 2008,(04)

文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。

原文链接:qq912100926.blog.csdn.net/article/details/115598244

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。