2016-06-07 131 views
1

經過2或3天的搜索,我仍然沒有找到解決我的問題的方法。灰度圖像中的MATLAB分類分割,陰影不變

我想創建沒有陰影的鼠標分割。問題是,如果我設法刪除陰影,我也刪除尾部和腳部這是一個問題。陰影來自鼠標所在的競技場的牆壁。

我想從灰度圖像中刪除陰影,但我不知道如何做到這一點。首先,我刪除了圖像的背景,並獲得了以下圖片。

enter image description here

EDIT1:謝謝你爲它工作得很好,當影子不觸摸鼠標的答案。這是我所得到的,否則:從這個原始圖像

segmented mouse

original image

我提取TIF文件每一幀和應用代碼的每一幀。這是我使用的代碼:

for k=1:1000 

    %reads image 
    I = imread('souris3.tif',k); 

    %first stage: perform thesholding and fill holes 

    seg = I >20000; 
    seg = imfill(seg,'holes'); 

    %fixes the missing tail problem 
    %extract edges, and add them to the segmentation. 
    edges = edge(I); 
    seg = seg | edges; 

    %fill holes (again) 
    seg = imfill(seg,'holes'); 

    %find all the connected components 
    CC = bwconncomp(seg,8); 

    %keeps only the biggest CC 
    numPixels = cellfun(@numel,CC.PixelIdxList); 
    [biggest,idx] = max(numPixels); 
    seg = zeros(size(edges)); 
    seg(CC.PixelIdxList{idx}) = 1; 

    imshow(seg); 

end 

我選擇20000步用命令impixelinfo因爲圖像是uint16,它是鼠標的平均值。

這是鏈接,如果你想擁有的TIF文件:

souris3.tif

謝謝你的幫助。

回答

7

我建議以下方法:

  1. 的圖像執行閾值,並獲得包含大部分老鼠的身體沒有他的尾巴和腿口罩。
  2. 使用MATLAB的imfill函數執行孔填充。在這個階段,分割幾乎是完美的,除了尾部缺失的部分。
  3. 使用邊緣映射爲了找到尾部的邊界。這可以通過將邊緣圖添加到分割並再次執行孔填充來完成。在這個階段只保留最大的連接組件。

代碼:

%reads image 
I = rgb2gray(imread('mSWm4.png')); 

%defines thersholds (you may want to tweak these thresholds, or find 
%a way to calculate it automatically). 
FIRST_STAGE_THRESHOLD = 70; 
IM_BOUNDARY_RELEVANCE_THRESHOLD = 10; 

%perform thesholding and fill holes, the tail is still missing 
seg = I > FIRST_STAGE_THRESHOLD; 
seg = imfill(seg,'holes'); 

%second stage fix the missing tail problem: 
%extract edges from relevant areas (in which the matter is not too dark), and add them to the segmentation. 
%the boundries of the image which are close enough to edges are also considered as edges 
edges = edge(I); 
imageBoundries = ones(size(I)); 
imageBoundries(2:end-1,2:end-1) = 0; 
relevantDistFromEdges = bwdist(edges) > IM_BOUNDARY_RELEVANCE_THRESHOLD; 
imageBoundries(bwdist(edges) > IM_BOUNDARY_RELEVANCE_THRESHOLD) = 0; 
seg = seg | (edges | imageBoundries); 

%fill holes (again) and perform noise cleaning 
seg = imfill(seg,'holes'); 
seg = getBiggestCC(imopen(seg,strel('disk',1))); 

getBiggestCC功能:

function [ res ] = getBiggestCC(mask) 
CC = bwconncomp(mask,8); 
numPixels = cellfun(@numel,CC.PixelIdxList); 
[~,idx] = max(numPixels); 
res = zeros(size(mask)); 
res(CC.PixelIdxList{idx}) = 1; 
end 

結果每個階段的

結果:

enter image description here

結果 圖像1個結果:

enter image description here

圖像2個結果:

enter image description here

另一個視圖(分割是紅色):

enter image description here

+0

謝謝!當陰影不碰觸鼠標時它運作良好。我沒有隻有一個圖像,但幾個人,有時影子再次出現。 –

+0

您可以通過鏈接 –

+0

下載tif文件謝謝!如果我發現其他問題,我會很快找到你的 –