Hello, I’m using NPP for image processing. Today when I use nppiMinIndx_32f_C1R(). I get the min value from a row and let the whole row subtract the min value. The min value is invalid which leads to the error in nppiSubC_32f_C1R. I work on that for copule of hours but still cannot solve it. Can anyone help me?
Here is my code:
Update: Sorry for the error in the code, the code has been updated now.
#include “device_launch_parameters.h”
#include <stdio.h>
#include <windows.h>
#include<cuda_runtime.h>
#include<nppi.h>
#include<npp.h>
#include
//#include <Exceptions.h>
#include <nppi_morphological_operations.h>
#include <string.h>
#include
#include <helper_string.h>
#include<helper_cuda.h>
#include<ImageIO.h>
#include<ImagesNPP.h>
#include<ImagesCPU.h>
void main()
{
try
{
//cudaDeviceInit(argc, (const char **)argv);
std::string file_src(".\\test3_corr.jpg");
npp::ImageCPU_8u_C1 Host_Src;
//read image from disk to Cpu
npp::loadImage(file_src, Host_Src);
npp::ImageCPU_8u_C1 Host_Dst(Host_Src.size());
//Copy image from Cpu to Gpu
npp::ImageNPP_8u_C1 Device_Src_8u(Host_Src);
npp::ImageNPP_8u_C1 Device_Dst_8u(Device_Src_8u.size());
npp::ImageNPP_32f_C1 Device_Src_32f(Device_Src_8u.size());
npp::ImageNPP_32f_C1 Device_test_32f(Device_Src_8u.size());
npp::ImageNPP_16u_C1 Device_test_16u(Device_Src_8u.size());
npp::ImageNPP_8u_C1 Device_test_8u(Device_Src_8u.size());
//-----------------------------Nonuniformity_Correction-----------------------------------//
npp::ImageNPP_32f_C1 Device_column_mean(Device_Src_8u.width(), 1);
npp::ImageNPP_32f_C1 Device_column_sub(Device_Src_8u.width(), 1);
NppiSize column_range_size = { (int)Device_column_mean.width(), 1 };
int min_buffer_size;
Npp8u* min_buffer = 0;
Npp32f min_val = 0;
int minx = 0;
int miny = 0;
NppiSize Src_size = { (int)Device_Src_8u.width(), (int)Device_Src_8u.height() };
NppiSize roi_size = { (int)Device_Src_8u.width(), (int)Device_Src_8u.height() };
//-----------------------------Nonuniformity_Correction-----------------------------------//
//------------------------------Declare Over-------------------------//
//-----------------------------Nonuniformity_Correction-----------------------------------//
nppiSumWindowColumn_8u32f_C1R(
Device_Src_8u.data(), Device_Src_8u.pitch(),
Device_column_mean.data(), Device_column_mean.pitch(),
column_range_size, Device_Src_8u.height(), 0);
nppiDivC_32f_C1IR(
Device_Src_8u.height(),
Device_column_mean.data(), Device_column_mean.pitch(),
column_range_size
);
nppiMinIndxGetBufferHostSize_32f_C1R(column_range_size, &min_buffer_size);
cudaMalloc((void**)(&min_buffer), min_buffer_size);
nppiMinIndx_32f_C1R(Device_column_mean.data(), Device_column_mean.pitch(),
column_range_size, min_buffer, &min_val, &minx, &miny);
printf("%.2f", min_val);
printf("%.2f", minx);
printf("%.2f", miny);
printf("%d", sizeof(column_range_size));
system("pause");
auto kkk = nppiSubC_32f_C1R(
Device_column_mean.data(), Device_column_mean.pitch(),
min_val,
Device_column_sub.data(), Device_column_sub.pitch(),
{ (int)Device_column_mean.width(), 1 }
);
system("pause");
Device_column_mean.copyTo(Device_test_32f.data(), Device_test_32f.pitch());
// For test
nppiConvert_32f8u_C1R(
Device_test_32f.data(), Device_test_32f.pitch(),
Device_test_8u.data(), Device_test_8u.pitch(),
roi_size, NPP_RND_FINANCIAL);
Device_test_8u.copyTo(Host_Dst.data(), Host_Dst.pitch());
//Save image
npp::saveImage(".\\test3_test.pgm", Host_Dst);
exit(EXIT_SUCCESS);
// Helper function for using CUDA to add vectors in parallel.
}
catch (npp::Exception &rException)
{
std::cerr << "Program error! The following exception occurred: \n";
std::cerr << rException << std::endl;
std::cerr << "Aborting." << std::endl;
system("pause");
exit(EXIT_FAILURE);
}
catch (...)
{
std::cerr << "Program error! An unknow type of exception occurred. \n";
std::cerr << "Aborting." << std::endl;
system("pause");
exit(EXIT_FAILURE);
//return -1;
}
}