<div dir="ltr"><div>I realize that itk::RandomImageSource is not meant to be a perfect source of randomness.  But it is pretty bad.  I was trying to generate a noise video with ITK -- by writing out 2D Images and then combining them using FFMPEG -- and A) for a given set of dimensions, itk::RandomImageSource generates exactly the same image. and B) the resulting image is clearly not that random.<br><br>I got better results (without much speed penalty) calling drand48 once per pixel.</div><div><br></div>Link to image generated: <a href="https://flic.kr/p/Nz1p7w">https://flic.kr/p/Nz1p7w</a><div><br></div><div><div>#include <iostream></div><div>#include <stdio.h></div><div>#include <sys/types.h></div><div>#include <unistd.h></div><div>#include <itkImage.h></div><div>#include <itkImageFileWriter.h></div><div>#include <itkImageRegionIterator.h></div><div>#include <itkRandomImageSource.h></div><div>#include <time.h></div><div>#include <stdlib.h></div><div>typedef itk::Image<unsigned char,2> ImageType;</div><div>typedef itk::ImageFileWriter<ImageType> ImageFileWriter;</div><div>typedef itk::RandomImageSource<ImageType> RandomImageSource;</div><div>typedef itk::ImageRegionIterator<ImageType> Iterator;</div><div><br></div><div>// 1080p</div><div>//const int XSize(1920);</div><div>//const int YSize(1080);</div><div>const int XSize(1280);</div><div>const int YSize(720);</div><div><br></div><div>int main(int argc, char **argv) {</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">  </span>ImageType::SizeType imageSize;</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>imageSize[0] = XSize;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>imageSize[1] = YSize;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// only used for the first GetBufferPointer method</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>ImageType::Pointer image = ImageType::New();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>image->SetRegions(imageSize);</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>image->Allocate();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">       </span>ImageFileWriter::Pointer writer = ImageFileWriter::New();</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>for(unsigned i = 0; i < (60*24); ++i) {</div><div><span class="Apple-tab-span" style="white-space:pre">           </span>char fname[256];</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>sprintf(fname,"%04u.tiff", i);</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>writer->SetFileName(fname);</div><div>#if 0</div><div><span class="Apple-tab-span" style="white-space:pre">           </span>// fill buffer with lrand48 results</div><div><span class="Apple-tab-span" style="white-space:pre">          </span>unsigned char *cp = image->GetBufferPointer();</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>unsigned char *end = cp + (XSize * YSize);</div><div><span class="Apple-tab-span" style="white-space:pre">           </span>for(; cp < end; ++cp)</div><div><span class="Apple-tab-span" style="white-space:pre">                     </span>*cp = lrand48();</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>writer->SetInput(image);</div><div>#else</div><div><span class="Apple-tab-span" style="white-space:pre">              </span>srand48(getpid() + time(NULL));</div><div><span class="Apple-tab-span" style="white-space:pre">              </span>RandomImageSource::Pointer rndSource = RandomImageSource::New();</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>rndSource->SetSize(imageSize);</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>writer->SetInput(rndSource->GetOutput());</div><div>#endif</div><div><span class="Apple-tab-span" style="white-space:pre">         </span>writer->Update();</div><div><span class="Apple-tab-span" style="white-space:pre">         </span>std::cout << i << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>}</div></div><div><br></div></div>