www.GetXFactor.com

Leading Technology, Science,
Agriculture News and information


Part of the Identityscape.com network...

getxfactor.com jmoodmusic.com smartbusinesschoices.com mintdepot.com lowfaresalways.com evangelicalview.com shoppingpodder.com soproudlywehail.com webnews.ws currenthumor.com

 

 

Rotation of color bitmap
   Science and Technology news... Forum Index -> Image Processing Forum  
View previous topic :: View next topic  
Author Message
eljainc
Guest






PostPosted: Fri Oct 17, 2008 8:24 pm    Post subject: Rotation of color bitmap Reply with quote

Hello,

I am running into a bit of difficulty. I have an algorithm that
rotates an 8-bit bitmap (matrix). The content has been grayscale
images in the past. When I apply this towards an 8-bit color image,
the results are less than ideal. It seems the pixels that result look
almost random.
Here is my procedure:

Why would the color objects not be translated properly?

Thanks
Mike


Procedure RotateObject(M1:MatrixPtr;Angle:Single);
Type Small_Image=Array[0..119,0..119] of byte;
Small_ImagePtr=^Small_Image;
Var
i,j,n,m,ci,cj:Integer;
sina,cosa,oldi,oldj:Single;
r_oldi,r_oldj:real;
v,t,xmax,xmin,alpha,beta:Single;
ii,jj:Integer;
{X,rim,newimage:Small_ImagePtr;}
X,rim:Small_ImagePtr;

Const
MM:integer= 120;
NN:integer= 120;

Function Bilinear( x:Small_ImagePtr; a,b:Single; ii,jj:integer ):
Integer;
Var y:Single;
Begin
if ((ii<1) or (ii > 118)) then bilinear:=64 else
if ((jj<1) or (jj> 118)) then bilinear:=64 else
if (x^[ii,jj]=64) and (x^[ii+1,jj+1]=64) and (x^[ii+1,jj]=64) and
(x^[ii,jj+1]=64)
then bilinear:=64 else
{if ((ii<1) or (ii > 118)) then bilinear:=64 else
if ((jj<1) or (jj> 118)) then bilinear:=64 else
}
if ((a=0) and (b=0)) then bilinear:=x^[ii,jj] else
if (a=0) then
begin
y:=int((1-b)*x^[ii,jj]+b*x^[ii,jj+1]+0.5);
if y>63 then bilinear:=63 else bilinear:=round(y);
end else
if (b=0) then
begin
y:=int((1-a)*x^[ii,jj]+a*x^[ii+1,jj]+0.5);
if y>63 then bilinear:=63 else bilinear:=round(y);
end else
begin
y:=(1-a)*(1-b)*x^[ii,jj]+(1-a)*b*x^[ii,jj+1];
y:=y+a*(1-b)*x^[ii+1,jj]+a*b*x^[ii+1,jj+1]+0.5;
if y>63 then y:=63;
bilinear:=round(int(y));
end;
End;

Begin
angle:=6.283185307-angle;
sina:=sin(angle);
cosa:=cos(angle);
ci:=NN div 2;
cj:=MM div 2;
New(x);
For i:=0 to 119 do for j:=0 to 119 do X^[i,j]:=M1^[i-60,j-60];
New(rim);

For i:=0 to (NN-1) do For j:=0 to (MM-1) do
Begin
oldi:=(i-ci)*cosa-(j-cj)*sina+ci;
oldj:=(i-ci)*sina+(j-cj)*cosa+cj;
ii:=round(int(oldi));
jj:=round(int(oldj));
alpha:=oldi-int(oldi);
beta:=oldj-int(oldj);
rim^[i,j]:=bilinear(x,alpha,beta,ii,jj);
end;
for i:=0 to (NN-1) do for j:=0 to (MM-1) do
M1^[i-60,j-60]:=rim^[i,j];
dispose(x);
dispose(rim);
end;
Back to top
ImageAnalyst
Guest






PostPosted: Fri Oct 17, 2008 8:45 pm    Post subject: Re: Rotation of color bitmap Reply with quote

On Oct 17, 4:24 pm, eljainc <elja...@sbcglobal.net> wrote:
[quote]Hello,

I am running into a bit of difficulty. I have an algorithm that
rotates an 8-bit bitmap (matrix). The content has been grayscale
images in the past. When I apply this towards an 8-bit color image,
the results are less than ideal. It seems the pixels that result look
almost random.
Here is my procedure:

Why would the color objects not be translated properly?

Thanks
Mike

Procedure RotateObject(M1:MatrixPtr;Angle:Single);
Type Small_Image=Array[0..119,0..119] of byte;
     Small_ImagePtr=^Small_Image;
Var
  i,j,n,m,ci,cj:Integer;
  sina,cosa,oldi,oldj:Single;
  r_oldi,r_oldj:real;
  v,t,xmax,xmin,alpha,beta:Single;
  ii,jj:Integer;
  {X,rim,newimage:Small_ImagePtr;}
  X,rim:Small_ImagePtr;

Const
  MM:integer= 120;
  NN:integer= 120;

Function Bilinear( x:Small_ImagePtr; a,b:Single; ii,jj:integer ):
Integer;
Var y:Single;
Begin
   if ((ii<1) or (ii > 118)) then bilinear:=64 else
  if ((jj<1) or (jj> 118)) then bilinear:=64 else
  if (x^[ii,jj]=64) and (x^[ii+1,jj+1]=64) and (x^[ii+1,jj]=64) and
(x^[ii,jj+1]=64)
    then bilinear:=64 else
  {if ((ii<1) or (ii > 118)) then bilinear:=64 else
  if ((jj<1) or (jj> 118)) then bilinear:=64 else
  }
  if ((a=0) and (b=0)) then bilinear:=x^[ii,jj] else
  if (a=0) then
  begin
    y:=int((1-b)*x^[ii,jj]+b*x^[ii,jj+1]+0.5);
    if y>63 then bilinear:=63 else bilinear:=round(y);
  end else
  if (b=0) then
  begin
    y:=int((1-a)*x^[ii,jj]+a*x^[ii+1,jj]+0.5);
    if y>63 then bilinear:=63 else bilinear:=round(y);
  end  else
  begin
    y:=(1-a)*(1-b)*x^[ii,jj]+(1-a)*b*x^[ii,jj+1];
    y:=y+a*(1-b)*x^[ii+1,jj]+a*b*x^[ii+1,jj+1]+0.5;
    if y>63 then y:=63;
    bilinear:=round(int(y));
  end;
End;

Begin
  angle:=6.283185307-angle;
  sina:=sin(angle);
  cosa:=cos(angle);
  ci:=NN div 2;
  cj:=MM div 2;
  New(x);
  For i:=0 to 119 do for j:=0 to 119 do X^[i,j]:=M1^[i-60,j-60];
  New(rim);

  For i:=0 to (NN-1) do For j:=0 to (MM-1) do
  Begin
    oldi:=(i-ci)*cosa-(j-cj)*sina+ci;
    oldj:=(i-ci)*sina+(j-cj)*cosa+cj;
    ii:=round(int(oldi));
    jj:=round(int(oldj));
    alpha:=oldi-int(oldi);
    beta:=oldj-int(oldj);
    rim^[i,j]:=bilinear(x,alpha,beta,ii,jj);
  end;
  for i:=0 to (NN-1) do for j:=0 to (MM-1) do
M1^[i-60,j-60]:=rim^[i,j];
  dispose(x);
  dispose(rim);
end;
[/quote]
I understand images a lot faster than code. Could you post the input
and output gray scale and color images somewhere?
Back to top
Martin Leese
Guest






PostPosted: Sat Oct 18, 2008 2:48 am    Post subject: Re: Rotation of color bitmap Reply with quote

eljainc wrote:
[quote]Hello,

I am running into a bit of difficulty. I have an algorithm that
rotates an 8-bit bitmap (matrix). The content has been grayscale
images in the past. When I apply this towards an 8-bit color image,
the results are less than ideal. It seems the pixels that result look
almost random.
Here is my procedure:

Why would the color objects not be translated properly?
....
Function Bilinear( x:Small_ImagePtr; a,b:Single; ii,jj:integer ):
[/quote]
Er ... because you are using bi-linear
interpolation. Imagine you have neighbouring
pixels with values of 32 and 34. When
interpolated during your rotation, your new
image could well contain a pixel with a value
of 33.

With shades of gray, a graytone of 33 looks
very similar to graytones of 32 and 34.
However, when passed through a palette, 33
could appear very different from 32 or 34.
(I assume you are using a palette, although
using 3, 3, 2 bits for red, green, blue will
behave similarly.)

If I have diagnosed the problem correctly
then the simple solution is to use nearest
neighbour interpolation.

--
Regards,
Martin Leese
E-mail: please@see.Web.for.e-mail.INVALID
Web: http://members.tripod.com/martin_leese/
Back to top
Display posts from previous:   
   Science and Technology news... Forum Index -> Image Processing Forum  
Page 1 of 1
All times are GMT

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum