Skip to content
Merged
Binary file added AIDevGallery/Assets/horse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions AIDevGallery/Samples/Definitions/WcrApis/WcrApiCodeSnippet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,28 @@ internal static class WcrApiCodeSnippet
}
""""
},
{
ModelType.ForegroundExtractor, """"
using Microsoft.Windows.AI;
using Microsoft.Windows.AI.Imaging;
using Windows.Graphics;
using Windows.Graphics.Imaging;

var readyState = ImageForegroundExtractor.GetReadyState();
if (readyState is AIFeatureReadyState.Ready or AIFeatureReadyState.NotReady)
{
if (readyState == AIFeatureReadyState.NotReady)
{
var op = await ImageForegroundExtractor.EnsureReadyAsync();
}

ImageForegroundExtractor imageForegroundExtractor = await ImageForegroundExtractor.CreateAsync();

SoftwareBitmap mask = imageForegroundExtractor.GetMaskFromSoftwareBitmap(inputBitmap);
SoftwareBitmap finalBitmap = ApplyMask(inputBitmap, mask);
}
""""
},
{
ModelType.ObjectRemover, """"
using Microsoft.Windows.AI.Imaging;
Expand Down
6 changes: 6 additions & 0 deletions AIDevGallery/Samples/Definitions/WcrApis/WcrApiHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ internal static class WcrApiHelpers
{
ModelType.BackgroundRemover, ImageObjectExtractor.GetReadyState
},
{
ModelType.ForegroundExtractor, ImageForegroundExtractor.GetReadyState
},
{
ModelType.ImageDescription, ImageDescriptionGenerator.GetReadyState
},
Expand Down Expand Up @@ -75,6 +78,9 @@ internal static class WcrApiHelpers
{
ModelType.BackgroundRemover, ImageObjectExtractor.EnsureReadyAsync
},
{
ModelType.ForegroundExtractor, ImageForegroundExtractor.EnsureReadyAsync
},
{
ModelType.ObjectRemover, ImageObjectRemover.EnsureReadyAsync
},
Expand Down
14 changes: 13 additions & 1 deletion AIDevGallery/Samples/Definitions/WcrApis/apis.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,19 @@
"Description": "Remove the background from an image.",
"ReadmeUrl": "https://github.com/MicrosoftDocs/windows-ai-docs/blob/docs/docs/apis/imaging.md",
"License": "ms-pl",
"SampleIdToShowInDocs": "79eca6f0-3092-4b6f-9a81-94a2aff22559"
"SampleIdToShowInDocs": "79eca6f0-3092-4b6f-9a81-94a2aff22559",
"Category": "Image Segmentation"
},
"ForegroundExtractor": {
"Id": "9d445930-b353-429a-9674-777eef771ccf",
"Name": "Foreground Extractor",
"Icon": "WCRAPI.svg",
"IconGlyph": "\uE7C5",
"Description": "Remove the foreground from an image.",
"ReadmeUrl": "https://github.com/MicrosoftDocs/windows-ai-docs/blob/docs/docs/apis/imaging.md",
"License": "ms-pl",
"SampleIdToShowInDocs": "877ff911-19c9-400b-8f60-83fb8e808c20",
"Category": "Image Segmentation"
},
"ImageDescription": {
"Id": "bdab049c-9b01-48f4-b12d-acb911b0a61c",
Expand Down
73 changes: 73 additions & 0 deletions AIDevGallery/Samples/WCRAPIs/ForegroundExtractor.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8" ?>
<samples:BaseSamplePage
x:Class="AIDevGallery.Samples.WCRAPIs.ForegroundExtractor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:samples="using:AIDevGallery.Samples"
mc:Ignorable="d">
<Grid ColumnSpacing="12" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image x:Name="InputImage"
Grid.Column="0"
Stretch="Uniform"
MaxHeight="400"
HorizontalAlignment="Left"
VerticalAlignment="Top"/>
<StackPanel Grid.Column="0" Margin="8" HorizontalAlignment="Right"
VerticalAlignment="Top"
Background="{ThemeResource AcrylicBackgroundFillColorDefaultBrush}"
CornerRadius="{StaticResource ControlCornerRadius}">
<DropDownButton Padding="8"
HorizontalAlignment="Right"
VerticalAlignment="Top"
AutomationProperties.Name="Select image"
ToolTipService.ToolTip="Select image">
<DropDownButton.Flyout>
<MenuFlyout Placement="Bottom">
<MenuFlyoutItem Click="LoadImage_Click" Text="From file" />
<MenuFlyoutItem Click="PasteImage_Click" Text="From clipboard" />
</MenuFlyout>
</DropDownButton.Flyout>
<FontIcon FontSize="16" Glyph="&#xEE71;" />
</DropDownButton>
</StackPanel>
<Image x:Name="GeneratedImage"
Grid.Column="1"
AutomationProperties.LiveSetting="Assertive"
AutomationProperties.Name="Output"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Stretch="Uniform"
MaxHeight="400"/>
<StackPanel
Margin="12"
Padding="8"
Grid.Column="1"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Background="{ThemeResource AcrylicBackgroundFillColorDefaultBrush}"
CornerRadius="{StaticResource ControlCornerRadius}"
Orientation="Horizontal"
Spacing="8">
<Button x:Name="CopyButton"
AutomationProperties.Name="Copy Image to the Clipboard"
Click="Copy_Click"
ToolTipService.ToolTip="Copy Image to the Clipboard"
Visibility="Visible">
<FontIcon FontSize="16" Glyph="&#xE8C8;" />
</Button>
<Button
x:Name="SaveButton"
Click="Save_Click"
ToolTipService.ToolTip="Save Image"
Visibility="Visible">
<FontIcon FontSize="16" Glyph="&#xEE71;" />
</Button>
</StackPanel>
</Grid>
</samples:BaseSamplePage>
Loading
Loading