[vtkusers] New-Member: VTK-Disparity
cecile lombardot
cecile_lombardot at hotmail.com
Wed Jan 21 19:03:23 EST 2004
Hi all,
I am new in VTK and I would like to translate a basic stereo/disparity
calculation software into VTK format. I want to use it for 3D Object
representation caluclated from stereo images. I have attached the piece of
software. Any help is appreciated for helping to bring it in VTK format and
discribing bottle-necks and other problems related to this subject.
Thank you very much /Merci beaucoup
CECILE LOMBARDOT
////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
/* Image variables */
char Name1[50];
char Name2[50];
char Name3[50];
IM_TYPE *Image1;
IM_TYPE *Image2;
IM_TYPE *Image3;
IM_TYPE *Image4;
SHORT_TYPE **Data1;
SHORT_TYPE **Data2;
SHORT_TYPE **Data3;
SHORT_TYPE **Data4;
SHORT_TYPE **Data5;
int PixType, Xdim, Ydim, Zdim, DimCnt;
/* Program variables */
int Width = 15;
int Width2 = 7;
int i = 0, x, y, s, min, left, right;
while ((++i < argc) && (argv[i][0] == '-'))
switch (argv[i][1])
{
case 'w':
if (sscanf(argv[++i], "%d", &Width) == 0)
Error("Could not get integer argument");
Width2 = Width / 2;
Width = Width2 * 2 + 1;
break;
case 'd':
Debug = TRUE;
break;
default:
Error("Invalid option encountered");
break;
}
/* Check number of file names */
if (argc - i != 3)
{
fprintf(stderr, "Usage: stereo [options] left right outfile\n");
fprintf(stderr, " [-w #] Width of smoothing window (15)\n");
exit(1);
}
/* Get image file names from argument list */
if (sscanf(argv[i++], "%s", Name1) == 0)
Error("Could not get input file name");
if (sscanf(argv[i++], "%s", Name2) == 0)
Error("Could not get input file name");
if (sscanf(argv[i++], "%s", Name3) == 0)
Error("Could not get output file name");
/* Read left image */
Image1 = im_open(Name1, &PixType, &Xdim, &Ydim, &Zdim, &DimCnt);
if (DimCnt != 2)
Error("Can not process 1D or 3D images");
Data1 = (SHORT_TYPE **) im_alloc2D(Image1, SHORT);
im_read(Image1, SHORT, (char *) &(Data1[0][0]));
/* Read right image */
Image2 = im_open(Name2, &PixType, &Xdim, &Ydim, &Zdim, &DimCnt);
if (DimCnt != 2)
Error("Can not process 1D or 3D images");
Data2 = (SHORT_TYPE **) im_alloc2D(Image2, SHORT);
im_read(Image2, SHORT, (char *) &(Data2[0][0]));
/* Create output image */
Image3 = im_create(Name3, SHORT, Xdim, Ydim, Zdim);
Data3 = (SHORT_TYPE **) im_alloc2D(Image3, SHORT);
/* Create temporary images */
Image4 = im_create("/dev/null", SHORT, Xdim, Xdim, 1);
Data4 = (SHORT_TYPE **) im_alloc2D(Image4, SHORT);
Data5 = (SHORT_TYPE **) im_alloc2D(Image4, SHORT);
/* Calculate disparity between input images */
for (y = 0; y < Ydim; y++)
{
for (s = 0; s < Xdim / 2; s++)
{
/* Generate absolute differences */
for (x = 0; x < Xdim; x++)
{
if (x < s)
Data4[s][x] = 255;
else if (Data1[y][x] < Data2[y][x - s])
Data4[s][x] = Data2[y][x - s] - Data1[y][x];
else
Data4[s][x] = Data1[y][x] - Data2[y][x - s];
}
/* Generate summed differences */
Data5[s][0] = Data4[s][0];
for (x = 1; x < Xdim; x++)
Data5[s][x] = Data5[s][x - 1] + Data4[s][x];
/* Generate smoothed differences */
for (x = 0; x < Xdim; x++)
{
if ((left = x - Width2) < 0)
left = 0;
if ((right = x + Width2) > Xdim - 1)
right = Xdim - 1;
Data4[s][x] = Data5[s][right] - Data5[s][left];
}
}
/* Select best alignments */
for (x = 0; x < Xdim; x++)
{
min = 0;
for (s = 1; s < Xdim / 2; s++)
if (Data4[s][x] < Data4[min][x])
min = s;
Data3[y][x] = Data4[min][x]; /* best match error */
Data3[y][x] = min; /* best displacement */
}
}
/* Write information to output image */
im_write(Image3, SHORT, (char *) &(Data3[0][0]));
im_free2D((char **) Data1);
im_free2D((char **) Data2);
im_free2D((char **) Data3);
im_free2D((char **) Data4);
im_free2D((char **) Data5);
return (0);
}
_________________________________________________________________
E-Mails sind Ihnen nicht schnell genug? http://messenger.msn.de MSN
Messenger - Kommunikation in Echtzeit
More information about the vtkusers
mailing list