Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program new;
- {$DEFINE ERR_HIDE_ALL}
- {$I SimbaExt/SimbaExt.simba}
- function ImSplitShapes(Im:TIntMatrix; Tol:Int32): T2DPointArray;
- var
- i,j,w,h,hi,trace,color:Int32;
- adj,tpa,queue:TPointArray;
- pt:TPoint;
- begin
- W := im.Width();
- H := im.Height();
- SetLength(Adj,8);
- TPA := TPAFromBox([0,0,w-1,h-1]);
- hi := -1;
- for i:=0 to High(TPA) do
- begin
- pt := TPA[i];
- Trace := im[pt.y,pt.x];
- if Trace = -1 then Continue;
- inc(hi);
- SetLength(Result, hi+1);
- Queue.Append(pt);
- while not(Queue.IsEmpty) do
- begin
- se.GetAdjacent(Adj, Queue.Pop() ,True);
- for j:=0 to 7 do
- if InRange(adj[j].y,0,H-1) and InRange(adj[j].x,0,W-1) then
- begin
- color := Im[adj[j].y, adj[j].x];
- if (color <> -1) and (SimilarColors(color, trace, tol)) then
- begin
- Queue.Append(adj[j]);
- Result[hi].Append(adj[j]);
- Im[adj[j].y, adj[j].x] := -1;
- end;
- end;
- end;
- end;
- end;
- var
- Im:TRafBitmap;
- ATPA:T2DPointArray;
- i:Int32;
- begin
- Im.Open('tests/c__.jpg');
- Im.SetSize(Im.Width*2, Im.Height);
- ATPA := ImSplitShapes(Im.ToMatrix(), 60);
- for i:=0 to High(ATPA) do
- begin
- ATPA[i].Offset(Im.Width div 2,0);
- Im.SetPixels(ATPA[i], Random($FFFFFF));
- end;
- Im.Debug();
- Im.Save('tmp.png');
- Im.Free();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement