【matlab】基于分水岭分割进行肺癌诊断GUI设计

先看GUI的设计
在这里插入图片描述
运行结果:
在这里插入图片描述
因为是小报告,没怎么认真做,麻雀虽小五脏俱全
后端源码:

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

% Last Modified by GUIDE v2.5 15-May-2022 11:56:16

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled1_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled1_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 untitled1 is made visible.
function untitled1_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 untitled1 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = untitled1_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)

axes(handles.axes1);
image1 = imread('images/01.JPG');
imshow(image1); title('原图');



% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
fileName='images/01.JPG'
rgb = imread(fileName);
if ndims(rgb) == 3
    I = rgb2gray(rgb);
else    
    I = rgb;
end
sz = size(I);
if sz(1) ~= 256
    I = imresize(I, 256/sz(1));
    rgb = imresize(rgb, 256/sz(1));
end
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(I), hy, 'replicate');
Ix = imfilter(double(I), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
se = strel('disk', 3);
Io = imopen(I, se);
Ie = imerode(I, se);
Iobr = imreconstruct(Ie, I);
Ioc = imclose(Io, se);
Iobrd = imdilate(Iobr, se);
Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
fgm = imregionalmax(Iobrcbr);
se2 = strel(ones(3,3));
fgm2 = imclose(fgm, se2);
fgm3 = imerode(fgm2, se2);
fgm4 = bwareaopen(fgm3, 15);
bw = im2bw(Iobrcbr, graythresh(Iobrcbr));
D = bwdist(bw);
DL = watershed(D);
bgm = DL == 0;
gradmag2 = imimposemin(gradmag, bgm | fgm4);
L = watershed(gradmag2);
Lrgb = label2rgb(L, 'jet', 'w', 'shuffle');

[pathstr, name, ext] = fileparts(fileName);
filefolder = fullfile(pwd, '实验结果', [name, '_实验截图']);
if ~exist(filefolder, 'dir')
    mkdir(filefolder);
end

axes(handles.axes3);
imshow(I, []); title('灰度图像')
fileurl = fullfile(filefolder, '1');



axes(handles.axes4);
imshow(Iobrcbr, []); title('图像二值化')
fileurl = fullfile(filefolder, '2');



axes(handles.axes5);
imshow(gradmag, []):title('梯度图像')
fileurl = fullfile(filefolder, '3');

h4 = figure(4); imshow(rgb, []); hold on;
himage = imshow(Lrgb);

set(himage, 'AlphaData', 0.3);
hold off;
fileurl = fullfile(filefolder, '4');
set(h4,'PaperPositionMode','auto');
print(h4,'-dtiff','-r200',fileurl);

源文件下载地址:
https://github.com/MeetNiceMe/matlab/tree/main/%E5%9F%BA%E4%BA%8E%E5%88%86%E6%B0%B4%E5%B2%AD%E5%88%86%E5%89%B2%E8%BF%9B%E8%A1%8C%E8%82%BA%E7%99%8C%E8%AF%8A%E6%96%ADGUI

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
分水岭分割是数字图像处理中常用的一种分割方法,对于肺癌诊断来说也有一定的应用。下面是对于基于分水岭分割进行肺癌诊断的相关代码分析。 在MATLAB中,使用分水岭分割进行肺癌诊断的代码主要包括以下几个步骤: 1. 加载图像数据:首先需要将待分割的肺部CT图像加载到MATLAB中。可以使用`imread`函数加载图像,并使用`imshow`函数显示图像。 2. 预处理:对于分水岭分割来说,预处理是非常重要的步骤。首先需要进行图像增强,以凸显肺部区域。可以使用直方图均衡化、灰度拉伸等方法进行图像增强。然后,可以使用一些图像滤波技术,如高斯滤波或中值滤波,消除图像中的噪声。 3. 分割:使用分水岭分割方法对预处理后的图像进行分割。通过设置一些阈值来确定分水岭的位置,将图像分割成不同的区域。在MATLAB中,可以使用`watershed`函数进行分割分割结果可以使用不同的颜色标记不同的区域。 4. 后处理:由于分水岭分割可能会产生一些过分割和欠分割的情况,需要进行后处理来优化分割结果。常见的后处理方法包括区域合并、区域切割和边缘优化等。可以使用MATLAB中的图像处理函数来实现这些方法。 5. 结果显示和分析:最后,将分割结果用不同的颜色进行显示,并进行观察和分析。可以使用`imshow`函数将图像显示出来,并使用`imtool`函数进行分析。 总结: 基于分水岭分割进行肺癌诊断MATLAB代码主要包括图像加载、预处理、分割、后处理以及结果显示和分析等几个步骤。熟练掌握这些步骤能够帮助我们更准确地进行肺癌诊断

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值