Difference between revisions of "Function:FocusStack"

From CUVI Wiki
(11 intermediate revisions by the same user not shown)
Line 3: Line 3:
===Function===
===Function===
{|
{|
|style="font-size:150%;"|
<pre style="background-color:#f7f7f7; color:#2f3337;">
<syntaxhighlight lang="cpp">
CuviStatus focusStack(const CuviImage* ImgArr, const int numImages, CuviImage& sharpImage, CuviFilter denoiseFilter, const CuviStream& stream = CuviStream());
CuviStatus focusResize(const CuviImage* ImgArr,
</pre>
                  const int numImages
                  CuviImage& sharpImage,
                  CuviFilter denoiseFilter
                  const CuviStream& stream = CuviStream());
</syntaxhighlight>
|}
|}


===Parameters===
===Parameters===


{|class="wikitable"
{|class="wikitable" style="background-color:#D4F4B4;"
|-
|-
! Name
! Name
Line 46: Line 40:
===Image Type Support===
===Image Type Support===


{| class="wikitable"
{|class="wikitable" style="background-color:#C1E6F5;"
|-
|-
! Input
! Input
Line 61: Line 55:
{|
{|
|-
|-
|[[File:Resizein1.jpg|frame|Input Image (Width = W, Height = H)]]
|[[File:Fs-in-1.jpg|frame| Input image with foreground focused]]
|[[File:Resizeout1.jpg|frame| Resized Image (width =0.78625*W, height= 0.78625*H)]]
|-
|[[File:Fs-in-2.jpg|frame| Input image with background focused]]
|-
|-
|[[File:Resizein2.jpg|frame|Input Image (Width = W, Height = H)]]
|[[File:Focused.jpg|frame| Focus-Stacked Image]]
|[[File:Resizeout2.jpg|frame| Resized Image (width = 1.2*W, height= 1.75*H)]]
 
|}
|}


===Example===
{|
<pre style="background-color:#f7f7f7; color:#2f3337;">


std::string path = "D:/dataset/fs/imageFolder/";
std::string result = "D:/dataset/fs/focused.png";


===Example===
{|
|style="font-size:150%;"|
<syntaxhighlight lang="cpp">


CuviImage gimg = cuvi::io::loadImage(path);
for (const auto& entry : fs::directory_iterator(path))
{
if (entry.path().has_extension() && isSupportedExtension(entry.path().extension().string()))
vec.push_back(entry.path().string());
}


const Cuvi32f xScale = 0.5f, yScale = 0.7f;
int numImages = vec.size();
vector<CuviImage> ImgArr(numImages);
//Sort filesnames to read in order. THIS IS VERY IMPORTANT FOR FOCUS STACKING
sort(vec.begin(), vec.end(), lessFirst);


const Cuvi32s newWidth = static_cast<Cuvi32s>(gimg.width() * xScale);
for (int i = 0; i < numImages; i++)
const Cuvi32s newHeight = static_cast<Cuvi32s>(gimg.height() * yScale);
{
ImgArr[i].create(vec[i], CUVI_LOAD_IMAGE_COLOR_KEEP_DEPTH);
cout << vec[i]<< std::endl;
}


CuviImage gout(newWidth,newHeight,gimg.type());


CuviImage focusImage;
CuviFilter denoiseFilter = CuviSpecialFilters::gaussian(CuviSize(11, 11), 15.0f);
cuvi::computerVision::focusStack(ImgArr.data(), numImages, focusImage, denoiseFilter);


//Re-sizing input image to fit output container using bicubic interpolation
printf("\nSaving to disk..");
cuvi::geometryTransforms::resize(gimg,gout, CUVI_INTER_CUBIC);
cuvi::io::saveImage(focusImage, result);


</syntaxhighlight>
</pre>
|}
|}

Revision as of 21:11, 3 January 2022

Stacks multiple images into a single image. Images need to be aligned.

Function

CuviStatus focusStack(const CuviImage* ImgArr, const int numImages, CuviImage& sharpImage, CuviFilter denoiseFilter, const CuviStream& stream = CuviStream());

Parameters

Name Type Description
ImgArr const CuviImage* Input images array
numImages const int Number of images
sharpImage CuviImage& Resultant image
denoiseFilter CuviFilter Filter to remove noise
stream const CuviStream& GPU stream ID for execution

Image Type Support

Input Output
8uC3 x N 8uC3
16uC3 x N 16uC3

Samples

Input image with foreground focused
Input image with background focused
Focus-Stacked Image

Example


std::string path = "D:/dataset/fs/imageFolder/";
std::string result = "D:/dataset/fs/focused.png";


for (const auto& entry : fs::directory_iterator(path))
	{
		if (entry.path().has_extension() && isSupportedExtension(entry.path().extension().string()))
			vec.push_back(entry.path().string());
	}

int numImages = vec.size();
vector<CuviImage> ImgArr(numImages);
//Sort filesnames to read in order. THIS IS VERY IMPORTANT FOR FOCUS STACKING
sort(vec.begin(), vec.end(), lessFirst);

for (int i = 0; i < numImages; i++)
	{
		ImgArr[i].create(vec[i], CUVI_LOAD_IMAGE_COLOR_KEEP_DEPTH);
		cout << vec[i]<< std::endl;
	}


CuviImage focusImage;
CuviFilter denoiseFilter = CuviSpecialFilters::gaussian(CuviSize(11, 11), 15.0f);
cuvi::computerVision::focusStack(ImgArr.data(), numImages, focusImage, denoiseFilter);

printf("\nSaving to disk..");
cuvi::io::saveImage(focusImage, result);