Well, this code also gives an exception. Thanks for the reply . I am starting to deal with iterators from now on<br><br> ReaderType::Pointer reader = ReaderType::New();<br><br> reader->SetFileName( fileName.toStdString() );<br>
reader->Update();<br><br> InputImageType::RegionType inputRegion =<br> reader->GetOutput()->GetLargestPossibleRegion();<br><br> <br> //typedef itk::Image< short, 3 > InputImageType;<br>
<br> InputImageType::Pointer image = reader->GetOutput();<br><br> <br><br> InputImageType::SizeType size = reader->GetOutput()->GetLargestPossibleRegion().GetSize();<br> InputImageType::IndexType index = reader->GetOutput()->GetLargestPossibleRegion().GetIndex();<br>
<br> <br><br> InputImageType::PixelType maxValue;<br> for(int i = index[0]; i<size[0]; i++)<br> {<br> for(int j = index[1]; j<size[1]; j++)<br> {<br>
InputImageType::IndexType currentIndex;<br> currentIndex[0] = i;<br> currentIndex[1] = j;<br> InputImageType::PixelType currentValue = image->GetPixel(currentIndex);<br>
if(currentValue>maxValue)<br> {<br> maxValue = currentValue;<br> }<br> }<br> }<br>
<br> ui->label_22->setText(QString("maximum_value_raw%1").arg(maxValue));<br><br><div class="gmail_quote">2011/6/7 Brecht Heyde <span dir="ltr"><<a href="mailto:Brecht.Heyde@med.kuleuven.be">Brecht.Heyde@med.kuleuven.be</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div link="blue" vlink="purple" lang="NL">
<div>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Hi John,</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">The following code should do (for 2D images)</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal" style="text-indent: 35.4pt;"><span style="font-size: 9pt; font-family: "Courier New"; color: blue;" lang="EN-US">int</span><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> main(<span style="color: blue;">void</span>)</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> {</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> <span style="color: green;">//Find maximum of 2D image</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> <span style="color: blue;">typedef</span> <span style="color: blue;">unsigned</span> <span style="color: blue;">char</span> PixelType;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> <span style="color: blue;">const</span> <span style="color: blue;">unsigned</span> <span style="color: blue;">int</span> dimension = 2;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> <span style="color: blue;">typedef</span> itk::Image<PixelType,dimension>
ImageType;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> <span style="color: blue;">typedef</span> itk::ImageFileReader<ImageType>
ReaderType;</span></p><div class="im">
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> ReaderType::Pointer
reader = ReaderType::New();</span></p>
</div><p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> std::string
filename = <span style="color: rgb(163, 21, 21);">"C://Code//ITK320//src//InsightToolkit-3.20.0//Examples//Data//BrainProtonDensitySliceShifted13x17y.mhd"</span>;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> reader->SetFileName(filename);</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> <span style="color: blue;">try</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> {</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> reader->Update();</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> }</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> <span style="color: blue;">catch</span>(itk::ExceptionObject &err)</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> {</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> std::cerr
<< <span style="color: rgb(163, 21, 21);">"Error: "</span> << err
<< std::endl;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> <span style="color: blue;">return</span> EXIT_FAILURE;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> }</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> ImageType::Pointer
image = reader->GetOutput();</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> ImageType::SizeType
size = reader->GetOutput()->GetLargestPossibleRegion().GetSize();</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> ImageType::IndexType
index = reader->GetOutput()->GetLargestPossibleRegion().GetIndex();</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> ImageType::PixelType
maxValue;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> <span style="color: blue;">for</span>(<span style="color: blue;">int</span> i = index[0];
i<size[0]; i++)</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> {</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> <span style="color: blue;">for</span>(<span style="color: blue;">int</span> j = index[1];
j<size[1]; j++)</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> {</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> ImageType::IndexType
currentIndex;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> currentIndex[0]
= i;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> currentIndex[1]
= j;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> ImageType::PixelType
currentValue = image->GetPixel(currentIndex);</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> <span style="color: blue;">if</span>(currentValue>maxValue)</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> {</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> maxValue
= currentValue;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> }</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> }</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> }</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> std::cout
<< <span style="color: rgb(163, 21, 21);">"maxValue: "</span> << (<span style="color: blue;">int</span>)maxValue << std::endl;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: "Courier New";" lang="EN-US"> </span><span style="font-size: 9pt; font-family: "Courier New"; color: blue;">return</span><span style="font-size: 9pt; font-family: "Courier New";"> EXIT_SUCCESS;</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: "Courier New";"> }</span><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">I would however strongly suggest using the imageIterators as
Roberto already pointed out. His code snippet should do the exact same thing,
only more efficient. Have a look in the software guide chapter 11 for examples
in using image iterators.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Regards,</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Brecht</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<div style="border-width: 1pt medium medium; border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; padding: 3pt 0cm 0cm;">
<p class="MsoNormal"><b><span style="font-size: 10pt;" lang="EN-US">From:</span></b><span style="font-size: 10pt;" lang="EN-US"> john smith
[mailto:<a href="mailto:mkitkinsightuser@gmail.com" target="_blank">mkitkinsightuser@gmail.com</a>] <br>
<b>Sent:</b> dinsdag 7 juni 2011 16:52<div><div></div><div class="h5"><br>
<b>To:</b> Brecht Heyde; <a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a><br>
<b>Subject:</b> Re: [Insight-users] get the maximum pixel value using
GetPixel() for 3D image</div></div></span></p>
</div><div><div></div><div class="h5">
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin-bottom: 12pt;">You have right.Using Iteretors
was really easy, but I am not yet used to them.Could somebody give me a small
code of finding the max value without using iterators, in order to compare the
two methods?<br>
<br>
Thanks a lot for all your replies.They are very useful.</p>
<div>
<p class="MsoNormal">2011/6/7 Brecht Heyde <<a href="mailto:Brecht.Heyde@med.kuleuven.be" target="_blank">Brecht.Heyde@med.kuleuven.be</a>></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">You are probably trying to
access a pixel location in image->GetPixel() which doesn’t exist. </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Try removing the lines, which
I think are not needed:</span></p>
<div>
<p class="MsoNormal"><span lang="EN-US"> image->SetRegions( region );<br>
image->Allocate();</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
</div>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">You should also modify the
following as your image’s origin might not be [0 0 0]: </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">index =
inputRegion.GetIndex();</span></p>
<p class="MsoNormal"><span lang="EN-US">for ( i=index[0];i<size_x;i++) {<br>
for ( j=index[1];i<size_y;j++){<br>
for ( k=index[2];i<size_z;k++){</span></p>
<p class="MsoNormal"><span lang="EN-US"> /*…*/</span></p>
<p class="MsoNormal"><span lang="EN-US"> }</span></p>
<p class="MsoNormal"><span lang="EN-US"> }</span></p>
<p class="MsoNormal"><span lang="EN-US">}</span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">start_x, start_y and start_z
are not needed anymore.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Try debugging to see at what
line of code you are getting the violation error or printing the i,j,k to see
where it goes wrong. Any C++ basic book can tell you how to do that.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Regards,</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Brecht</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<div style="border-width: 1pt medium medium; border-style: solid none none; padding: 3pt 0cm 0cm; border-color: -moz-use-text-color;">
<p class="MsoNormal"><b><span style="font-size: 10pt;" lang="EN-US">From:</span></b><span style="font-size: 10pt;" lang="EN-US"> john smith [mailto:<a href="mailto:mkitkinsightuser@gmail.com" target="_blank">mkitkinsightuser@gmail.com</a>]
<br>
<b>Sent:</b> dinsdag 7 juni 2011 16:24<br>
<b>To:</b> Brecht Heyde; <a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a></span></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size: 10pt;" lang="EN-US"><br>
<b>Subject:</b> Re: [Insight-users] get the maximum pixel value using
GetPixel() for 3D image</span></p>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style="margin-bottom: 12pt;">OK,
this is the exception that I get<br>
<br>
<i>Unhandled exception at 0x00286a67 in mainwindow.exe: 0xC0000005: Access
violation reading location 0x04960548.</i></p>
<div>
<p class="MsoNormal">2011/6/7
john smith <<a href="mailto:mkitkinsightuser@gmail.com" target="_blank">mkitkinsightuser@gmail.com</a>></p>
<p class="MsoNormal">Well,<br>
<br>
When I debug the code, then I am taking an exception:<br>
<i>Unhandled exception at 0x00856a67 in mainwindow.exe: 0xC0000005: Access
violation reading location 0x050f0548.</i><br>
<br>
Do yoy know why?Should I change something in my code?Is there wrong in the
logic of the code?<br>
Thanks for the replies</p>
<div>
<p class="MsoNormal" style="margin-bottom: 12pt;"><br>
<br>
ReaderType::Pointer reader = ReaderType::New();<br>
<br>
reader->SetFileName( fileName.toStdString()
);<br>
reader->Update();<br>
<br>
InputImageType::RegionType inputRegion =<br>
reader->GetOutput()->GetLargestPossibleRegion();<br>
<br>
<br>
//typedef itk::Image< short, 3 > InputImageType;<br>
<br>
InputImageType::Pointer image =
reader->GetOutput();<br>
<br>
<br>
<br>
InputImageType::IndexType start;<br>
InputImageType::SizeType size;</p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom: 12pt;"> size
= inputRegion.GetSize();<br>
// get the size of the hole 3D image<br>
size_x = size[0];<br>
size_y = size[1];<br>
size_z = size[2];<br>
</p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom: 12pt;">
start[0] = 0; // first index on X<br>
start[1] = 0; // first index on Y<br>
start[2] = 0; // first index on Z<br>
<br>
InputImageType::RegionType region;<br>
region.SetSize( size );<br>
region.SetIndex( start );<br>
<br>
// Pixel data is allocated<br>
image->SetRegions( region );<br>
image->Allocate();<br>
<br>
int i,j,k;<br>
int max_value=0;<br>
<br>
<br>
<br>
for ( i=0;i<size_x;i++) {<br>
for ( j=0;i<size_y;j++){<br>
for ( k=0;i<size_z;k++){<br>
<br>
InputImageType::IndexType pixelIndex;<br>
pixelIndex[0] = i; // x position<br>
pixelIndex[1] = j; // y position<br>
pixelIndex[2] = k; // z position<br>
<br>
InputImageType::PixelType pixelValue = image->GetPixel( pixelIndex );<br>
<br>
if(pixelValue>max_value){max_value=pixelValue;}<br>
<br>
}<br>
}<br>
}<br>
<br>
ui->label_22->setText(QString("maximum_value_raw%1").arg(max_value));</p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">2011/6/7
john smith <<a href="mailto:mkitkinsightuser@gmail.com" target="_blank">mkitkinsightuser@gmail.com</a>></p>
<p class="MsoNormal">I
have added this</p>
<div>
<p class="MsoNormal" style="margin-bottom: 12pt;"><br>
<br>
size = inputRegion.GetSize();<br>
// get the size of the hole 3D image<br>
size_x = size[0];<br>
size_y = size[1];<br>
size_z = size[2];</p>
</div>
<p class="MsoNormal">I
am getting into the loop, but now I am getting an exception.Do you know what I
am doing wrong? I have declared the size_x,size_y,size_z in an other function
as it seems bellow, and declare them as global variable.Is it this declaration
responcible for the exception?<br>
<br>
Thanks</p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom: 12pt;"><br>
</p>
<div>
<p class="MsoNormal">2011/6/7
Brecht Heyde <<a href="mailto:Brecht.Heyde@med.kuleuven.be" target="_blank">Brecht.Heyde@med.kuleuven.be</a>></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Sorry, it should have been:</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">size = inputRegion.GetSize();</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Regards,</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Brecht Heyde</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<div>
<div style="border-width: 1pt medium medium; border-style: solid none none; padding: 3pt 0cm 0cm; border-color: -moz-use-text-color;">
<p class="MsoNormal"><b><span style="font-size: 10pt;" lang="EN-US">From:</span></b><span style="font-size: 10pt;" lang="EN-US"> <a href="mailto:insight-users-bounces@itk.org" target="_blank">insight-users-bounces@itk.org</a> [mailto:<a href="mailto:insight-users-bounces@itk.org" target="_blank">insight-users-bounces@itk.org</a>]
<b>On Behalf Of </b>Brecht Heyde<br>
<b>Sent:</b> dinsdag 7 juni 2011 15:34<br>
<b>To:</b> 'john smith'; 'robert tamburo'; <a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a></span></p>
<div>
<p class="MsoNormal"><span style="font-size: 10pt;" lang="EN-US"><br>
<b>Subject:</b> Re: [Insight-users] get the maximum pixel value using
GetPixel() for 3D image</span></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Hi,</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Your size_x, size_y and size_z
are not representing the actual size of the image.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Add:</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">size =
inputRegion->GetSize();</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Before </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">size_x = …</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">size_y = …</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">size_z = …</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">I would however also suggest
to use an imageIterator.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Regards,</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Brecht Heyde</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<div style="border-width: 1pt medium medium; border-style: solid none none; padding: 3pt 0cm 0cm; border-color: -moz-use-text-color;">
<p class="MsoNormal"><b><span style="font-size: 10pt;" lang="EN-US">From:</span></b><span style="font-size: 10pt;" lang="EN-US"> <a href="mailto:insight-users-bounces@itk.org" target="_blank">insight-users-bounces@itk.org</a> [mailto:<a href="mailto:insight-users-bounces@itk.org" target="_blank">insight-users-bounces@itk.org</a>]
<b>On Behalf Of </b>john smith<br>
<b>Sent:</b> dinsdag 7 juni 2011 15:27<br>
<b>To:</b> robert tamburo; <a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a><br>
<b>Subject:</b> Re: [Insight-users] get the maximum pixel value using
GetPixel() for 3D image</span></p>
</div>
<p class="MsoNormal"> </p>
</div>
<p class="MsoNormal" style="margin-bottom: 12pt;">Thanks
for your reply.I have used the MinimumMaximumImageCalculator, but know I want
to take the result playing with the raw data.But I am trying to do that without
using iterators, just with using for loop. I have added the largest possible
area from reader, but when I am debuging my code, it seems that I cannot get
inside the loop. Do you know why? Here is my code:</p>
<div>
<div>
<p class="MsoNormal"><br>
<br>
ReaderType::Pointer reader = ReaderType::New();<br>
<br>
reader->SetFileName( fileName.toStdString()
);<br>
reader->Update();<br>
<br>
InputImageType::RegionType inputRegion =<br>
reader->GetOutput()->GetLargestPossibleRegion();<br>
<br>
<br>
//typedef itk::Image< short, 3 > InputImageType;<br>
<br>
InputImageType::Pointer image =
reader->GetOutput();<br>
<br>
<br>
<br>
InputImageType::IndexType start;<br>
InputImageType::SizeType size;<br>
<br>
// get the size of the hole 3D image<br>
size_x = size[0];<br>
size_y = size[1];<br>
size_z = size[2];<br>
<br>
start[0] = 0; // first index on X<br>
start[1] = 0; // first index on Y<br>
start[2] = 0; // first index on Z<br>
<br>
InputImageType::RegionType region;<br>
region.SetSize( size );<br>
region.SetIndex( start );<br>
<br>
// Pixel data is allocated<br>
image->SetRegions( region );<br>
image->Allocate();<br>
<br>
int i,j,k;<br>
int max_value=0;<br>
<br>
for ( i=0;i<size_x;i++) {<br>
for ( j=0;i<size_y;j++){<br>
for ( k=0;i<size_z;k++){<br>
<br>
InputImageType::IndexType
pixelIndex;<br>
pixelIndex[0] = i; // x position<br>
pixelIndex[1] = j; // y position<br>
pixelIndex[2] = k; // z position<br>
<br>
InputImageType::PixelType pixelValue = image->GetPixel( pixelIndex );<br>
<br>
if(pixelValue>max_value){max_value=pixelValue;}<br>
<br>
}<br>
}<br>
}<br>
<br>
ui->label_22->setText(QString("maximum_value_raw%1").arg(max_value));</p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">2011/6/7
robert tamburo <<a href="mailto:robert.tamburo@gmail.com" target="_blank">robert.tamburo@gmail.com</a>></p>
<p class="MsoNormal">GetPixel()
belongs to itkImage, not the reader. Try
reader->GetOutput()->GetPixel(index). </p>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">Two
other things: 1) You may want to consider using an ImageRegionIterator instead
of for loops, and 2) You can use the MinimumMaximumImageCalculator to get the
maximum intensity in an image.</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">There
are examples on how to use each class at <a href="http://www.itk.org/Wiki/ITK/Examples" target="_blank">http://www.itk.org/Wiki/ITK/Examples</a></p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom: 12pt;"> </p>
<div>
<div>
<div>
<p class="MsoNormal">On
Tue, Jun 7, 2011 at 8:36 AM, john smith <<a href="mailto:mkitkinsightuser@gmail.com" target="_blank">mkitkinsightuser@gmail.com</a>>
wrote:</p>
</div>
</div>
<blockquote style="border-width: medium medium medium 1pt; border-style: none none none solid; padding: 0cm 0cm 0cm 6pt; margin: 5pt 0cm 5pt 4.8pt; border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color rgb(204, 204, 204);">
<div>
<div>
<p class="MsoNormal" style="margin-bottom: 12pt;">Hello,<br>
<br>
I am trying to find the maximum pixel value of a 3D image, and I am using
the GetPixel method with 3 loops.I want to load my image from a file so I
created a reader pointer.Does this pointer include the raw data of my image? I
have created the following code but I get an error: GetPixel() method is not a
member of reader. Could somebody tell me what I am doing wrong? How I could
find the maximum pixel value of a loaded image with the method of GetPixel()?<br>
<br>
Thanks<br>
<br>
typedef
short
InputPixelType;<br>
const unsigned int
Dimension = 3;<br>
<br>
typedef itk::Image< InputPixelType, Dimension
> InputImageType;<br>
typedef itk::ImageFileReader< InputImageType >
ReaderType;<br>
<br>
<br>
ReaderType::Pointer reader = ReaderType::New();<br>
<br>
reader->SetFileName( fileName.toStdString()
);<br>
reader->Update();<br>
<br>
InputImageType::RegionType inputRegion =<br>
reader->GetOutput()->GetLargestPossibleRegion();<br>
<br>
InputImageType::SizeType size = inputRegion.GetSize();<br>
<br>
// get the size of the hole 3D image<br>
size_x = size[0];<br>
size_y = size[1];<br>
size_z = size[2];<br>
<br>
InputImageType::IndexType start = inputRegion.GetIndex();<br>
start[0] = 0; // first index on X<br>
start[1] = 0; // first index on Y<br>
start[2] = 0; // first index on Z<br>
<br>
int i,j,k;<br>
int max_value=0;<br>
for ( i=0;i<size_x;i++) {<br>
for ( j=0;i<size_y;j++){<br>
for ( k=0;i<size_z;k++){<br>
<br>
InputImageType::IndexType pixelIndex;<br>
pixelIndex[0] = i; // x position<br>
pixelIndex[1] = j; // y position<br>
pixelIndex[2] = k; // z position<br>
<br>
InputImageType::PixelType pixelValue = reader->GetPixel( pixelIndex );<br>
<br>
if(pixelValue>max_value){max_value=pixelValue;}<br>
<br>
}<br>
}<br>
}</p>
</div>
</div>
<p class="MsoNormal">_____________________________________</p>
<div>
<p class="MsoNormal" style="margin-bottom: 12pt;"><br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"> </p>
</div>
</div>
<p class="MsoNormal"> </p>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"> </p>
</div>
</div>
</div>
<p class="MsoNormal"> </p>
</div>
</div>
</div>
<p class="MsoNormal"> </p>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"> </p>
</div></div></div>
</div>
</blockquote></div><br>