Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change randomValue function to provide reaching of maximum value. #565

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Performance_Test
{
PenguinV_Image::Image uniformImage( uint32_t width, uint32_t height )
{
return uniformImage( width, height, randomValue<uint8_t>( 256 ) );
return uniformImage( width, height, randomValue<uint8_t>( 255 ) );
}

PenguinV_Image::Image uniformImage( uint32_t width, uint32_t height, uint8_t value )
Expand Down
2 changes: 1 addition & 1 deletion test/performance_tests/performance_test_blob_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace
{
Performance_Test::TimerContainer timer;

PenguinV_Image::Image image = Performance_Test::uniformImage( Performance_Test::randomValue<uint8_t>( 1, 256 ), size, size );
PenguinV_Image::Image image = Performance_Test::uniformImage( Performance_Test::randomValue<uint8_t>( 1, 255 ), size, size );

for( uint32_t i = 0; i < Performance_Test::runCount(); ++i ) {
timer.start();
Expand Down
2 changes: 1 addition & 1 deletion test/performance_tests/performance_test_filtering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace
{
Performance_Test::TimerContainer timer;

PenguinV_Image::Image input = Performance_Test::uniformImage( Performance_Test::randomValue<uint8_t>( 1, 256 ), size, size );
PenguinV_Image::Image input = Performance_Test::uniformImage( Performance_Test::randomValue<uint8_t>( 1, 255 ), size, size );
PenguinV_Image::Image output( input.width(), input.height() );

for( uint32_t i = 0; i < Performance_Test::runCount(); ++i ) {
Expand Down
8 changes: 4 additions & 4 deletions test/performance_tests/performance_test_image_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace Function_Template
std::pair < double, double > template_Fill( FillForm1 Fill, const std::string & namespaceName, uint32_t size )
{
PenguinV_Image::Image image = Performance_Test::uniformImage( size, size );
uint8_t value = Performance_Test::randomValue<uint8_t>( 256 );
uint8_t value = Performance_Test::randomValue<uint8_t>( 255 );

TEST_FUNCTION_LOOP( Fill( image, value ), namespaceName )
}
Expand Down Expand Up @@ -239,16 +239,16 @@ namespace Function_Template
std::pair < double, double > template_Threshold( ThresholdForm2 Threshold, const std::string & namespaceName, uint32_t size )
{
std::vector < PenguinV_Image::Image > image = Performance_Test::uniformImages( 2, size, size );
uint8_t threshold = Performance_Test::randomValue<uint8_t>( 256 );
uint8_t threshold = Performance_Test::randomValue<uint8_t>( 255 );

TEST_FUNCTION_LOOP( Threshold( image[0], image[1], threshold ), namespaceName )
}

std::pair < double, double > template_ThresholdDouble( ThresholdDoubleForm2 Threshold, const std::string & namespaceName, uint32_t size )
{
std::vector < PenguinV_Image::Image > image = Performance_Test::uniformImages( 2, size, size );
uint8_t minThreshold = Performance_Test::randomValue<uint8_t>( 256 );
uint8_t maxThreshold = Performance_Test::randomValue<uint8_t>( minThreshold, 256 );
uint8_t minThreshold = Performance_Test::randomValue<uint8_t>( 255 );
uint8_t maxThreshold = Performance_Test::randomValue<uint8_t>( minThreshold, 255 );

TEST_FUNCTION_LOOP( Threshold( image[0], image[1], minThreshold, maxThreshold ), namespaceName )
}
Expand Down
14 changes: 7 additions & 7 deletions test/test_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace
const uint8_t * outXEnd = outX + width;

for( ; outX != outXEnd; ++outX )
(*outX) = Test_Helper::randomValue<uint8_t>( 256 );
( *outX ) = Test_Helper::randomValue<uint8_t>( 255 );
}
}

Expand All @@ -45,7 +45,7 @@ namespace Test_Helper
{
PenguinV_Image::Image uniformImage( uint32_t width, uint32_t height, const PenguinV_Image::Image & reference )
{
return uniformImage( randomValue<uint8_t>( 256 ), width, height, reference );
return uniformImage( randomValue<uint8_t>( 255 ), width, height, reference );
}

PenguinV_Image::Image uniformImage( uint8_t value, uint32_t width, uint32_t height, const PenguinV_Image::Image & reference )
Expand All @@ -60,7 +60,7 @@ namespace Test_Helper

PenguinV_Image::Image uniformRGBImage( const PenguinV_Image::Image & reference )
{
return uniformRGBImage( randomValue<uint8_t>( 256 ), reference );
return uniformRGBImage( randomValue<uint8_t>( 255 ), reference );
}

PenguinV_Image::Image uniformRGBImage( uint8_t value, const PenguinV_Image::Image & reference )
Expand All @@ -70,7 +70,7 @@ namespace Test_Helper

PenguinV_Image::Image uniformRGBImage( uint32_t width, uint32_t height )
{
return uniformRGBImage( width, height, randomValue<uint8_t>( 256 ) );
return uniformRGBImage( width, height, randomValue<uint8_t>( 255 ) );
}

PenguinV_Image::Image uniformRGBImage( uint32_t width, uint32_t height, uint8_t value )
Expand All @@ -80,7 +80,7 @@ namespace Test_Helper

PenguinV_Image::Image uniformRGBAImage( uint32_t width, uint32_t height )
{
return uniformRGBAImage( width, height, randomValue<uint8_t>( 256 ) );
return uniformRGBAImage( width, height, randomValue<uint8_t>( 255 ) );
}

PenguinV_Image::Image uniformRGBAImage( uint32_t width, uint32_t height, uint8_t value )
Expand All @@ -90,7 +90,7 @@ namespace Test_Helper

PenguinV_Image::Image uniformRGBAImage( const PenguinV_Image::Image & reference )
{
return uniformRGBAImage( randomValue<uint8_t>( 256 ), reference );
return uniformRGBAImage( randomValue<uint8_t>( 255 ), reference );
}

PenguinV_Image::Image uniformRGBAImage( uint8_t value, const PenguinV_Image::Image & reference )
Expand Down Expand Up @@ -125,7 +125,7 @@ namespace Test_Helper

std::vector<uint8_t> intesity( images );
for( size_t i = 0u; i < intesity.size(); ++i )
intesity[i] = randomValue<uint8_t>( 256 );
intesity[i] = randomValue<uint8_t>( 255 );

return uniformImages( intesity, reference );
}
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Test_Helper
if( maximum == 0 )
return 0;
else
return static_cast<data>(static_cast<uint32_t>(rand()) % maximum);
return static_cast<data>( static_cast<uint32_t>( rand() ) % ( maximum + 1 ) );
}

template <typename data>
Expand All @@ -47,7 +47,7 @@ namespace Test_Helper
return 0;
}
else {
data value = static_cast<data>(static_cast<uint32_t>(rand()) % maximum);
data value = static_cast<data>( static_cast<uint32_t>( rand() ) % ( maximum + 1 ) );

if( value < minimum )
value = minimum;
Expand Down
20 changes: 10 additions & 10 deletions test/unit_tests/cuda/unit_test_image_function_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ namespace image_function_cuda
const std::vector < uint8_t > intensity = intensityArray( 2 );
PenguinV_Image::Image input = uniformImage( intensity[0], 0, 0, reference );

const bool horizontalFlip = (randomValue<uint32_t>( 0, 2 ) == 0);
const bool verticalFlip = (randomValue<uint32_t>( 0, 2 ) == 0);
const bool horizontalFlip = ( randomValue<uint32_t>( 0, 1 ) == 0 );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create randomBoolValue() function instead. No harm to do this but it makes code easier to read.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this function we could use rand() directly, no need to call randomValue<> function

const bool verticalFlip = ( randomValue<uint32_t>( 0, 1 ) == 0 );
const uint32_t xCorrection = input.width() % 2;
const uint32_t yCorrection = input.height() % 2;

Expand Down Expand Up @@ -249,8 +249,8 @@ namespace image_function_cuda
const uint8_t intensityFill = intensityValue();
std::vector < PenguinV_Image::Image > input = uniformImages( intensity, reference );

const bool horizontalFlip = (randomValue<uint32_t>( 0, 2 ) == 0);
const bool verticalFlip = (randomValue<uint32_t>( 0, 2 ) == 0);
const bool horizontalFlip = ( randomValue<uint32_t>( 0, 1 ) == 0 );
const bool verticalFlip = ( randomValue<uint32_t>( 0, 1 ) == 0 );
const uint32_t xCorrection = input[0].width() % 2;
const uint32_t yCorrection = input[0].height() % 2;

Expand Down Expand Up @@ -291,8 +291,8 @@ namespace image_function_cuda
uint32_t roiX, roiY, roiWidth, roiHeight;
generateRoi( input, roiX, roiY, roiWidth, roiHeight );

const bool horizontalFlip = (randomValue<uint32_t>( 0, 2 ) == 0);
const bool verticalFlip = (randomValue<uint32_t>( 0, 2 ) == 0);
const bool horizontalFlip = ( randomValue<uint32_t>( 0, 1 ) == 0 );
const bool verticalFlip = ( randomValue<uint32_t>( 0, 1 ) == 0 );
const uint32_t xCorrection = roiWidth % 2;
const uint32_t yCorrection = roiHeight % 2;

Expand Down Expand Up @@ -337,8 +337,8 @@ namespace image_function_cuda
uint32_t roiWidth, roiHeight;
generateRoi( image, roiX, roiY, roiWidth, roiHeight );

const bool horizontalFlip = (randomValue<uint32_t>( 0, 2 ) == 0);
const bool verticalFlip = (randomValue<uint32_t>( 0, 2 ) == 0);
const bool horizontalFlip = ( randomValue<uint32_t>( 0, 1 ) == 0 );
const bool verticalFlip = ( randomValue<uint32_t>( 0, 1 ) == 0 );
const uint32_t xCorrection = roiWidth % 2;
const uint32_t yCorrection = roiHeight % 2;

Expand Down Expand Up @@ -617,8 +617,8 @@ namespace image_function_cuda
std::vector<uint32_t> Y( X.size() );

for ( size_t j = 0; j < X.size(); ++j ) {
X[j] = randomValue<uint32_t>( 0, image.width() );
Y[j] = randomValue<uint32_t>( 0, image.height() );
X[j] = randomValue<uint32_t>( 0, image.width() - 1 );
Y[j] = randomValue<uint32_t>( 0, image.height() - 1 );
}

Image_Function_Cuda::SetPixel( image, X, Y, intensity[1] );
Expand Down
2 changes: 1 addition & 1 deletion test/unit_tests/unit_test_blob_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace blob_detection
uint32_t roiWidth, roiHeight;
Unit_Test::generateRoi( image, roiX, roiY, roiWidth, roiHeight );

Unit_Test::fillImage( image, roiX, roiY, roiWidth, roiHeight, Unit_Test::randomValue<uint8_t>( 1, 256 ) );
Unit_Test::fillImage( image, roiX, roiY, roiWidth, roiHeight, Unit_Test::randomValue<uint8_t>( 1, 255 ) );

Blob_Detection::BlobDetection detection;
detection.find( image );
Expand Down
4 changes: 2 additions & 2 deletions test/unit_tests/unit_test_edge_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace edge_detection
if ( !isValidLeftEdge && !isValidRightEdge )
continue;

Unit_Test::fillImage( image, roiX, roiY, roiWidth, roiHeight, Unit_Test::randomValue<uint8_t>( 64, 256 ) );
Unit_Test::fillImage( image, roiX, roiY, roiWidth, roiHeight, Unit_Test::randomValue<uint8_t>( 64, 255 ) );

EdgeDetectionBase<_Type> edgeDetection;
edgeDetection.find( image, EdgeParameter( EdgeParameter::LEFT_TO_RIGHT) );
Expand Down Expand Up @@ -63,7 +63,7 @@ namespace edge_detection
if ( !isValidTopEdge && !isValidBottomEdge )
continue;

Unit_Test::fillImage( image, roiX, roiY, roiWidth, roiHeight, Unit_Test::randomValue<uint8_t>( 64, 256 ) );
Unit_Test::fillImage( image, roiX, roiY, roiWidth, roiHeight, Unit_Test::randomValue<uint8_t>( 64, 255 ) );

EdgeDetectionBase<_Type> edgeDetection;
edgeDetection.find( image, EdgeParameter( EdgeParameter::TOP_TO_BOTTOM) );
Expand Down
2 changes: 1 addition & 1 deletion test/unit_tests/unit_test_fft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace fft
bool RandomImageFFT()
{
for ( uint32_t i = 0u; i < 32u; ++i ) { // a special case for FFT because it take a lot of time for execution
const uint32_t dimension = (2u << Unit_Test::randomValue<uint8_t>( 11 ));
const uint32_t dimension = ( 2u << Unit_Test::randomValue<uint8_t>( 10 ) );

const PenguinV_Image::Image input = Unit_Test::randomImage( dimension, dimension );

Expand Down
4 changes: 2 additions & 2 deletions test/unit_tests/unit_test_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ namespace Unit_Test
maximumHeight = im->second;
}

width = randomValue<uint32_t>( 1, maximumWidth + 1 );
height = randomValue<uint32_t>( 1, maximumHeight + 1 );
width = randomValue<uint32_t>( 1, maximumWidth );
height = randomValue<uint32_t>( 1, maximumHeight );

x.resize( imageSize.size() );
y.resize( imageSize.size() );
Expand Down
4 changes: 2 additions & 2 deletions test/unit_tests/unit_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ namespace Unit_Test
template <typename _Type>
void generateRoi( const PenguinV_Image::ImageTemplate<_Type> & image, uint32_t & x, uint32_t & y, uint32_t & width, uint32_t & height )
{
width = randomValue<uint32_t>( 1, image.width() + 1 );
height = randomValue<uint32_t>( 1, image.height() + 1 );
width = randomValue<uint32_t>( 1, image.width() );
height = randomValue<uint32_t>( 1, image.height() );

x = randomValue<uint32_t>( image.width() - width );
y = randomValue<uint32_t>( image.height() - height );
Expand Down
12 changes: 6 additions & 6 deletions test/unit_tests/unit_test_image_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace template_image
for( uint32_t i = 0; i < Unit_Test::runCount(); ++i ) {
const uint32_t width = Unit_Test::randomValue<uint32_t>( 2048 );
const uint32_t height = Unit_Test::randomValue<uint32_t>( 2048 );
const uint8_t colorCount = Unit_Test::randomValue<uint8_t >( 1, 4 );
const uint8_t colorCount = Unit_Test::randomValue<uint8_t >( 1, 3 );
const uint8_t alignment = Unit_Test::randomValue<uint8_t >( 1, 32 );

if( !Unit_Test::equalSize( PenguinV_Image::ImageTemplate < uint8_t >( width, height, colorCount, alignment ), width, height,
Expand All @@ -32,7 +32,7 @@ namespace template_image
PenguinV_Image::ImageTemplate < uint8_t > image;

uint8_t fakeArray[1];
uint8_t fakeValue = Unit_Test::randomValue<uint8_t>( 2 );
uint8_t fakeValue = Unit_Test::randomValue<uint8_t>( 1 );
if( fakeValue == 1 )
fakeValue = 0;

Expand All @@ -51,11 +51,11 @@ namespace template_image
for( uint32_t i = 0; i < Unit_Test::runCount(); ++i ) {
const uint32_t width = Unit_Test::randomValue<uint32_t>( 1024 );
const uint32_t height = Unit_Test::randomValue<uint32_t>( 1024 );
const uint8_t colorCount = Unit_Test::randomValue<uint8_t >( 1, 4 );
const uint8_t colorCount = Unit_Test::randomValue<uint8_t >( 1, 3 );
const uint8_t alignment = Unit_Test::randomValue<uint8_t >( 1, 32 );

PenguinV_Image::ImageTemplate < _Type > image( width, height, colorCount, alignment );
image.fill( static_cast<_Type>( Unit_Test::randomValue<uint8_t>( 256u ) ) );
image.fill( static_cast<_Type>( Unit_Test::randomValue<uint8_t>( 255u ) ) );

const PenguinV_Image::ImageTemplate < _Type > image_copy( image );

Expand All @@ -72,11 +72,11 @@ namespace template_image
for( uint32_t i = 0; i < Unit_Test::runCount(); ++i ) {
const uint32_t width = Unit_Test::randomValue<uint32_t>( 1024 );
const uint32_t height = Unit_Test::randomValue<uint32_t>( 1024 );
const uint8_t colorCount = Unit_Test::randomValue<uint8_t >( 1, 4 );
const uint8_t colorCount = Unit_Test::randomValue<uint8_t >( 1, 3 );
const uint8_t alignment = Unit_Test::randomValue<uint8_t >( 1, 32 );

PenguinV_Image::ImageTemplate < _Type > image( width, height, colorCount, alignment );
image.fill( static_cast<_Type>( Unit_Test::randomValue<uint8_t>( 256u ) ) );
image.fill( static_cast<_Type>( Unit_Test::randomValue<uint8_t>( 255u ) ) );

PenguinV_Image::ImageTemplate < _Type > image_copy;

Expand Down
Loading