How can i read a dicom file in "float pixel format", filtered and write it to an "unsigned char pixel format" dicom file?

ConnectedThresholdOutput3.dcm (513.0 KB)
next is my code from web:

typedef   float           InternalPixelType;
const     unsigned int    Dimension = 2;
typedef   signed short  InputPixelType;
typedef   signed short  OutputPixelType;
typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
// Software Guide : EndCodeSnippet

typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
typedef itk::ImageToVTKImageFilter<InternalImageType> ConnectorType;
typedef itk::CastImageFilter< InternalImageType, OutputImageType >
	CastingFilterType;
CastingFilterType::Pointer caster = CastingFilterType::New();


// We instantiate reader and writer types
//
typedef  itk::ImageFileReader< InternalImageType > ReaderType;
typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;
ConnectorType::Pointer connector = ConnectorType::New();
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();

reader->SetFileName(argv[1]);
writer->SetFileName(argv[2]);

//dicom read and write
typedef itk::GDCMImageIO           ImageIOType;
ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
reader->SetImageIO(gdcmImageIO);
writer->SetImageIO(gdcmImageIO);
reader->Update();
//end

try
{
	reader->Update();
}
catch (itk::ExceptionObject & e)
{
	std::cerr << "exception in file reader " << std::endl;
	std::cerr << e << std::endl;
	return EXIT_FAILURE;
}

//itkvtk
connector->SetInput(reader->GetOutput());

vtkImageActor *actor = vtkImageActor::New();
actor->SetInputData(connector->GetOutput());
vtkRenderer * ren = vtkRenderer::New();
ren->AddActor(actor);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);

vtkImageViewer* viewer = vtkImageViewer::New();

vtkRenderWindowInteractor* renderWindowInteractor = vtkRenderWindowInteractor::New();

viewer->SetInputData(connector->GetOutput());
viewer->SetupInteractor(renderWindowInteractor);
//renWin->SetInteractor(renderWindowInteractor);

viewer->SetColorWindow(255);
viewer->SetColorLevel(128);
viewer->Render();
renderWindowInteractor->Initialize();
//renWin->Render();
renderWindowInteractor->Start();
 
typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType >
	CurvatureFlowImageFilterType;
 
CurvatureFlowImageFilterType::Pointer smoothing =
	CurvatureFlowImageFilterType::New();
 
typedef itk::ConfidenceConnectedImageFilter<InternalImageType, InternalImageType>
	ConnectedFilterType;
 
ConnectedFilterType::Pointer confidenceConnected = ConnectedFilterType::New();
 
smoothing->SetInput(reader->GetOutput());
confidenceConnected->SetInput(smoothing->GetOutput());
caster->SetInput(confidenceConnected->GetOutput());
writer->SetInput(caster->GetOutput());
 
smoothing->SetNumberOfIterations(5);
smoothing->SetTimeStep(0.125);
 
confidenceConnected->SetMultiplier(2.5);
 
confidenceConnected->SetNumberOfIterations(5);
 
confidenceConnected->SetReplaceValue(255);
 

InternalImageType::IndexType  index;

index[0] = atoi(argv[3]);
index[1] = atoi(argv[4]);
confidenceConnected->SetSeed(index);
 
confidenceConnected->SetInitialNeighborhoodRadius(2);
 
try
{
	writer->Update();
}
catch (itk::ExceptionObject & excep)
{
	std::cerr << "Exception caught !" << std::endl;
	std::cerr << excep << std::endl;
}
  

reader->SetFileName(argv[2]);

ConnectorType::Pointer connector1 = ConnectorType::New();
connector1->SetInput(reader->GetOutput());

vtkImageActor *actor1 = vtkImageActor::New();
actor1->SetInputData(connector1->GetOutput());
vtkRenderer * ren1 = vtkRenderer::New();
ren1->AddActor(actor1);
vtkRenderWindow *renWin1 = vtkRenderWindow::New();
renWin1->AddRenderer(ren1);

vtkImageViewer* viewer1 = vtkImageViewer::New();

vtkRenderWindowInteractor* renderWindowInteractor1 = vtkRenderWindowInteractor::New();

viewer1->SetInputData(connector1->GetOutput());
viewer1->SetupInteractor(renderWindowInteractor1);
//renWin->SetInteractor(renderWindowInteractor);

viewer1->SetColorWindow(255);
viewer1->SetColorLevel(128);
viewer1->Render();
renderWindowInteractor1->Initialize();
//renWin->Render();
renderWindowInteractor1->Start();