Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab:如何在图像中弯曲直线_Matlab_Image Processing_Line - Fatal编程技术网

Matlab:如何在图像中弯曲直线

Matlab:如何在图像中弯曲直线,matlab,image-processing,line,Matlab,Image Processing,Line,我有一个图像(png格式)在手。限制椭圆(代表核)的线是过直的,这是不切实际的。我如何从图像中提取线条并使其弯曲,前提是它们仍然包围细胞核 下图: 弯曲后 编辑:如何将answer2中的膨胀和过滤部分翻译成Matlab语言?我想不出来。您输入的是Voronoi图。您可以使用另一个距离函数(而不是欧几里德函数)重新计算它 下面是Mathematica中使用曼哈顿距离的一个示例(i3是没有线条的输入图像): 编辑 我正在使用另一种算法(初步结果)。你觉得怎么样 好的,这里有一种方法,包括几个随

我有一个图像(png格式)在手。限制椭圆(代表核)的线是过直的,这是不切实际的。我如何从图像中提取线条并使其弯曲,前提是它们仍然包围细胞核

下图:

弯曲后


编辑:如何将answer2中的膨胀和过滤部分翻译成Matlab语言?我想不出来。

您输入的是Voronoi图。您可以使用另一个距离函数(而不是欧几里德函数)重新计算它

下面是Mathematica中使用曼哈顿距离的一个示例(
i3
是没有线条的输入图像):

编辑

我正在使用另一种算法(初步结果)。你觉得怎么样


好的,这里有一种方法,包括几个随机步骤,以获得“自然”的非对称外观

我正在用Mathematica发布实际代码,以防有人关心将其翻译成Matlab

(* A preparatory step: get your image and clean it*)
i = Import@"http://i.stack.imgur.com/YENhB.png";
i1 = Image@Replace[ImageData[i], {0., 0., 0.} -> {1, 1, 1}, {2}];
i2 = ImageSubtract[i1, i];
i3 = Inpaint[i, i2]


这是我想到的,它不是代码的直接翻译,但应该足够接近

%# read image (indexed image)
[I,map] = imread('http://i.stack.imgur.com/YENhB.png');

%# extract the blobs (binary image)
BW = (I==1);

%# skeletonization + dilation
BW = bwmorph(BW, 'skel', Inf);
BW = imdilate(BW, strel('square',2*1+1));

%# connected components
L = bwlabel(BW);
imshow(label2rgb(L))

%# filter 15x15 neighborhood
for i=1:13
    L = nlfilter(L, [15 15], @myFilterFunc);
    imshow( label2rgb(L) )
end

%# result
L(I==1) = 0;                %# put blobs back
L(edge(L,'canny')) = 0;     %# edges
imshow( label2rgb(L,@jet,[0 0 0]) )
myFilterFunc.m 结果是:

下面是这个过程的动画:


