<DIV id=RTEContent>Hi,</DIV> <DIV> </DIV> <DIV>I translate a matlab procedure into C++ with ITK to make things quicker. Now, comparing both of them, I found that results are the same but my <STRONG>C++ version with ITK is twice slower than matlab</STRONG>, whereas the contrary was expected. Could someone tell me what is wrong with my code: is there things that I can improve and time that I can save?</DIV> <DIV> </DIV> <DIV>Here is what I did:</DIV> <DIV><FONT size=2> <div> </div> <div><STRONG><EM>constructeur()</EM></STRONG></div> <div><STRONG><EM>{</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM> this</EM></STRONG></FONT><FONT size=2><STRONG><EM>->input = NULL;</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM> this</EM></STRONG></FONT><FONT size=2><STRONG><EM>->image1 = NULL;</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM> this</EM></STRONG></FONT><FONT
size=2><STRONG><EM>->image2 = NULL;</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM> this</EM></STRONG></FONT><FONT size=2><STRONG><EM>->coeff = NULL;</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM> this</EM></STRONG></FONT><FONT size=2><STRONG><EM>->shiftx = NULL;</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM> this</EM></STRONG></FONT><FONT size=2><STRONG><EM>->shifty = NULL;</EM></STRONG></div> <div><STRONG><EM></EM></STRONG></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2><STRONG><EM> //filters</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM> extractSlice = ExtractSliceFilter::New();</EM></STRONG></div> <div><STRONG><EM> extractRegion = ExtractRegionFilter::New();</EM></STRONG></div> <div><STRONG><EM> fft1 = FFTFilterType::New();</EM></STRONG></div> <div><STRONG><EM> fft2 = FFTFilterType::New();
</EM></STRONG></div> <div><STRONG><EM> mult = MultiplyFilter::New(); </EM></STRONG></div> <div><STRONG><EM> ifft = IFFTFilterType::New();</EM></STRONG></div> <div><STRONG><EM></EM></STRONG></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2><STRONG><EM> //release extra data</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM> extractSlice->GetOutput()->ReleaseDataFlagOn();</EM></STRONG></div> <div><STRONG><EM> extractRegion->GetOutput()->ReleaseDataFlagOn();</EM></STRONG></div> <div><STRONG><EM> fft1->GetOutput()->ReleaseDataFlagOn();</EM></STRONG></div> <div><STRONG><EM> fft2->GetOutput()->ReleaseDataFlagOn();</EM></STRONG></div> <div><STRONG><EM> mult->GetOutput()->ReleaseDataFlagOn();</EM></STRONG></div> <div><STRONG><EM> ifft->GetOutput()->ReleaseDataFlagOn();</EM></STRONG></div> <div><STRONG><EM> </EM></STRONG></div>
<div><STRONG><EM> mult->SetInput1(fft1->GetOutput());</EM></STRONG></div> <div><STRONG><EM> mult->SetInput2(fft2->GetOutput());</EM></STRONG></div> <div><STRONG><EM> ifft->SetInput(mult->GetOutput()); </EM></STRONG></div> <div><STRONG><EM>}</EM></STRONG></div></FONT><FONT color=#0000ff size=2> <div><STRONG><EM>void</EM></STRONG></FONT><FONT size=2><STRONG><EM> ComputeElastogram::SetInput( ImageType3D::ConstPointer image)</EM></STRONG></div> <div><STRONG><EM>{</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM>this</EM></STRONG></FONT><FONT size=2><STRONG><EM>->input = image;</EM></STRONG></div> <div><STRONG><EM>extractSlice->SetInput(</EM></STRONG></FONT><FONT color=#0000ff size=2><STRONG><EM>this</EM></STRONG></FONT><FONT size=2><STRONG><EM>->input);</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM>this</EM></STRONG></FONT><FONT
size=2><STRONG><EM>->calcul_deplacements();}</EM></STRONG></div> <div><STRONG><EM></EM></STRONG> </div></FONT><FONT color=#0000ff size=2> <div><STRONG><EM>void</EM></STRONG></FONT><FONT size=2><STRONG><EM> ComputeElastogram::calcul_deplacements() </EM></STRONG></div> <div><STRONG><EM>{</EM></STRONG></div> <div></FONT><STRONG><EM><FONT color=#0000ff size=2>unsigned</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> k1,k2,n;</FONT></EM></STRONG></div> <div><FONT size=2><STRONG><EM></EM></STRONG></FONT> </div><FONT size=2> <div><FONT color=#008000 size=2><STRONG><EM>//Creation des matrices de deplacement</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM>ImageType::IndexType start;</EM></STRONG></div> <div><STRONG><EM>start.Fill(0); </EM></STRONG></div> <div><STRONG><EM>ImageType::SizeType sz;</EM></STRONG></div> <div><STRONG><EM>sz[0] = dim_s[0]; </EM></STRONG></div> <div><STRONG><EM>sz[1] = dim_s[1];</EM></STRONG></div>
<div><STRONG><EM>ImageType::RegionType region;</EM></STRONG></div> <div><STRONG><EM>region.SetSize( sz );</EM></STRONG></div> <div><STRONG><EM>region.SetIndex( start );</EM></STRONG></div> <div><STRONG><EM>shifty = ImageType::New();</EM></STRONG></div> <div><STRONG><EM>shifty->SetRegions( region );</EM></STRONG></div> <div><STRONG><EM>shifty->Allocate();</EM></STRONG></div> <div><STRONG><EM>shiftx = ImageType::New();</EM></STRONG></div> <div><STRONG><EM>shiftx->SetRegions( region );</EM></STRONG></div> <div><STRONG><EM>shiftx->Allocate();</EM></STRONG></div></FONT> <div><STRONG><EM></EM></STRONG></FONT><FONT size=2> </div> <div><STRONG><EM>rowa = dim_fen[0]; cola = dim_fen[1];</EM></STRONG></div> <div></FONT><FONT color=#008000 size=2><STRONG><EM>/*--------Cropped ROI-------------*/</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM>ImageType3D::SizeType croppedSize;</EM></STRONG></div> <div><STRONG><EM>croppedSize[0] =
dim_img[0];</EM></STRONG></FONT><FONT color=#008000 size=2><STRONG><EM>//dim_roi[0];</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM>croppedSize[1] = dim_img[1];</EM></STRONG></FONT><FONT color=#008000 size=2><STRONG><EM>//dim_roi[1];</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM>croppedSize[2] = 0;</EM></STRONG></div> <div><STRONG><EM></EM></STRONG> </div> <div><STRONG><EM></EM></STRONG></div> <div><STRONG><EM>ImageType3D::IndexType croppedStart;</EM></STRONG></div> <div><STRONG><EM>croppedStart[0] = 0;</EM></STRONG></FONT><FONT color=#008000 size=2><STRONG><EM>//bords_c[0];</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM>croppedStart[1] = 0;</EM></STRONG></FONT><FONT color=#008000 size=2><STRONG><EM>//bords_l[0];</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM>croppedStart[2] = 0; </EM></STRONG></div> <div><STRONG><EM></EM></STRONG> </div> <div><STRONG><EM>ImageType3D::RegionType croppedRegion;</EM></STRONG></div>
<div><STRONG><EM>croppedRegion.SetSize(croppedSize);</EM></STRONG></div> <div><STRONG><EM>croppedRegion.SetIndex(croppedStart);</EM></STRONG></div> <div><STRONG><EM></EM></STRONG> </div> <div></FONT><FONT color=#008000 size=2><STRONG><EM>/*------------------------------------*/</EM></STRONG></div></FONT><FONT size=2> <div></FONT><FONT color=#008000 size=2><STRONG><EM>/*--------WINDOWS--------------------*/</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM>ImageType::SizeType extractedSize;</EM></STRONG></div> <div><STRONG><EM>extractedSize[0] =80;</EM></STRONG></div> <div><STRONG><EM>extractedSize[1] = 20;</EM></STRONG></div> <div><STRONG><EM>ImageType::IndexType extractedStart;</EM></STRONG></div> <div><STRONG><EM>extractedStart.Fill(0); </EM></STRONG></div> <div><STRONG><EM>ImageType::RegionType desiredRegion;</EM></STRONG></div> <div><STRONG><EM>desiredRegion.SetSize(extractedSize); </EM></STRONG></div>
<div><STRONG><EM>desiredRegion.SetIndex(extractedStart); </EM></STRONG></div> <div></FONT><FONT color=#008000 size=2><STRONG><EM>/*------------------------------------*/</EM></STRONG></FONT></div> <div><EM><STRONG><FONT color=#008000 size=2> </div></FONT></STRONG></EM><FONT size=2> <div></FONT><FONT color=#008000 size=2><STRONG><EM>/*--------Hanning Window--------------*/</EM></STRONG></FONT><FONT size=2><STRONG><EM> </EM></STRONG></div> <div><STRONG><EM>ImageType::Pointer hanning = ImageType::New();</EM></STRONG></div> <div><STRONG><EM>hanning->SetRegions( desiredRegion );</EM></STRONG></div> <div><STRONG><EM>hanning->Allocate();</EM></STRONG></div> <div></FONT><STRONG><EM><FONT color=#0000ff size=2>float</FONT><FONT size=2> **w = hanning_2D(dim_fen[1],dim_fen[0]);</FONT><FONT color=#008000 size=2>//taille de la fenetre 20lignes * 80colonnes</div></FONT></EM></STRONG><FONT size=2> <div><STRONG><EM>ImageRegionIterator it(hanning, desiredRegion);
</EM></STRONG></div> <div></FONT><STRONG><EM><FONT color=#0000ff size=2>for</FONT><FONT size=2>(</FONT><FONT color=#0000ff size=2>int</FONT></EM></STRONG><FONT size=2><STRONG><EM> i=0;i<dim_fen[1];i++)</EM></STRONG></div> <div></FONT><STRONG><EM><FONT color=#0000ff size=2>for</FONT><FONT size=2>(</FONT><FONT color=#0000ff size=2>int</FONT></EM></STRONG><FONT size=2><STRONG><EM> j=0; j<dim_fen[0]; j++)</EM></STRONG></div> <div><STRONG><EM>{</EM></STRONG></div> <div><STRONG><EM> it.Set(w[i][j]);</EM></STRONG></div> <div><STRONG><EM> ++it;</EM></STRONG></div> <div><STRONG><EM>}</EM></STRONG></div> <div><STRONG><EM>free_fmatrix_2d(w);</EM></STRONG></div> <div><STRONG><EM></EM></STRONG> </div> <div><STRONG><EM></EM></STRONG></div> <div><STRONG><EM>fhan = WindowFilter::New();</EM></STRONG></div> <div><STRONG><EM>fhan->GetOutput()->ReleaseDataFlagOn();</EM></STRONG></div> <div><STRONG><EM>fhan->SetInput1(hanning);</EM></STRONG></div>
<div><STRONG><EM>fhan->SetInput2(extractRegion->GetOutput());</EM></STRONG></div> <div></FONT><FONT color=#008000 size=2><STRONG><EM>/*------------------------------------*/</EM></STRONG></div> <div><STRONG><EM></EM></STRONG> </div></FONT><FONT size=2> <div><STRONG><EM>ImageRegionIterator it1(shifty, shifty->GetLargestPossibleRegion()); </EM></STRONG></div> <div><STRONG><EM>ImageRegionIterator it2(shiftx, shiftx->GetLargestPossibleRegion());</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM></EM></STRONG></div> <div><STRONG><EM></EM></STRONG></FONT><FONT color=#008000 size=2> </div></FONT><FONT size=2> <div><STRONG><EM>croppedStart[2] = 0;</EM></STRONG></div> <div><STRONG><EM>croppedRegion.SetIndex(croppedStart); </EM></STRONG></div> <div><STRONG><EM>extractSlice->SetExtractionRegion(croppedRegion);</EM></STRONG></div></FONT><FONT size=2> <div></FONT><FONT size=2><STRONG><EM>extractSlice->Update();</EM></STRONG></FONT></div> <div><FONT
size=2><STRONG><EM>ImageType2D::Pointer im0 = extractSlice->GetOutput();</EM></STRONG></div> <div><STRONG><EM>im0->DisconnectPipeline(); </EM></STRONG></div> <div><STRONG><EM></EM></STRONG></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT size=2><STRONG><EM>croppedStart[2] = 1;</EM></STRONG></div> <div><STRONG><EM>croppedRegion.SetIndex(croppedStart); </EM></STRONG></div> <div><STRONG><EM>extractSlice->SetExtractionRegion(croppedRegion);</EM></STRONG></div> <div><STRONG><EM>extractSlice->Modified();</EM></STRONG></div> <div></FONT><FONT size=2><STRONG><EM>extractSlice->Update();</EM></STRONG></FONT></div> <div><FONT size=2><STRONG><EM>ImageType2D::Pointer im1 = extractSlice->GetOutput();</EM></STRONG></div> <div><STRONG><EM>im1->DisconnectPipeline();</EM></STRONG></div> <div><STRONG><EM></EM></STRONG></div> <div></FONT><FONT color=#008000
size=2><STRONG><EM>//-------------------------------------------------------------------</EM></STRONG></FONT></div> <div><EM><STRONG><FONT color=#008000 size=2> </div></FONT></STRONG></EM><FONT size=2> <div><STRONG><EM>it1.GoToBegin();</EM></STRONG></div> <div><STRONG><EM>it2.GoToBegin(); </EM></STRONG></div> <div><STRONG><EM></EM></STRONG> </div> <div><STRONG><EM></EM></STRONG></div> <div></FONT><FONT color=#008000 size=2><STRONG><EM>// Correlation </EM></STRONG></FONT></div> <div><FONT size=2></FONT><FONT color=#0000ff size=2><STRONG><EM>for</EM></STRONG></FONT><FONT size=2><STRONG><EM>(k1 = 0; k1 < dim_s[0]; k1++)</EM></STRONG></div> <div><STRONG><EM>{</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM>for</EM></STRONG></FONT><FONT size=2><STRONG><EM>(k2 = 0; k2 < dim_s[1]; k2++)</EM></STRONG></div> <div><STRONG><EM>{ </EM></STRONG></div> <div><STRONG><EM> extractedStart[0] = k1*pas_fen[0]+ bords_c[0];</EM></STRONG></div>
<div><STRONG><EM> extractedStart[1] = k2*pas_fen[1]+ bords_l[0];</EM></STRONG></div> <div><STRONG><EM> desiredRegion.SetIndex(extractedStart); </EM></STRONG></div> <div><STRONG><EM></EM></STRONG></div> <div><STRONG><EM> extractRegion->SetRegionOfInterest(desiredRegion); </EM></STRONG></div> <div><STRONG><EM> extractRegion->SetInput(im0); </EM></STRONG></div> <div><STRONG><EM> fhan->Update();</EM></STRONG></div> <div><STRONG><EM> image1 = fhan->GetOutput();</EM></STRONG></div> <div><STRONG><EM> image1->DisconnectPipeline();</EM></STRONG></div> <div><STRONG><EM> extractRegion->SetInput(im1); </EM></STRONG></div> <div><STRONG><EM> fhan->Update();</EM></STRONG></div> <div><STRONG><EM> image2 = fhan->GetOutput();</EM></STRONG></div> <div><STRONG><EM> image2->DisconnectPipeline();</EM></STRONG></div> <div><STRONG><EM></EM></STRONG></div> <div></FONT><FONT color=#0000ff
size=2><STRONG><EM> int</EM></STRONG></FONT><FONT size=2><STRONG><EM> *shft = shift(image1,image2);</EM></STRONG></div> <div><STRONG><EM></EM></STRONG></div> <div><STRONG><EM> it1.Set(shft[0]);</EM></STRONG></div> <div><STRONG><EM> it2.Set(shft[1]);</EM></STRONG></div> <div><STRONG><EM> ++it1;</EM></STRONG></div> <div><STRONG><EM> ++it2;</EM></STRONG></div> <div><STRONG><EM></EM></STRONG></div> <div><STRONG><EM>}</EM></STRONG></FONT><FONT color=#008000 size=2><STRONG><EM>//k1</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM>}</EM></STRONG></FONT><FONT color=#008000 size=2><STRONG><EM>//k2 </EM></STRONG></FONT></div> <div><EM><STRONG><FONT color=#008000 size=2> </div></FONT></STRONG></EM><FONT size=2> <div><STRONG><EM>timer.Stop();</EM></STRONG></div> <div><STRONG><EM>fprintf(fp, "\n Elapsed time: %f\n", timer.GetMeanTime());</EM></STRONG></div> <div><STRONG><EM></EM></STRONG></div></FONT><FONT size=2> <div></FONT><FONT
size=2><STRONG><EM>}</EM></STRONG></FONT></div> <div><EM><STRONG><FONT size=2> </div></FONT></STRONG></EM><FONT color=#0000ff size=2> <div><STRONG><EM>int</EM></STRONG></FONT><FONT size=2><STRONG><EM>* ComputeElastogram::shift( ImageType::Pointer image1, ImageType::Pointer image2) </EM></STRONG></div> <div><STRONG><EM>{</EM></STRONG></div> <div></FONT><STRONG><EM><FONT color=#0000ff size=2>int</FONT><FONT size=2> *shft = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>int</FONT></EM></STRONG><FONT size=2><STRONG><EM>[2];</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM>this</EM></STRONG></FONT><FONT size=2><STRONG><EM>->calcul_coef(image2,image1);</EM></STRONG></div> <div><STRONG><EM></EM></STRONG></FONT><FONT size=2></FONT> </div> <div><FONT size=2><STRONG><EM>ImageType::IndexType index;</EM></STRONG></div> <div><STRONG><EM>index[0] = 0; index[1] = 0;</EM></STRONG></div>
<div></FONT><STRONG><EM><FONT color=#0000ff size=2>unsigned</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>int</FONT></EM></STRONG><FONT size=2><STRONG><EM> row, col; </EM></STRONG></div> <div><STRONG><EM>row=col=0;</EM></STRONG></div> <div><STRONG><EM>ImageType::PixelType max = coeff->GetPixel(index); </EM></STRONG></div> <div><STRONG><EM></EM></STRONG></div> <div><STRONG><EM>ImageRegionIterator it(coeff, coeff->GetLargestPossibleRegion()); </EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM>while</EM></STRONG></FONT><FONT size=2><STRONG><EM>( !it.IsAtEnd() )</EM></STRONG></div> <div><STRONG><EM>{</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM> if</EM></STRONG></FONT><FONT size=2><STRONG><EM>(it.Get()>max)</EM></STRONG></div> <div><STRONG><EM> {</EM></STRONG></div> <div><STRONG><EM> max = it.Get();</EM></STRONG></div> <div><STRONG><EM> index=it.GetIndex();</EM></STRONG></div>
<div><STRONG><EM> row = index[0];</EM></STRONG></div> <div><STRONG><EM> col = index[1];</EM></STRONG></div> <div><STRONG><EM>}</EM></STRONG></div> <div><STRONG><EM>++it;</EM></STRONG></div> <div><STRONG><EM>}</EM></STRONG></div> <div><STRONG><EM></EM></STRONG></div> <div><STRONG><EM>shft[0] = - rowa * (row > (</EM></STRONG></FONT><FONT color=#0000ff size=2><STRONG><EM>int</EM></STRONG></FONT><FONT size=2><STRONG><EM>)(rowa/2) ) + row;</EM></STRONG></div> <div><STRONG><EM>shft[1] = - cola * (col > (</EM></STRONG></FONT><STRONG><EM><FONT color=#0000ff size=2>int</FONT><FONT size=2>)(cola/2)) + col;</FONT></EM></STRONG><FONT size=2><STRONG><EM>}</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM>return</EM></STRONG></FONT><FONT size=2><STRONG><EM> shft;</EM></STRONG></div> <div><STRONG><EM>}</EM></STRONG></div></FONT><FONT color=#0000ff size=2> <div><STRONG><EM>void</EM></STRONG></FONT><FONT size=2><STRONG><EM>
ComputeElastogram::calcul_coef( ImageType::Pointer image1, ImageType::Pointer image2) </EM></STRONG></div> <div><STRONG><EM>{ </EM></STRONG></div> <div></FONT><FONT color=#008000 size=2><STRONG><EM>// Forward FFT filter</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM>fft1->SetInput( image1 );</EM></STRONG></div> <div><STRONG><EM>fft2->SetInput( image2 );</EM></STRONG></div> <div><STRONG><EM></EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM>try</EM></STRONG></FONT><FONT size=2><STRONG><EM>{ ifft->Update(); }</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM>catch</EM></STRONG></FONT><FONT size=2><STRONG><EM>(itk::ExceptionObject &e){</EM></STRONG></div> <div><STRONG><EM>CString msg;</EM></STRONG></div> <div><STRONG><EM>msg.Format("Erreur %s in %s\n", e.GetDescription(), e.GetLocation());</EM></STRONG></div> <div></FONT><FONT color=#0000ff size=2><STRONG><EM>return</EM></STRONG></FONT><FONT
size=2><STRONG><EM>;</EM></STRONG></div> <div><STRONG><EM>}</EM></STRONG></div> <div></FONT><FONT color=#008000 size=2><STRONG><EM>// Iterator which traverse the image</EM></STRONG></div></FONT><FONT size=2> <div><STRONG><EM>coeff = ifft->GetOutput();</EM></STRONG></div> <div></FONT><FONT size=2><STRONG><EM>}</EM></STRONG></FONT></div> <div><FONT size=2><STRONG><EM></EM></STRONG></FONT> </div> <div><FONT size=2>Actually, I don't see what is wrong. I tried to release data and so on, but it seems to make any difference. </FONT></div> <div><FONT size=2></FONT> </div> <div>Please help,</div> <div> </div> <div><FONT size=2>Isabelle</div></FONT></DIV><p>
                <hr size=1>
<b><font color=#FF0000>Appel audio GRATUIT</font> partout dans le monde</b> avec le nouveau Yahoo! Messenger<br>
<a href="http://us.rd.yahoo.com/messenger/mail_taglines/default/*http://fr.messenger.yahoo.com">Téléchargez le ici !</a>