小编cla*_*lax的帖子

朱莉娅中的 vcat StackOverflowError

我编写了一个函数来检测数组中的对象。在本例中,我使用它来清除接触图像边框的白色物体。但问题是,vcat 中总是存在 StackOverFlowError 并且它发生在不同的行(取决于图像)。这是一个最小的工作示例。它适用于第二张图像,但不适用于第一张图像: 测试.png 测试2.png

using Images


function getImChars(I::Array)
  charAr=copy(I);
  indexMax=find(x->(x==1),charAr);
  (h,w)=size(charAr);
  # check border values
  (r,c)=ind2sub(size(charAr),indexMax);
  indexBorderR1=find(x->(x==1),r);
  indexBorderR2=find(x->(x==h),r);
  indexBorderR=[indexBorderR1;indexBorderR2];
  indexBorderC1=find(x->(x==1),c);
  indexBorderC2=find(x->(x==w),c);
  indexBorderC=[indexBorderC1;indexBorderC2];
  borderPixels=[999;999]; # initialize def value FIX
  for bRc=1:length(indexBorderR)
    borderPixels=[borderPixels [r[indexBorderR[bRc]];c[indexBorderR[bRc]]]];
  end
  for bCc=1:length(indexBorderC)
     borderPixels=[borderPixels [r[indexBorderC[bCc]];c[indexBorderC[bCc]]]];
  end
 borderPixels=borderPixels[:,2:end];
  (rbP,cbP)=size(borderPixels);
  fcharAr=[];
  for k=1:cbP
  bP=[borderPixels[:,k];false;false;false;false];
  locObj1=[];
  locObj2=[];
  locObj3=[];
  locObj4=[];
  locObj5=[];
  locObj6=[];
  if(charAr[bP[1],bP[2]]==0)
   continue;
  else
   charAr[bP[1],bP[2]]=0;
  end
  recGetCharClearBorders(true,false,h,w,bP,locObj1,locObj2,locObj3,locObj4,locObj5,locObj6,charAr);
  end
return charAr;
end



function recGetCharClearBorders(firstFlag::Bool,doNotAdd::Bool,h::Int,w::Int,hP::Array,locObj1::Array,locObj2::Array,locObj3::Array,locObj4::Array,locObj5::Array,locObj6::Array,imAr::Array)
  leftPoint=[hP[1];hP[2]-1;0;0;0;0];
  rightPoint=[hP[1];hP[2]+1;0;0;0;0];
  topPoint=[hP[1]-1;hP[2];0;0;0;0];
  bottomPoint=[hP[1]+1;hP[2];0;0;0;0];
 # check if it is not out of bounds and relative directions
  if(topPoint[1]!=0)
    if(imAr[topPoint[1],topPoint[2]]==1) …
Run Code Online (Sandbox Code Playgroud)

julia

3
推荐指数
1
解决办法
583
查看次数

标签 统计

julia ×1