[Insight-users] Problem with ImageFileWriter or Something Filter, after ImportImageFilter->itkImage

HeeMin Kang itk-heemin at live.com
Mon Jul 21 23:05:24 EDT 2008


Hi there,
 
Though I tried the whole week, I could NOT find the reason.
Of course, I found a similar case(ImportImageFiter->itkImage, data transfer, memory-mapped image etc.) , and then tried…
But, the data transfer(memory buffer à itkImage) was not work properly.
 
My situation is like follows:
 
My program based on ‘ImageRegistrationMFC’ / ITK 3.6 / CMake 2.6 / VC++2005 SP1(MFC8)
1. Using ATL::CImage’s load method, an image is loaded, and get the memory buffer by ATL::CImage:GetBits() method.
2. Transfer Memory buffer to itkImage by ImportImageFilter, and run importer->Update()
   --> Until this time, work properly. 
3. And then, save or filter proc. itkImage by ImageFileWriter/itk some filters
   --> This is a problem.
 
         Debug Msg: memcpy.asm
         TrialUp1:
    -->           mov      al,[esi]                       ; U - get byte from source (*Break Point)
                                                               ; V - spare
                    mov      [edi],al                      ; U - put byte in destination
                    mov      eax,[dst]                   ; V - return pointer to destination
                    pop       esi                            ; U - restore esi
                    pop       edi                            ; V - restore edi
                    N_EXIT  
 
 
My code is like follows:
 
/*=========================================================================  ItkRegMFCView.h : interface of the CItkRegMFCView class
  Include the essential header files for ITK image registration.  Core functionality for image registration comes from ImageRegistration1 example.  Please refer to InsightToolkit-3.0.0\Examples\Registration\ImageRegistration1.cxx    Author  Yong Su  E-mail  jean.timex at gmail.com  Date    January 29, 2007=========================================================================*/#pragma once
// Header files for ITK image registration#include "itkImageRegistrationMethod.h"
...
 
#include "itkImportImageFilter.h"#include "itkBinaryThresholdImageFilter.h"
#include "itkImage.h"
...
 
class CItkRegMFCView : public CView{
...
 
public:  CItkRegMFCDoc* GetDocument() const;
 
...
 
  typedef  float           PixelType;  typedef  BYTE          BytePixelType;
 
  ...
 
  typedef itk::Image< BytePixelType, Dimension >   ImageType;
 
  ...
 
  CImage imgBase;      // an instance of CImage for fixed image
  ...
};
#ifndef _DEBUG  // debug version in ItkRegMFCView.cppinline CItkRegMFCDoc* CItkRegMFCView::GetDocument() const   { return reinterpret_cast<CItkRegMFCDoc*>(m_pDocument); }#endif
 
 
 
/*=========================================================================  ItkRegMFCView.cpp : implementation of the CItkRegMFCView class    Note:     OnPaint() is used for updating images showing. Do not call this function     or invoke this function by calling Invalidate() from CommandIterationUpdate.   Because registration runs fast while refreshing the images runs slow.   UpdateView() is created for you to handle iteration information.
  Author  Yong Su  E-mail  jean.timex at gmail.com  Date    January 29, 2007=========================================================================*/#include "stdafx.h"
...
 
END_MESSAGE_MAP()
// CItkRegMFCView construction/destruction// Initialize the propertiesCItkRegMFCView::CItkRegMFCView():margin(10),interval(5),margin_d(60),freeViewMode(false),dragMode(true),showMode(0),onPress_Align(false), onPress_Base(false),onPress_Input(false),m_multiple_Align(1), m_multiple_Base(1), m_multiple_Input(1),m_bRunning(false){  name_imgAlign = "output.png";
  rectSrc_Base.left = 0;  rectSrc_Base.right = 0;  rectSrc_Base.top = 0;  rectSrc_Base.bottom = 0;
  rectSrc_Input.left = 0;  rectSrc_Input.right = 0;  rectSrc_Input.top = 0;  rectSrc_Input.bottom = 0;
  rectSrc_Align.left = 0;  rectSrc_Align.right = 0;  rectSrc_Align.top = 0;  rectSrc_Align.bottom = 0;
  offset_Base_x = 0;  offset_Base_y = 0;  offset_Input_x = 0;  offset_Input_y = 0;  offset_Align_x = 0;  offset_Align_y = 0;
  mouse.x = 0;  mouse.y = 0;
 
  image = ImageType::New();  image2 = ImageType::New();}
CItkRegMFCView::~CItkRegMFCView(){}
 
...
 
