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