你说的是黑线吗?在这种情况下,“弯曲”是什么意思。你可以在图片中选择一条线,画出“弯曲”后的效果吗?请看我的编辑。谢谢。@Ivy取决于你需要的幻影数量,但老实说,这类幻影的最佳幻影似乎是从真实图像(如你的示例)中提取的阈值/简化图像。@John我认为它可以模拟从核心椭圆中随机生长的某种形状,但是我还是不能让它工作。OP想要更多的生命细胞。i、 e.不太像Voronoi图。在示例照片中,你会看到一些细胞有更大的压力或其他什么,然后膨胀并挤压其他细胞。@John,我理解。我尽量使事情简单化。工作允许的时候我再试试。太好了!我会关注这个帖子。这是一个很好的问题。@John你觉得我的新画怎么样?我还在研究一些细节!真是太棒了。我喜欢!上面使用的算法,如果我的理解是正确的,您可以为分水岭区域指定不同的颜色,一旦膨胀彼此相遇,它将返回黑色背景色的边缘。它在数学中非常有效。现在我正尝试在matlab中应用这个方法,希望我能做到。谢谢。@Ivy是的。当心随机化部分。如果你不这样做,你最终会得到一个美丽的方形格子呢拼图。祝你好运@Ivy用户Amro是将Mathematica翻译成Matlab的大师。。。以防万一,谢谢你的信任投票,但这是一个很难翻译的问题(我自己还在学习数学)。。。无论如何,我会尽快看一看,然后回来报告。非常好的解决方案+1@Amro你很值得我表扬!无论如何,如果你正在学习Mma,记得在SO中查看Mma标签问题和答案。有很多知识渊博的用户可供学习。+1不错。在我的回答中使用了掩蔽来提供额外的随机步骤。不管怎样,我认为这已经足够好了。恭喜你@阿姆罗:邻近的区域需要时间…不管怎样,那真的很酷!
(*Now reduce to a skeleton to get a somewhat random starting point.  
The actual algorithm for this dilation does not matter, as far as we 
get a random area slightly larger than the original elipses *)
id = Dilation[SkeletonTransform[
             Dilation[SkeletonTransform@ColorNegate@Binarize@i3, 3]], 1] 
(*Now the real random dilation loop*)
(*Init vars*)
p = Array[1 &, 70]; j = 1;
(*Store in w an image with a different color for each cluster, so we 
can find edges between them*)
w = (w1 = 
      WatershedComponents[
       GradientFilter[Binarize[id, .1], 1]]) /. {4 -> 0} // Colorize;
(*and loop ...*)
For[i = 1, i < 70, i++,
 (*Select edges in w and dilate them with a random 3x3 kernel*)
 ed = Dilation[EdgeDetect[w, 1], RandomInteger[{0, 1}, {3, 3}]];
 (*The following is the core*)
 p[[j++]] = w =
   ImageFilter[  (* We apply a filter to the edges*)
    (Switch[
          Length[#1],  (*Count the colors in a 3x3 neighborhood of each pixel*)
          0, {{{0, 0, 0}, 0}},          (*If no colors, return bkg*)
          1, #1,                        (*If one color, return it*)
          _, {{{0, 0, 0}, 0}}])[[1, 1]] (*If more than one color, return bkg*)&@
      Cases[Tally[Flatten[#1, 1]], 
       Except[{{0.`, 0.`, 0.`}, _}]] & (*But Don't count bkg pixels*),
    w, 1,
    Masking -> ed,       (*apply only to edges*)
    Interleaving -> True (*apply to all color chanels at once*)]
 ]
NestList[
 ImageFilter[  
   If[Length[#1] ==  1, #1[[1, 1]], {0, 0, 0}] &@
     Cases[Tally[Flatten[#1, 1]], Except[{0.` {1, 1, 1}, _}]] & , #, 1,
   Masking      -> Dilation[EdgeDetect[#, 1], RandomInteger[{0, 1}, {3, 3}]],  
   Interleaving -> True ] &,
 WatershedComponents@GradientFilter[Binarize[id,.1],1]/.{4-> 0}//Colorize, 
5]
%# read image (indexed image)
[I,map] = imread('http://i.stack.imgur.com/YENhB.png');

%# extract the blobs (binary image)
BW = (I==1);

%# skeletonization + dilation
BW = bwmorph(BW, 'skel', Inf);
BW = imdilate(BW, strel('square',2*1+1));

%# connected components
L = bwlabel(BW);
imshow(label2rgb(L))

%# filter 15x15 neighborhood
for i=1:13
    L = nlfilter(L, [15 15], @myFilterFunc);
    imshow( label2rgb(L) )
end

%# result
L(I==1) = 0;                %# put blobs back
L(edge(L,'canny')) = 0;     %# edges
imshow( label2rgb(L,@jet,[0 0 0]) )
function p = myFilterFunc(x)
    if range(x(:)) == 0
        p = x(1);                %# if one color, return it
    else
        p = mode(x(x~=0));       %# else, return the most frequent color
    end
end