{"id":449,"date":"2023-03-23T08:17:33","date_gmt":"2023-03-23T13:17:33","guid":{"rendered":"https:\/\/davidwdrell.net\/wordpress\/?p=449"},"modified":"2023-05-22T06:04:58","modified_gmt":"2023-05-22T11:04:58","slug":"example-implementation-of-nppiresize_32f_c1r_ctx","status":"publish","type":"post","link":"https:\/\/davidwdrell.net\/wordpress\/?p=449","title":{"rendered":"Example implementation of nppiResize_32f_C1R_Ctx()"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Project Source Code<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The project source can be found here:   <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/daviddrell\/image_proc_samples\">https:\/\/github.com\/daviddrell\/image_proc_samples<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The project structure is Visual Studio 2019 with Cuda 11.7 installed. If you are using a different version of Cuda, I find the easiest was to solve this is to edit the Visual Studio project file in a text editor and change the version number there.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is an example of re-scaling the size of the image in gray-scale floating point format accelerated using cuda on a GPU.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This example creates a simulated image of 2048&#215;2048. In actual image processing applications you will have an image that comes from a jpeg or tiff file and must be decoded, often into an array of RGB bytes or directly into a gray-scale format. Many image processing operations occur on a gray-scale version of the image encoded as floating point, typically of values 0 to 1, or -1 to +1.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">NVIDIA cuda comes with a library of basic image processing functions which are accelerated with parallel operations on the GPU, that run on top of the cuda library.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One of these functions is nppiResize_32f_C1R_Ctx().  The file resize.cpp implements all the memory operations necessary to resize an image using nppiResize_32f_C1R_Ctx().<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The file resize.h provides a simple entry point for an image resize function which can be called from a c program with no knowledge of cuda programming.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code Details<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Refer to the gitlab project link. The sample entry point from a c programing perspective is given in main.cu. The example implementation of nppiResize_32f_C1R_Ctx() is given in resize.cpp.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sample Results<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In a machine learning application, I needed to analyze a biological image (cells growing into vessel structures imaged under a microscope). The scientist provided images that were sized at 5995 x 6207 pixels.  This size is too extreme for the requirements of extracting the structures. Additionally, the AI models were trained on images typically in the range of 1000&#215;1000 to 2000&#215;2000 pixels. So I scale down the images using the resize_Cuda() function demonstrated in the example project.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the original image that is too large:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/video_000001-scaled.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"989\" height=\"1024\" src=\"https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/video_000001-989x1024.jpg\" alt=\"\" class=\"wp-image-459\" srcset=\"https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/video_000001-989x1024.jpg 989w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/video_000001-290x300.jpg 290w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/video_000001-768x795.jpg 768w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/video_000001-1484x1536.jpg 1484w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/video_000001-1978x2048.jpg 1978w\" sizes=\"auto, (max-width: 989px) 100vw, 989px\" \/><\/a><figcaption class=\"wp-element-caption\">Original Image at 5995 x 6207 pixels.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the downsized image at 2000 x 2070 (the width was set to be 2000, our max AI trained size, the height was calculated to be 2070 to maintain the aspect ratio):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/debug_scaled_000000.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"989\" height=\"1024\" src=\"https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/debug_scaled_000000-989x1024.jpg\" alt=\"\" class=\"wp-image-460\" srcset=\"https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/debug_scaled_000000-989x1024.jpg 989w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/debug_scaled_000000-290x300.jpg 290w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/debug_scaled_000000-768x795.jpg 768w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/debug_scaled_000000-1484x1536.jpg 1484w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/debug_scaled_000000-1979x2048.jpg 1979w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/debug_scaled_000000.jpg 2000w\" sizes=\"auto, (max-width: 989px) 100vw, 989px\" \/><\/a><figcaption class=\"wp-element-caption\">downsized image at 2000 x 2070 pixels<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the result of the analysis showing the branches and loops detected:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/final.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1022\" src=\"https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/final-1024x1022.jpg\" alt=\"\" class=\"wp-image-461\" srcset=\"https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/final-1024x1022.jpg 1024w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/final-300x300.jpg 300w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/final-150x150.jpg 150w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/final-768x766.jpg 768w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/final-1536x1532.jpg 1536w, https:\/\/davidwdrell.net\/wordpress\/wp-content\/uploads\/2023\/03\/final.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\"> final analysis output<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Project Source Code The project source can be found here: https:\/\/github.com\/daviddrell\/image_proc_samples The project structure is Visual Studio 2019 with Cuda [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[8],"tags":[7],"class_list":["post-449","post","type-post","status-publish","format-standard","hentry","category-cuda","tag-cuda"],"_links":{"self":[{"href":"https:\/\/davidwdrell.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davidwdrell.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davidwdrell.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davidwdrell.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davidwdrell.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=449"}],"version-history":[{"count":10,"href":"https:\/\/davidwdrell.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/449\/revisions"}],"predecessor-version":[{"id":499,"href":"https:\/\/davidwdrell.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/449\/revisions\/499"}],"wp:attachment":[{"href":"https:\/\/davidwdrell.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davidwdrell.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davidwdrell.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}