Home Neural Network totally different conduct when sort casting from float to uchar

totally different conduct when sort casting from float to uchar

0
totally different conduct when sort casting from float to uchar

[ad_1]

I’m utilizing dpc++ compiler built-in with microsoft visible studio, I wrote a small app to use a filter to a picture (grey scale), the app will compute the brand new worth of the pixel on the machine and retailer it on new filtered_image_buffer, whereas computing, the worth is float after which will probably be transformed to uchar however the conduct is totally different once I use cpu vs gpu selector, on gpu the filter is utilized accurately and the outcome picture is ok, however in cpu the picture is in chaos.
cpu that I’m utilizing: Intel(R) Core(TM) i7-8665U
gpu: Intel(R) UHD Graphics 620
right here the outcomes for gpu vs cpu (filter to sharpen the picture is used)

NabeelKh_0-1714378957863.pngNabeelKh_1-1714378967550.png

 

code:
“`

#embody <sycl/sycl.hpp>
#embody <iostream>
#embody <opencv2/opencv.hpp>

utilizing namespace sycl;

int most important(int argc, char* argv[]) {
cv::Mat picture = cv::imread(“oneapi1.png”, cv::IMREAD_GRAYSCALE);
if (picture.empty()) {
std::cout << “Couldn’t open or discover the picture” << std::endl;
return -1;
}
std::vector<uchar> imageData;
imageData.assign(picture.information, picture.information + picture.complete());
buffer <uchar, 1> imageBuffer(imageData.information(), vary<1>(picture.complete()));

cv::Mat filteredImage = picture.clone();
std::vector<uchar> filteredImageData;
filteredImageData.assign(filteredImage.information, filteredImage.information + filteredImage.complete() * filteredImage.channels());
cpu_selector selector;
queue q{ selector };
auto top = picture.rows;
auto width = picture.cols;
const int filterHeight = 5;
const int filterWidth = 5;
float filter[filterHeight][filterWidth] = {
{-1, -1, -1, -1, -1,},
{-1, 1.5, 1.5, 1.5, -1},
{-1, 1.5, 5, 1.5, -1},
{-1, 1.5, 1.5, 1.5, -1},
{-1, -1, -1, -1, -1}
};
buffer <float, 2> filterBuf(vary<2>(filterHeight, filterWidth));
{
auto filterBufAcc = filterBuf.get_access<entry::mode::read_write>();
for (int i = 0; i < filterHeight; i++) {
for (int j = 0; j < filterWidth; j++) {
filterBufAcc[i][j] = filter[i][j];
}
}
}

{
buffer <uchar, 1> filteredImageBuffer(filteredImageData.information(), vary<1>(filteredImage.complete() * filteredImage.channels()));
q.submit([&](handler& h) {
auto imageAcc = imageBuffer.get_access<entry::mode::learn>(h);
auto filteredImageAcc = filteredImageBuffer.get_access<>(h);
auto filterAcc = filterBuf.get_access<entry::mode::learn>(h);
h.parallel_for(vary<2>{top – ((filterHeight / 2) * 2), width – ((filterWidth / 2) * 2)}, [=](merchandise<2> id) {
float worth = 0;
auto global_row = id.get_id(0) + (filterHeight / 2);
auto global_column = id.get_id(1) + (filterWidth / 2);
//filter want a particular case for edges, however right here it simply skip them

for (int i = 0; i < filterHeight; i++) {
for (int j = 0; j < filterWidth; j++) {
worth += filterAcc[i][j] * imageAcc[(id.get_id(0) + i) * width + id.get_id(1) + j];
}
}
filteredImageAcc[global_row * width + global_column] = (uchar)(worth);
});
});
q.wait();
}

cv::Mat filteredImageResult(top, width, CV_8UC1, filteredImageData.information());
cv::namedWindow(“filtered Picture”, cv::WINDOW_NORMAL);
cv::imshow(“filtered Picture”, filteredImageResult);
cv::namedWindow(“unique Picture”, cv::WINDOW_NORMAL);
cv::imshow(“unique Picture”, picture);
cv::waitKey(0);

return 0;
}
“`
the unique picture is connected

[ad_2]