平滑和适合二进制图像的边缘

时间:2016-09-13 04:30:45

标签: matlab image-processing filter shape best-fit-curve

我正在研究有关使用视频分析进行鱼类游泳的研究,然后我需要仔细研究图像(从视频帧中获取),重点放在尾部。

图像采用高分辨率,我自定义的软件使用二进制图像,因为这很容易使用数学运算。

对于这个二进制图像,我使用了两种方法:

1)将图像转换为灰色,将颜色反转,然后转换为bw,最后转换为二进制,其阈值为我提供这样的图像,几乎没有任何噪声。图像有时会丢失一些区域并且与尾部没有完全相同(现在我需要更多的准确度以确定尾部移动的幅度) image 1

2)我使用这个代码,为了切割增加阈值的边框,这给我一个很好的边缘图像,但我不知道像关节这些点和平滑图像,或拟合二进制图像,应用程序拟合matlab 2012Rb并没有给我一个很好的图表,我也无法访问matlab的工具箱。

s4 = imread('arecorte.bmp');
A=[90 90 1110 550]
s5=imcrop(s4,A)
E = edge(s5,'canny',0.59);

image2

我的问题是

我如何能够适应二值图像或关节点并平滑而不会打扰尾巴?

我如何使用图像2的边缘来增加图像1的粗糙度?

我会在评论中上传一张图片,让我了解方法2),因为我无法发布更多链接,请记住我正在使用迭代,我无法工作按框架。

注意:如果我问这是因为我处于一个死角,我没有资源支付给某人这样做,直到这一刻我能够编写代码但是在这个最后的问题我不能孤单。

1 个答案:

答案 0 :(得分:0)

我认为您应该使用连接组件labling并丢弃小标签,然后提取标签边界以获取每个部分的像素

代码:

clear all

% Read image
I = imread('fish.jpg');

% You don't need to do it you haef allready a bw image
Ibw = rgb2gray(I); 
Ibw(Ibw < 100) = 0;

% Find size of image
[row,col] = size(Ibw);

% Find connceted components
CC = bwconncomp(Ibw,8);

% Find area of the compoennts
stats = regionprops(CC,'Area','PixelIdxList');
areas = [stats.Area];

% Sort the areas
[val,index] = sort(areas,'descend');

% Take the two largest comonents ids and create filterd image
IbwFilterd = zeros(row,col);
IbwFilterd(stats(index(1,1)).PixelIdxList) = 1;
IbwFilterd(stats(index(1,2)).PixelIdxList) = 1;
imshow(IbwFilterd);

% Find the pixels of the border of the main component and tail
boundries = bwboundaries(IbwFilterd);

yCorrdainteOfMainFishBody = boundries{1}(:,1);
xCorrdainteOfMainFishBody = boundries{1}(:,2);
linearCorrdMainFishBody = sub2ind([row,col],yCorrdainteOfMainFishBody,xCorrdainteOfMainFishBody);

yCorrdainteOfTailFishBody = boundries{2}(:,1);
xCorrdainteOfTailFishBody = boundries{2}(:,2);
linearCorrdTailFishBody = sub2ind([row,col],yCorrdainteOfTailFishBody,xCorrdainteOfTailFishBody);

% For visoulaztion put color for the boundries
IFinal = zeros(row,col,3);
IFinalChannel = zeros(row,col);

IFinal(:,:,1) = IFinalChannel;

IFinalChannel(linearCorrdMainFishBody) = 255;
IFinal(:,:,2) = IFinalChannel;

IFinalChannel = zeros(row,col);
IFinalChannel(linearCorrdTailFishBody) = 125;
IFinal(:,:,3) = IFinalChannel;
imshow(IFinal);

最终图片: enter image description here

相关问题