【圖像處理】基於最小誤差法的胸片分割系統

2021-01-20 天天Matlab
function varargout = MainForm(varargin)% MAINFORM MATLAB code for MainForm.fig%      MAINFORM, by itself, creates a new MAINFORM or raises the existing%      singleton*.%%      H = MAINFORM returns the handle to a new MAINFORM or the handle to%      the existing singleton*.%%      MAINFORM('CALLBACK',hObject,eventData,handles,...) calls the local%      function named CALLBACK in MAINFORM.M with the given input arguments.%%      MAINFORM('Property','Value',...) creates a new MAINFORM or raises the%      existing singleton*.  Starting from the left, property value pairs are%      applied to the GUI before MainForm_OpeningFcn gets called.  An%      unrecognized property name or invalid value makes property application%      stop.  All inputs are passed to MainForm_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 MainForm
% Last Modified by GUIDE v2.5 02-May-2017 08:10:18
% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @MainForm_OpeningFcn, ... 'gui_OutputFcn', @MainForm_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
function InitAxes(handles)clc;axes(handles.axes1); cla reset;set(handles.axes1, 'XTick', [], 'YTick', [], ... 'XTickLabel', '', 'YTickLabel', '', 'Color', [0.7020 0.7804 1.0000], 'Box', 'On');axes(handles.axes2); cla reset;set(handles.axes2, 'XTick', [], 'YTick', [], ... 'XTickLabel', '', 'YTickLabel', '', 'Color', [0.7020 0.7804 1.0000], 'Box', 'On');
function filePath = OpenFile(imgfilePath)% 打開文件% 輸出參數:% filePath——文件路徑
if nargin < 1 imgfilePath = fullfile(pwd, 'images/test.jpg');end[filename, pathname, ~] = uigetfile( ... { '*.jpg','All jpg Files';... '*.png','All png Files';... '*.*', '所有文件 (*.*)'}, ... '選擇文件', ... 'MultiSelect', 'off', ... imgfilePath);filePath = 0;if isequal(filename, 0) || isequal(pathname, 0) return;endfilePath = fullfile(pathname, filename);
% --- Executes just before MainForm is made visible.function MainForm_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 MainForm (see VARARGIN)
% Choose default command line output for MainFormhandles.output = hObject;InitAxes(handles);handles.I = 0;handles.J = 0;handles.bw_direct = 0;handles.bw_poly = 0;handles.bw__kittler = 0;handles.bw_temp = 0;% Update handles structureguidata(hObject, handles);
% UIWAIT makes MainForm wait for user response (see UIRESUME)% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.function varargout = MainForm_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 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)filePath = OpenFile();if isequal(filePath, 0) return;endImg = imread(filePath);% 灰度化if ndims(Img) == 3 I = rgb2gray(Img);else I = Img;endaxes(handles.axes1);imshow(I, []);title('原圖像');handles.I = I;guidata(hObject, handles);
% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)if isequal(handles.I, 0) return;end% 直接二值化bw_direct = im2bw(handles.I, graythresh(handles.I));axes(handles.axes2);imshow(bw_direct, []);title('直接二值化分割');handles.bw_direct = bw_direct;guidata(hObject, handles);
% --- 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)if isequal(handles.bw_direct, 0) return;end% 圈選胃區域空氣c = [1524 1390 1454 1548 1652 1738 1725 1673 1524];r = [1756 1909 2037 2055 1997 1863 1824 1787 1756];bw_poly = roipoly(handles.bw_direct, c, r);axes(handles.axes2);imshow(handles.I, []);hold on;plot(c, r, 'r-', 'LineWidth', 2);hold off;title('胃區域空氣選擇');handles.bw_poly = bw_poly;guidata(hObject, handles);
% --- Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)% hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)if isequal(handles.bw_poly, 0) return;end% 圖像歸一化IE = mat2gray(handles.I);% 對比度增強IE = imadjust(IE, [0.532 0.72], [0 1]);IE = im2uint8(mat2gray(IE));I = im2uint8(mat2gray(handles.I));% 顯示axes(handles.axes2);imshow(IE, []);title('圖像增強');figure;subplot(2, 2, 1); imshow(I); title('原圖像');subplot(2, 2, 2); imshow(IE); title('增強圖像');subplot(2, 2, 3); imhist(I); title('原圖像直方圖');subplot(2, 2, 4); imhist(IE); title('增強圖像直方圖');JE = IE;JE(handles.bw_poly) = 255;handles.JE = JE;guidata(hObject, handles);
% --- Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)if isequal(handles.JE, 0) return;endJ = handles.JE;% 直方圖統計[counts, gray_style] = imhist(J);% 亮度級別gray_level = length(gray_style);% 計算各灰度概率gray_probability = counts ./ sum(counts);% 統計像素均值gray_mean = gray_style' * gray_probability;% 初始化gray_vector = zeros(gray_level, 1);w = gray_probability(1);mean_k = 0;gray_vector(1) = realmax;ks = gray_level-1;for k = 1 : ks % 迭代計算 w = w + gray_probability(k+1); mean_k = mean_k + k * gray_probability(k+1); % 判斷是否收斂 if (w < eps) || (w > 1-eps) gray_vector(k+1) = realmax; else % 計算均值 mean_k1 = mean_k / w; mean_k2 = (gray_mean-mean_k) / (1-w); % 計算方差 var_k1 = (((0 : k)'-mean_k1).^2)' * gray_probability(1 : k+1); var_k1 = var_k1 / w; var_k2 = (((k+1 : ks)'-mean_k2).^2)' * gray_probability(k+2 : ks+1); var_k2 = var_k2 / (1-w); % 計算目標函數 if var_k1 > eps && var_k2 > eps gray_vector(k+1) = 1+w * log(var_k1)+(1-w) * log(var_k2)-2*w*log(w)-2*(1-w)*log(1-w); else gray_vector(k+1) = realmax; end endend% 極值統計min_gray_index = find(gray_vector == min(gray_vector));min_gray_index = mean(min_gray_index);% 計算閾值threshold_kittler = (min_gray_index-1)/ks;% 閾值分割bw__kittler = im2bw(J, threshold_kittler);axes(handles.axes2);imshow(bw__kittler, []);title('最小誤差法分割');handles.bw__kittler = bw__kittler;guidata(hObject, handles);
% --- Executes on button press in pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)% hObject handle to pushbutton6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)if isequal(handles.bw__kittler, 0) return;end% 形態學後處理bw_temp = handles.bw__kittler;% 反色bw_temp = ~bw_temp;% 填充孔洞bw_temp = imfill(bw_temp, 'holes');% 去噪bw_temp = imclose(bw_temp, strel('disk', 5));bw_temp = imclearborder(bw_temp);% 區域標記[L, ~] = bwlabel(bw_temp);% 區域屬性stats = regionprops(L);Ar = cat(1, stats.Area);% 提取目標並清理[~, ind] = sort(Ar, 'descend');bw_temp(L ~= ind(1) & L ~= ind(2)) = 0;% 去噪bw_temp = imclose(bw_temp, strel('disk',20));bw_temp = imfill(bw_temp, 'holes');axes(handles.axes2);imshow(bw_temp, []);title('形態學去噪');handles.bw_temp = bw_temp;guidata(hObject, handles);
% --- Executes on button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)% hObject handle to pushbutton7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)if isequal(handles.bw_temp, 0) return;end% 提取肺邊緣ed = bwboundaries(handles.bw_temp);axes(handles.axes2);imshow(handles.I, []); hold on;for k = 1 : length(ed) % 邊緣 boundary = ed{k}; plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 2);endhold off;title('肺邊緣顯示標記');
% --- Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)choice = questdlg('確定要退出系統?', ... '退出', ... '確定','取消','取消');switch choice case '確定' close all; case '取消' return;end