////////////////////////////////////////////////////////////////// Open fixed image////////////////////////////////////////////////////////////////void CItkRegMFCView::OnFileOpenbase(){  CString strFilter;  CSimpleArray<GUID> aguidFileTypes;  HRESULT hResult;
  hResult = imgBase.GetExporterFilterString(strFilter,aguidFileTypes,_T("All Image Files"));  if (FAILED(hResult)) {    MessageBox(_T("GetExporterFilter Calling Failed!"),0,0);    return;  }
  CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, strFilter);  dlg.m_ofn.nFilterIndex = m_nFilterLoad;  hResult = (int)dlg.DoModal();  if(FAILED(hResult)) {    return;  }
  m_nFilterLoad = dlg.m_ofn.nFilterIndex;  name_imgBase = dlg.GetFileName();  imgBase.Destroy();  hResult = imgBase.Load(name_imgBase);  if (FAILED(hResult)) {    MessageBox(_T("Base Image Loading Failed!"),0,0);    Invalidate();    UpdateWindow();    return;  }  //   typedef BYTE  PixelType;//   typedef itk::Image< PixelType, 2 > ImageType;//   ImageType::Pointer image = ImageType::New();//   ImageType::Pointer image2 = ImageType::New();
  typedef itk::ImageFileReader<ImageType> ReaderType;  ReaderType::Pointer reader = ReaderType::New();  reader->SetFileName("coronal150.png");  image2 = reader->GetOutput();  reader->Update();
  //////////////////////////////////////////////////////////////////////////  typedef itk::ImportImageFilter< BytePixelType, Dimension > ImportFilterType;  ImportFilterType::Pointer importer = ImportFilterType::New();
  int nx = imgBase.GetWidth();  int ny = imgBase.GetHeight();
 
  ImageType::SizeType size;  size[0] = nx;  size[1] = ny;
 
  ImageType::IndexType start;  start.Fill(0);
 
  ImageType::RegionType region;  region.SetSize( size );  region.SetIndex( start );  importer->SetRegion( region );
 
  double origin[2];  origin[0] = 0; //originX;  origin[1] = 0; //originY;  importer->SetOrigin( origin );
 
  double spacing[2];  spacing[0] = 1; //dx;  spacing[1] = 1; //dy;  importer->SetSpacing( spacing );
 
  const int totalNumberOfPixels = nx * ny;  BytePixelType *pixelData = static_cast< BytePixelType * >( (BYTE *)imgBase.GetBits() );
  const bool importFilterWillDeleteTheInputBuffer = false;  importer->SetImportPointer( pixelData,   totalNumberOfPixels,   importFilterWillDeleteTheInputBuffer );
  importer->Update();
 
  image = importer->GetOutput();//  image->GetPixelContainer()->ContainerManageMemoryOn();
//  image = image2;
//   typedef itk::BinaryThresholdImageFilter<ImageType, ImageType> FilterType;//   FilterType::Pointer filter = FilterType::New();// //   filter->SetInput( image );//   filter->SetOutsideValue( 0 );//   filter->SetInsideValue( 255 );//   filter->SetLowerThreshold( 160 );//   filter->SetUpperThreshold( 220 );// //   try//   {//     filter->Update();//   }//   catch( itk::ExceptionObject & exp ) //   {//    std::cerr << "Exception caught !" << std::endl;//    std::cerr << exp << std::endl;//   }
  typedef itk::ImageFileWriter<ImageType> WriterType;  WriterType::Pointer writer = WriterType::New();//  writer->SetInput( filter->GetOutput() );  writer->SetInput( image );  writer->SetFileName("output.bmp");  try  {      writer->Update();     // * Error: ImportImageFilter_err.PNG *     }  catch( itk::ExceptionObject & exp )   {   std::cerr << "Exception caught !" << std::endl;   std::cerr << exp << std::endl;  }
  // invoke onPaint()  Invalidate();  UpdateWindow();}
 
...
 
////////////////////////////////////////////////////////////////// handle Itk registration iteration information// //////////////////////////////////////////////////////////////void CItkRegMFCView::UpdateView(CString str){  CMainFrame *pMainFrame = (CMainFrame *)AfxGetApp()->m_pMainWnd;  CEdit *pEdit = (CEdit*)pMainFrame->m_wndDialogBar.GetDlgItem(IDC_INFO);  pEdit->SetWindowText(str);}//end
 
Pls give me some advice.
 
 
Thanks,
HeeMin
 
_________________________________________________________________
Explore the seven wonders of the world
http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080722/fda7acc7/attachment-0001.htm>


More information about the Insight-users mailing list