Difference between revisions of "Function:FocusStack"

From CUVI Wiki
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
Stacks multiple images into a single image. Images need to be aligned.
Stacks multiple images into a single, all focused image. The input images need to be aligned and in order. The function also returns a depth_info image that contains the information against each pixel where it was picked from the stack.  
===Function===
===Function===
{|
{|
|style="font-size:100%;"|
|style="font-size:100%;"|
<syntaxhighlight lang="C">
<syntaxhighlight lang="C">
CuviStatus focusStack(const CuviImage* ImgArr, const int numImages, CuviImage& sharpImage, CuviFilter denoiseFilter, const CuviStream& stream = CuviStream());
CUVI_EXPORTS CuviStatus focusStack(CuviImage* images, const int numImages, CuviImage& stack, CuviImage& depth_info, const CuviFilter denoiseFilter, const CuviStream& stream);
</syntaxhighlight>
</syntaxhighlight>
|}
|}
Line 18: Line 18:
! Description
! Description
|-
|-
| ImgArr
| images
| const CuviImage*
| const CuviImage*
| Input images array
| Input images array
Line 26: Line 26:
| Number of images  
| Number of images  
|-
|-
| sharpImage
| stack
| CuviImage&
| CuviImage&
| Resultant image
| Resultant image
|-
| depth_info
| CuviImage&
| Slice/Depth information against stacked image
|-
|-
| denoiseFilter
| denoiseFilter
Line 40: Line 44:
|}
|}


===Image Type Support===
====Image Type Support====
 
{|
{|class="wikitable" style="background-color:#C1E6F5;"
|style="font-size:75%;"|
{|class="wikitable"
|-
|-
! Input
! Input
Line 52: Line 57:
| 16uC3 x N
| 16uC3 x N
| 16uC3
| 16uC3
|}
|}
|}


===Samples===
====Samples====
{|
[[File:Fs-in-1.jpg|none|frame| Input image with foreground focused]]
|-
<br/>
|[[File:Fs-in-1.jpg|frame| Input image with foreground focused]]
[[File:Fs-in-2.jpg|none|frame| Input image with background focused]]
|-
<br/>
|[[File:Fs-in-2.jpg|frame| Input image with background focused]]
[[File:Focused.jpg|none|frame| Focus-Stacked Image]]
|-
<br/>
|[[File:Focused.jpg|frame| Focus-Stacked Image]]
|}


===Example===
====Code Example====
{|
{|
<pre style="background-color:#f7f7f7; color:#2f3337;">
|style="font-size:100%;"|
<syntaxhighlight lang="C">


std::string path = "D:/dataset/fs/imageFolder/";
std::string path = "D:/dataset/fs/imageFolder/";
Line 90: Line 95:




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


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


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

Latest revision as of 08:53, 18 November 2024

Stacks multiple images into a single, all focused image. The input images need to be aligned and in order. The function also returns a depth_info image that contains the information against each pixel where it was picked from the stack.

Function

CUVI_EXPORTS CuviStatus focusStack(CuviImage* images, const int numImages, CuviImage& stack, CuviImage& depth_info, const CuviFilter denoiseFilter, const CuviStream& stream);

Parameters

Name Type Description
images const CuviImage* Input images array
numImages const int Number of images
stack CuviImage& Resultant image
depth_info CuviImage& Slice/Depth information against stacked 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


Code 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, slice_info;
CuviFilter denoiseFilter = CuviSpecialFilters::gaussian(CuviSize(11, 11), 15.0f);
cuvi::computerVision::focusStack(ImgArr.data(), numImages, focusImage, slice_info, denoiseFilter);

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