[Insight-users] strange problem about ITK
宋涛
prog_st at 163 . com
Sun, 7 Sep 2003 14:04:24 +0800 (CST)
--Boundary-=_iHBWpVMuGhxqDPnjuTlmweyCQomO
Content-Type: text/plain
Content-Transfer-Encoding: 8bit
Hi Luis,
source code
=====================================================================================
const unsigned int IMAGE_DIMENSION = 2 ;
const int IMAGE_WIDTH = 400;
const int IMAGE_HEIGHT = 240;
const unsigned int NUMBEROFPIXELS = IMAGE_WIDTH * IMAGE_HEIGHT ;
typedef unsigned char GrayPixelType ;
typedef itk::Image< GrayPixelType, IMAGE_DIMENSION > GrayImageType ;
typedef itk::ImportImageFilter< GrayPixelType, IMAGE_DIMENSION > GrayImportFilterType ;
typedef itk::ImageFileReader< GrayImageType > GrayReaderType ;
typedef itk::ImageFileWriter< GrayImageType > GrayWriterType ;
typedef itk::RGBPixel< unsigned char > RGBPixelType ;
typedef itk::Image< RGBPixelType, IMAGE_DIMENSION > RGBImageType ;
typedef itk::ImportImageFilter< RGBPixelType, IMAGE_DIMENSION > RGBImportFilterType ;
typedef itk::ImageFileReader< RGBImageType > RGBReaderType ;
typedef itk::ImageFileWriter< RGBImageType > RGBWriterType ;
RGBReaderType::Pointer reader = RGBReaderType::New();
reader->SetFileName( "E:/InputRGB.png");
try
{
reader->Update();
}
catch( itk::ExceptionObject & exp )
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << exp << std::endl;
}
RGBImageType::Pointer image = reader->GetOutput();
RGBImageType::IndexType pixelIndex;
RGBImageType::PixelType pixelValue;
int FileSize = NUMBEROFPIXELS * 3;
unsigned char *Value = new unsigned char[FileSize];
if( Value == NULL)
{
printf( "Memmory is limit!\n" );
}
for(unsigned int y = 0; y < IMAGE_HEIGHT; y++)
{
for(unsigned int x = 0; x < IMAGE_WIDTH; x++)
{
pixelIndex[0] = x; // x position
pixelIndex[1] = y; // y position
pixelValue = image->GetPixel( pixelIndex );
// B
Value[ ((IMAGE_HEIGHT - 1 -y) * IMAGE_WIDTH + x)*3 + 0] = pixelValue.GetBlue();
// G
Value[ ((IMAGE_HEIGHT - 1 -y) * IMAGE_WIDTH + x)*3 + 1] = pixelValue.GetGreen();
// R
Value[ ((IMAGE_HEIGHT - 1 -y) * IMAGE_WIDTH + x)*3 + 2] = pixelValue.GetRed();
}
}
FILE *stream = NULL;
int NumRead = 0;
if( (stream = fopen( "E:/OutputRGB.200", "w+" )) != NULL )
{
NumRead = fwrite( Value, sizeof( unsigned char ), FileSize, stream );
printf( "Number of items write = %d\n", NumRead );
fclose( stream );
}
else
{
printf( "File could not be opened\n" );
return 1;
}
delete[] Value;
========================================================================================================
this is a very strange problem!
i think the size of file("OutputRGB.200") is FileSize,
the function (printf( "Number of items write = %d\n", NumRead );) also output FileSize,
but ACTUALLY the size of file("OutputRGB.200") is greater than FileSize!!!!!!!!!!!!!!!!!
WHY?
--Boundary-=_iHBWpVMuGhxqDPnjuTlmweyCQomO
Content-Type: text/html
Content-Transfer-Encoding: 8bit
Hi Luis,<br> <br>source code <br>=================================================================================<br>====<br>const unsigned int IMAGE_DIMENSION = 2 ;<br>const int IMAGE_WIDTH = 400;<br>const int IMAGE_HEIGHT = 240;<br>const unsigned int NUMBEROFPIXELS = IMAGE_WIDTH * IMAGE_HEIGHT ;<br> <br>typedef unsigned char GrayPixelT<br>ype ;<br>typedef itk::Image< GrayPixelType, IMAGE_DIMENSION > GrayImageTy<br>pe ;<br>typedef itk::ImportImageFilter< GrayPixelType, IMAGE_DIMENSION > GrayImport<br>FilterType ;<br>typedef itk::ImageFileReader< GrayImageType > GrayReaderType ;<br>typedef itk::ImageFileWriter< GrayImageType > GrayWriterType ;<br> <br>typedef itk::RGBPixel< unsigned char > RGBPixelType ;<br>typedef itk::Image< RGBPixelType, IMAGE_DIMENSION > RGBImageType ;<br>typedef itk::ImportImageFilter< RGBPixelType, IMAGE_DIMENSION > RGBImportF<br>ilterType ;<br>typedef itk::ImageFileReader< RGBImageType > RGBReaderType ;<br>typedef itk::ImageFileWriter< RGBImageType > RGBWriterType ;<br><br><br> RGBReaderType::Pointer reader = RGBReaderType::New();<br> reader->SetFileName( "E:/InputRGB.png");<br> try<br> {<br> reader->Update();<br> }<br> catch( itk::ExceptionObject & exp ) <br> {<br> std::cerr << "Exception caught !" << std::endl;<br> std::cerr << exp << std::endl;<br> }<br><br> RGBImageType::Pointer image = reader->GetOutput();<br> RGBImageType::IndexType pixelIndex;<br> RGBImageType::PixelType pixelValue;<br> <br> int FileSize = NUMBEROFPIXELS * 3;<br> unsigned char *Value = new unsigned char[FileSize];<br> if( Value == NULL)<br> {<br> printf( "Memmory is limit!\n" );<br> }<br> <br> for(unsigned int y = 0; y < IMAGE_HEIGHT; y++)<br> {<br> for(unsigned int x = 0; x < IMAGE_WIDTH; x++)<br> {<br> pixelIndex[0] = x; // x position<br> pixelIndex[1] = y; // y position<br> <br> pixelValue = image->GetPixel( pixelIndex );<br> <br> // B<br> Value[ ((IMAGE_HEIGHT - 1 -y) * IMAGE_WIDTH + x)*3 + 0] = pixelValue.GetBlue()<br>;<br> <br> // G<br> Value[ ((IMAGE_HEIGHT - 1 -y) * IMAGE_WIDTH + x)*3 + 1] = pixelValue.GetGreen(<br>);<br> <br> // R<br> Value[ ((IMAGE_HEIGHT - 1 -y) * IMAGE_WIDTH + x)*3 + 2] = pixelValue.GetRed();<br><br> }<br> }<br> <br> FILE *stream = NULL;<br> int NumRead = 0;<br> <br> if( (stream = fopen( "E:/OutputRGB.200", "w+" )) != NULL )<br> {<br> NumRead = fwrite( Value, sizeof( unsigned char ), FileSize, stream );<br> printf( "Number of items write = %d\n", NumRead );<br> <br> fclose( stream );<br> }<br> else<br> {<br> printf( "File could not be opened\n" );<br> return 1;<br> }<br> <br> delete[] Value;<br> <br>=================================================================================<br>=======================<br> <br>this is a very strange problem! <br> <br>i think the size of file("OutputRGB.200") is FileSize,<br>the function (printf( "Number of items write = %d\n", NumRead );) also output Fil<br>eSize,<br> <br>but ACTUALLY the size of file("OutputRGB.200") is greater than FileSize!!!!!!!!!!<br>!!!!!!!<br> <br>WHY?<br><font style='font-size:12pt'>
<br>
==============================================<br>
<a target=_blank href='http://vip . 163 . com' title='http://vip . 163 . com'><font color=green><b>安全稳定大容量,收费伊妹儿免费30日完美体验~</b></a><br>
<a target=_blank href='http://mail . 163 . com' title='http://mail . 163 . com'><font color=red><b>中国最大的免费邮箱在等你 25兆空间 4兆附件!</b></a><br>
<a target=_blank href='http://popo . 163 . com' title='http://popo . 163 . com'><font color=green><b>点击网易泡泡惊喜无限 全免费手机短信任你发!</b></a><br><br>
--Boundary-=_iHBWpVMuGhxqDPnjuTlmweyCQomO--