[ITK] [ITK-users] RandomImageSource is terrible no good not very random?

Kent Williams nkwmailinglists at gmail.com
Thu Oct 27 12:57:28 EDT 2016


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.

I got better results (without much speed penalty) calling drand48 once per
pixel.

Link to image generated: https://flic.kr/p/Nz1p7w

#include <iostream>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <itkImage.h>
#include <itkImageFileWriter.h>
#include <itkImageRegionIterator.h>
#include <itkRandomImageSource.h>
#include <time.h>
#include <stdlib.h>
typedef itk::Image<unsigned char,2> ImageType;
typedef itk::ImageFileWriter<ImageType> ImageFileWriter;
typedef itk::RandomImageSource<ImageType> RandomImageSource;
typedef itk::ImageRegionIterator<ImageType> Iterator;

// 1080p
//const int XSize(1920);
//const int YSize(1080);
const int XSize(1280);
const int YSize(720);

int main(int argc, char **argv) {


ImageType::SizeType imageSize;
imageSize[0] = XSize;
imageSize[1] = YSize;
// only used for the first GetBufferPointer method
ImageType::Pointer image = ImageType::New();
image->SetRegions(imageSize);
image->Allocate();

ImageFileWriter::Pointer writer = ImageFileWriter::New();
for(unsigned i = 0; i < (60*24); ++i) {
char fname[256];
sprintf(fname,"%04u.tiff", i);
writer->SetFileName(fname);
#if 0
// fill buffer with lrand48 results
unsigned char *cp = image->GetBufferPointer();
unsigned char *end = cp + (XSize * YSize);
for(; cp < end; ++cp)
*cp = lrand48();
writer->SetInput(image);
#else
srand48(getpid() + time(NULL));
RandomImageSource::Pointer rndSource = RandomImageSource::New();
rndSource->SetSize(imageSize);
writer->SetInput(rndSource->GetOutput());
#endif
writer->Update();
std::cout << i << std::endl;
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20161027/6313e8f1/attachment.html>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list