相關焦點

  • 圖像噪聲處理系統設計開題報告_圖像噪聲處理實驗報告 - CSDN
    超聲圖像的預處理效果是定位準確的一個關鍵因素[18]。3、圖像分割 圖像分割是圖像處理與圖像分析中的一個經典問題,就是一個根據區域間的相似或不同把圖像分割成若干區域的過程,主要以各種細胞、組織與器官的圖像作為處理對象。從分割操作策略上講,可以分為基於區域生成的分割方法,基於邊界檢測的分割方法和區域生成與邊界檢測的混合方法。
  • OpenCV圖像處理專欄十五 |《一種基於亮度均衡的圖像閾值分割技術》
    前言對於光照不均勻的圖像,用通常的圖像分割方法不能取得滿意的效果。為了解決這個問題,論文《一種基於亮度均衡的圖像閾值分割技術》提出了一種實用而簡便的圖像分割方法。該方法針對圖像中不同亮度區域進行亮度補償,使得整個圖像亮度背景趨於一致後,再進行常規的閾值分割。實驗結果表明,用該方法能取得良好的分割效果。
  • 基於顏色特徵與直方圖閾值相結合的田間青椒圖像分割算法
    由於機器人採集的圖像受到自然光的影響,青椒果實表面與其周圍葉片等環境存在一定的差別, 目前常用的圖像分割方法有兩種:利用圖像的顏色特徵進行分割以及利用BP神經網絡對圖像進行分割。 (4)採集方法:用數位相機在園藝田中拍攝青椒作物圖片,選擇具有典型代表的圖片進行處理,獲取的圖像以JPG格式存儲在存儲卡中,在並行口與計算機相連,將圖像存儲於硬碟中並轉成BMP格式的24位真彩圖。 在實際應用系統中可考慮採用CCD攝像機動態採集圖像,通過圖像採集卡將圖像實時地傳入到控制臺的計算機內。
  • CNN 在基於弱監督學習的圖像分割中的應用
    最近基於深度學習的圖像分割技術一般依賴於卷積神經網絡 CNN 的訓練,訓練過程中需要非常大量的標記圖像,即一般要求訓練圖像中都要有精確的分割結果。對於圖像分割而言,要得到大量的完整標記過的圖像非常困難,比如在 ImageNet 數據集上,有 1400 萬張圖有類別標記,有 50 萬張圖給出了 bounding box, 但是只有 4460 張圖像有像素級別的分割結果。對訓練圖像中的每個像素做標記非常耗時,特別是對醫學圖像而言,完成對一個三維的 CT 或者 MRI 圖像中各組織的標記過程需要數小時。
  • 一種基於人工智慧的腦圖像處理方法
    打開APP 一種基於人工智慧的腦圖像處理方法 MedPeer 發表於 2019-10-22 16:41:57 (文章來源:MedPeer
  • 基於Sigma-IFCM分割算法的腦部MR圖像
    圖像分割是把圖像分割成互不相交的區域,使每個區域內的像素具有某種相似的特徵,以便對圖像進行後續處理。圖像分割是圖像分析的難點之一,至今沒有一個通用且有效的圖像分割方法能夠滿足不同的需求。在腦部MR圖像分析中該問題尤為突出。
  • 圖像分割系列<->語義分割
    精選文章,第一時間送達 上期講到圖像分割(Image segmentation)根據某些規則把圖片中的像素分為不同的部分(加不同的標籤),它可分為:超像素、語義分割、實例分割、全景分割, 各有聯繫,又有區別。
  • 100個深度圖像分割算法,紐約大學UCLA等最新綜述論文
    引言 圖像分割是許多視覺理解系統的重要組成部分。它涉及到將圖像(或視頻幀)分割成多個段或對象[1]。分割在[2]的廣泛應用中起著核心作用,包括醫學圖像分析(如腫瘤邊界提取和組織體積測量),自動駕駛車輛(如可導航的表面和行人檢測),視頻監控,增強現實等。
  • Double DIP——一種無監督層圖像分割 AI 技術
    舉兩個突出的例子:圖像分割——分割成背景層和前景層的區域;圖像去霧——分割為清晰圖層和有霧圖層。在該論文中,作者提出了一種基於耦合的「深度圖像先驗」(DIP)網絡對單個圖像進行無監督層分割的統一框架。被 CVPR 2018 會議接收的深度圖像先驗(DIP)網絡,是一種可以用來對單個圖像的低級統計數據進行生成的結構,而且只需要在單張圖像上進行訓練。
  • Double DIP ——一種無監督層圖像分割 AI 技術
    舉兩個突出的例子:圖像分割——分割成背景層和前景層的區域;圖像去霧——分割為清晰圖層和有霧圖層。在該論文中,作者提出了一種基於耦合的「深度圖像先驗」(DIP)網絡對單個圖像進行無監督層分割的統一框架。被 CVPR 2018 會議接收的深度圖像先驗(DIP)網絡,是一種可以用來對單個圖像的低級統計數據進行生成的結構,而且只需要在單張圖像上進行訓練。
  • 利用基於幾何關係的擴增技術從OCT圖像進行病理視網膜區域分割
    用於分割的大規模數據集注釋需要圖像像素標記,這非常耗時,並且涉及到高度的臨床專業知識。這個問題對於病理圖像來說尤其嚴重,對於發病率較低的疾病,很難獲得不同的圖像,因此需要進行數據擴增。由 Amy Zhao 等人提出的一種基於學習的配準方法,將圖像配準到圖集中,利用相應的變形場對分割掩模進行變形,得到新的圖像數據。
  • 深度| 2017 CV 技術報告之圖像分割、超解析度和動作識別
    該材料共包括四大部分,在本文中機器之心對第二部分做了編譯介紹,第一部分和第四部分詳見《計算機視覺這一年:這是最全的一份 CV 技術報告》和《計算機視覺這一年:2017 CV 技術報告 Plus 之卷積架構、數據集與新趨勢》。圖像分割計算機視覺任務的核心是分割(Segmentation)處理,它將整幅圖片分割成可被標記和分類的像素組。
  • 基於DSP+FPGA的紅外圖像小目標檢測系統設計
    一般說來,由於小目標距離較遠,因而在成像系統中表現為微弱特性,並且沒有形狀和結構特徵或特徵不明顯。同時,由於高於絕對零度的物體均有紅外輻射能力,所以自然界中的幹擾源很多,很難準確地檢測出真正的目標。 本文在數學形態學Top-hat算子對於目標檢測的基礎上,設計了一種基於DSP+FPGA的圖像實時處理系統,使其能夠滿足高速採樣數據流快速存取,快速運算的要求。
  • 基於Otsu分割算法和Nios II軟硬體實現實現實時目標成像跟蹤研究
    然而對小目標圖象卻不能把目標從背景中分割出來,經常會把很多背景錯分為目標,本文提出了利用改進的快速局部遞歸Otsu分割算法對圖象分割。並且依靠並行Nios II軟核和硬體邏輯結合的速度優勢對算法實時實現。
  • 如何提高交互式圖像分割算法的效率?
    現有的交互式圖像分割算法雖然能迭代式地更新分割結果,但很大程度上忽略了對連續交互之間動態性的探索,造成分割效率大大降低。在 CVPR 2020 的一篇論文中,來自上海交大和華師大的團隊聯合提出了一種基於多智能體深度強化學習(MARL)的新型交互式三維醫療圖像分割算法(IteR-MRL)。
  • 智能圖像處理 讓機器視覺及其應用更智能高效
    1.機器視覺技術  機器視覺的起源可追溯到20世紀60年代美國學者L.R.羅伯茲對多面體積木世界的圖像處理研究,70年代麻省理工學院(MIT)人工智慧實驗室「機器視覺」課程的開設。到80年代,全球性機器視覺研究熱潮開始興起,出現了一些基於機器視覺的應用系統。
  • 基於OpenCV的區域分割、輪廓檢測和閾值處理
    重磅乾貨,第一時間送達 OpenCV是一個巨大的開源庫,廣泛用於計算機視覺,人工智慧和圖像處理領域 在輸入幀中定義ROI的過程稱為ROI分割。 在「 ROI細分」中,(此處)我們選擇框架中的特定區域,並以矩形方法提供其尺寸,以便它將在框架上繪製矩形的ROI。
  • 基於STFT濾波算法的指紋圖像識別系統的設計與實現
    本文在充分調研了目前的指紋預處理和特徵提取研究成果之後,分別針對指紋增強、指紋二值化和指紋特徵提取方面提出了三個新的算法,部分解決了目前指紋識別技術面臨的問題與挑戰,並且利用這些新的算法製作了一款指紋圖像識別系統。本文通過緒論、需求分析、系統設計、系統實現、系統測試一步步介紹指紋圖像識別技術在指紋識別系統中的應用情況。
  • 百度飛槳發布工業級圖像分割利器PaddleSeg
    圖像語義分割通過給出每一個圖像中像素點的標籤,實現圖像中像素級別的語義分割,它是由圖像處理到圖像分析的關鍵步驟。就像下圖中所看到的那樣,可以對車輛、馬路、人行道等實例進行分割和標記!ICNet 的主要思想是將輸入圖像變換為不同的解析度,然後用不同計算複雜度的子網絡計算不同解析度的輸入,然後將結果合併。ICNet 由三個子網絡組成,計算複雜度高的網絡處理低解析度輸入,計算複雜度低的網絡處理解析度高的網絡,通過這種方式在高解析度圖像的準確性和低複雜度網絡的效率之間獲得平衡。ICNet 的網絡結構如下:3.2.
  • 2020入坑圖像分割,我該從哪兒入手?
    初識圖像分割顧名思義,圖像分割就是指將圖像分割成多個部分。在這個過程中,圖像的每個像素點都和目標的種類相關聯。圖像分割方法主要可分為兩種類型:語義分割和實例分割。語義分割會使用相同的類標籤標註同一類目標(下圖左),而在實例分割中,相似的目標也會使用不同標籤進行標註(下圖右)。