Sunday, May 20, 2012

Function Rotasi dalam Lingkaran pada pengolahan citra digital


function Rotation2(MInput:Matriks;pil:String):Matriks;
var
   i,j,r: integer;
   MOutput: Matriks;
begin
  if (pil='90C') or (pil='90UC') then
    begin
    if (Length(MInput)>Length(MInput[0])) then
      SetLength(MOutput, Length(MInput), Length(MInput[0]))
      else
      SetLength(MOutput, Length(MInput[0]), Length(MInput));
      r:=Length(Moutput) div 2;
      for i:= 0 to Length(MOutput)-1 do
        begin
          for j:=0 to Length(MOutput[0])-1 do
            begin
              if pil='90C' then
              begin
                  if (((i-r)*(i-r)+(j-r)*(j-r))<=r*r) then
                  MOutput[i,j]:=MInput[j,(Length(MOutput)-1)-i]
                  else
              MOutput[i,j]:=MInput[i,j]
              end
              else
              begin
              if ((i-r)*(i-r)+(j-r)*(j-r))<=r*r then
                  MOutput[i,j]:=MInput[(Length(MOutput[0])-1)-j,i]
                  else
              MOutput[i,j]:=MInput[i,j];
                  end;

            end;
        end;
    end
  else
      if (pil='180C') or (pil='180UC') then
        begin
             MOutput:=Rotation2(MInput,'90C');
             MOutput:=Rotation2(MOutput, '90C');
        end
          else
              if (pil='270C') then
                begin
                  MOutput:=Rotation2(MInput,'90UC');
                end
              else
                begin
                  MOutput:=Rotation2(MInput,'90C');
                end;
  Rotation2:=MOutput;
end;

No comments:

Post a Comment