Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nodes] imageProcessing: metadata feature #970

Merged
merged 10 commits into from
Jul 19, 2020
261 changes: 181 additions & 80 deletions meshroom/nodes/aliceVision/ImageProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@

import os.path

def outputImagesValueFunct(attr):
basename = os.path.basename(attr.node.input.value)
fileStem = os.path.splitext(basename)[0]
inputExt = os.path.splitext(basename)[1]
outputExt = ('.' + attr.node.extension.value) if attr.node.extension.value else None

if inputExt in ['.abc', '.sfm']:
# If we have an SfM in input
return desc.Node.internalFolder + '*' + (outputExt or '.*')

if inputExt:
# if we have one or multiple files in input
return desc.Node.internalFolder + fileStem + (outputExt or inputExt)

if '*' in fileStem:
# The fileStem of the input param is a regular expression,
# so even if there is no file extension,
# we consider that the expression represents files.
return desc.Node.internalFolder + fileStem + (outputExt or '.*')

# No extension and no expression means that the input param is a folder path
return desc.Node.internalFolder + '*' + (outputExt or '.*')


class ImageProcessing(desc.CommandLineNode):
commandLine = 'aliceVision_utils_imageProcessing {allParams}'
Expand All @@ -25,8 +48,8 @@ class ImageProcessing(desc.CommandLineNode):
),
desc.ListAttribute(
elementDesc=desc.File(
name="imagesFolder",
label="Images Folder",
name="inputFolder",
label="input Folder",
description="",
value="",
uid=[0],
Expand All @@ -35,6 +58,18 @@ class ImageProcessing(desc.CommandLineNode):
label="Images input Folders",
description='Use images from specific folder(s).',
),
desc.ListAttribute(
elementDesc=desc.StringParam(
name="metadataFolder",
label="Metadata Folder",
description="",
value="",
uid=[0],
),
name="metadataFolders",
label="Metadata input Folders",
description='Use images metadata from specific folder(s).',
),
desc.ChoiceParam(
name='extension',
label='Output File Extension',
Expand Down Expand Up @@ -89,83 +124,149 @@ class ImageProcessing(desc.CommandLineNode):
value=False,
uid=[0],
),
desc.IntParam(
name='sharpenWidth',
label='Sharpen Width',
description='Sharpen Width.',
value=1,
range=(1, 9, 2),
uid=[0],
),
desc.FloatParam(
name='sharpenContrast',
label='Sharpen Contrast',
description='Sharpen Contrast.',
value=1.0,
range=(0.0, 100.0, 0.1),
uid=[0],
),
desc.FloatParam(
name='sharpenThreshold',
label='Sharpen Threshold',
description='Sharpen Threshold.',
value=0.0,
range=(0.0, 1.0, 0.01),
uid=[0],
),
desc.BoolParam(
name='bilateralFilter',
label='Bilateral Filter',
description='Bilateral Filter.',
value=False,
uid=[0],
),
desc.IntParam(
name='bilateralFilterDistance',
label='Bilateral Filter Distance',
description='Diameter of each pixel neighborhood that is used during bilateral filtering.\nCould be very slow for large filters, so it is recommended to use 5.',
value=0,
range=(0, 9, 1),
uid=[0],
),
desc.FloatParam(
name='bilateralFilterSigmaSpace',
label='Bilateral Filter Sigma Space',
description='Bilateral Filter sigma in the coordinate space.',
value=0.0,
range=(0.0, 150.0, 0.01),
uid=[0],
),
desc.FloatParam(
name='bilateralFilterSigmaColor',
label='Bilateral Filter Sigma Color Space',
description='Bilateral Filter sigma in the color space.',
value=0.0,
range=(0.0, 150.0, 0.01),
uid=[0],
),
desc.BoolParam(
name='claheFilter',
label='Clahe Filter',
description='Use Contrast Limited Adaptive Histogram Equalization (CLAHE) Filter.',
value=False,
uid=[0],
),
desc.FloatParam(
name='claheClipLimit',
label='Clahe Clip Limit.',
description='Sets Threshold For Contrast Limiting.',
value=4.0,
range=(0.0, 8.0, 1.0),
uid=[0],
),
desc.IntParam(
name='claheTileGridSize',
label='Clahe Tile Grid Size.',
description='Sets Size Of Grid For Histogram Equalization. Input Image Will Be Divided Into Equally Sized Rectangular Tiles.',
value=8,
range=(4, 64, 4),
uid=[0],
desc.GroupAttribute(name="sharpenFilter", label="Sharpen Filter", description="Sharpen Filtering Parameters.", joinChar=":", groupDesc=[
desc.BoolParam(
name='enabled',
label='Enable',
description='Use sharpen.',
value=False,
uid=[0],
),
desc.IntParam(
name='width',
label='Width',
description='Sharpen Width.',
value=3,
range=(1, 9, 2),
uid=[0],
),
desc.FloatParam(
name='contrast',
label='Contrast',
description='Sharpen Contrast.',
value=1.0,
range=(0.0, 100.0, 0.1),
uid=[0],
),
desc.FloatParam(
name='threshold',
label='Threshold',
description='Sharpen Threshold.',
value=0.0,
range=(0.0, 1.0, 0.01),
uid=[0],
),
]),
desc.GroupAttribute(name="bilateralFilter", label="Bilateral Filter", description="Bilateral Filtering Parameters.", joinChar=":", groupDesc=[
desc.BoolParam(
name='bilateralFilterEnabled',
label='Enable',
description='Bilateral Filter.',
value=False,
uid=[0],
),
desc.IntParam(
name='bilateralFilterDistance',
label='Distance',
description='Diameter of each pixel neighborhood that is used during bilateral filtering.\nCould be very slow for large filters, so it is recommended to use 5.',
value=0,
range=(0, 9, 1),
uid=[0],
),
desc.FloatParam(
name='bilateralFilterSigmaSpace',
label='Sigma Coordinate Space',
description='Bilateral Filter sigma in the coordinate space.',
value=0.0,
range=(0.0, 150.0, 0.01),
uid=[0],
),
desc.FloatParam(
name='bilateralFilterSigmaColor',
label='Sigma Color Space',
description='Bilateral Filter sigma in the color space.',
value=0.0,
range=(0.0, 150.0, 0.01),
uid=[0],
),
]),
desc.GroupAttribute(name="claheFilter", label="Clahe Filter", description="Clahe Filtering Parameters.", joinChar=":", groupDesc=[
desc.BoolParam(
name='claheEnabled',
label='Enable',
description='Use Contrast Limited Adaptive Histogram Equalization (CLAHE) Filter.',
value=False,
uid=[0],
),
desc.FloatParam(
name='claheClipLimit',
label='Clip Limit',
description='Sets Threshold For Contrast Limiting.',
value=4.0,
range=(0.0, 8.0, 1.0),
uid=[0],
),
desc.IntParam(
name='claheTileGridSize',
label='Tile Grid Size',
description='Sets Size Of Grid For Histogram Equalization. Input Image Will Be Divided Into Equally Sized Rectangular Tiles.',
value=8,
range=(4, 64, 4),
uid=[0],
),
]),
desc.GroupAttribute(name="noiseFilter", label="Noise Filter", description="Noise Filtering Parameters.", joinChar=":", groupDesc=[
desc.BoolParam(
name='noiseEnabled',
label='Enable',
description='Add Noise.',
value=False,
uid=[0],
),
desc.ChoiceParam(
name='noiseMethod',
label='Method',
description=" * method: There are several noise types to choose from:\n"
" * uniform: adds noise values uninformly distributed on range [A,B).\n"
" * gaussian: adds Gaussian (normal distribution) noise values with mean value A and standard deviation B.\n"
" * salt: changes to value A a portion of pixels given by B.\n",
value='uniform',
values=['uniform', 'gaussian', 'salt'],
exclusive=True,
uid=[0],
),
desc.FloatParam(
name='noiseA',
label='A',
description='Parameter that have a different interpretation depending on the method chosen.',
value=0.0,
range=(0.0, 1.0, 0.0001),
uid=[0],
),
desc.FloatParam(
name='noiseB',
label='B',
description='Parameter that have a different interpretation depending on the method chosen.',
value=1.0,
range=(0.0, 1.0, 0.0001),
uid=[0],
),
desc.BoolParam(
name='noiseMono',
label='Mono',
description='If is Checked, a single noise value will be applied to all channels otherwise a separate noise value will be computed for each channel.',
value=True,
uid=[0],
),
]),
desc.ChoiceParam(
name='outputFormat',
label='Output Image Format',
description='Allows you to choose the format of the output image.',
value='rgba',
values=['rgba', 'rgb', 'grayscale'],
exclusive=True,
uid=[0],
),
desc.ChoiceParam(
name='verboseLevel',
Expand Down Expand Up @@ -198,7 +299,7 @@ class ImageProcessing(desc.CommandLineNode):
name='outputImages',
label='Output Images',
description='Output Image Files.',
value=lambda attr: desc.Node.internalFolder + os.path.basename(attr.node.input.value) if (os.path.splitext(attr.node.input.value)[1] not in ['', '.abc', '.sfm']) else (desc.Node.internalFolder + '*.' + (attr.node.extension.value or '*')),
value= outputImagesValueFunct,
group='', # do not export on the command line
uid=[],
),
Expand Down