联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codehelp

您当前位置:首页 >> 代写Assignment代写Assignment

日期:2020-01-06 09:56

Image processing pipeline - Part C (10%)

Complete your program by implementing pipefile parsing and command-line argument

parsing.

Pipefile parsing (5%)

Your program should be able to parse an input text file, which we can call the pipefile. The

pipefile describes a complete processing pipeline using nodes in a sequence. The following

pipefile, pipe1.txt , is given as an example:

Your program should be able to parse any pipefile that describes nodes that you have

implemented in part A.

In order to parse a pipefile, you will need to implement a method that reads in a pipefile, and

then creates and links the nodes as needed, and finally returns the exit node. The usage may

look like the following:

Pipefile format

Each line in a pipefile describes a node to be integrated into a pipeline, described by key-value

pairs of the form key=value . Every line requires a node key whose value contains a known node

name. Additional key-value pairs are needed for any parameters required by the node.

Within key-value pairs, values may take the form of:

string : e.g. crop , vignette , sharpen

bool : given by either yes or no

veci : integer vector, e.g. 550x0 or 300x300

vecf : floating-point vector such as 0.5x0.5

int : integer such as 34 or 55

path : a filepath such as in/mask.png

float : floating-point values such as 0.5 (can use double in C#)

The following describes the key-value pairs needed for each of the processors in part A:

N_Greyscale

node=greyscale

N_Resize

node=crop origin=550x0 size=300x300

node=vignette

node=greyscale

node=convolve kernel=sharpen

Image input = new Image("in/cat.png");

Node endNode = PipelineLoader.LoadPipeline("pipe1.txt");

Image output = endNode.GetOutput(input);

output.Write("output");

node=resize

newSize= veci

N_Threshold

node=threshold

minThreshold= int [optional] (minimum threshold value)

maxThreshold= int [optional] (maximum threshold value)

N_Mask

node=mask

maskFile= path (path to the mask file)

N_Crop

node=crop

origin= veci (location of the top-left origin)

size= veci (size of the crop region)

N_Pixelate

node=pixelate

pixelSize= veci (pixel size of pixelations)

N_Vignette

node=vignette

N_Noise

node=noise

noisePercent= double

N_Convolve

node=convolve

kernel=[blur or sharpen or edge]

N_RegionGrow

node=region_grow

origin= veci (origin of the region growth)

threshold= int (minimum threshold to grow into)

Pipefile processing tips

The System.IO.File.ReadAllLines(...) method can be used to read a text file. See the following

example:

The string.Split(...) method can be used to split up a string into an array of strings using a

given string as a splitting element. For example:

It is highly recommended that you break this problem down by writing small methods that

perform very simple processes.

using System.IO;

...

string[] linesArr = File.ReadAllLines("pipe1.txt");

string example = "100x500";

string[] split = example.Split("x");  returns { "100", "500" }

Here are some examples:

A method that takes a pipefile line as a parameter, and returns a constructed Node

A method that takes a pipefile line and a key as parameters, and returns the value

associated with that key, or an empty string if the key does not exist

A method that parses a vector string or coordinate (such as "500x300")

Command-line argument parsing (5%)

When the program is invoked via dotnet run , a number of parameters are used to control the

way the program behaves:

-pipefile : the path to the input pipefile

-input : the path to the input image or image folder

-output : the path to the output image or image folder (without extension)

-verbose : optional argument to enable logging

-saveall : optional argument to enable saving of intermediate files

-help : optional argument to print the help text and close (no processing)

Command-line arguments should be able to be positioned in any order - your program should

not make any assumptions about the existence or the order of command-line arguments.

If -input is a single image, then that image should be processed into a single output image at the

-output path using the pipeline described in -pipefile . However, if the -saveall option is given,

the output should be a folder containing the output image of each node.

If -input is a folder, then all images in that folder should be processed into a folder of outputs at

the -output path using the pipeline described in -pipefile . If the -saveall option is given, each

output within the -output folder will also be a folder, containing the output images from each

node.

If a required folder does not exist, your program should create it using

Directory.CreateDirectory(...) .

For example:

C:/> dotnet run -pipe mypipe.txt -input cat.png -output out

| C:/

| cat.png

| out.png

C:/> dotnet run -pipe mypipe.txt -input cat.png -output out -saveall

| C:/

| cat.png

| out/

| | cat-01-crop.png

| | cat-02-convolve.png

| | cat-03-noise.png

| | cat-04-greyscale.png

C:/> dotnet run -pipe mypipe.txt -input in/ -output out

| C:/

| in/

| | cat.png

| | greys.png

Output displayed using the -help option:

See below for the help text given when the -help command-line argument is given:

The order of parameters is unimportant - parameters should be able to be specified in any order.

For instance, the following two examples are equivalent:

Output displayed with no inputs:

| | house.png

| out/

| | mypipe-cat.png

| | mypipe-greys.png

| | mypipe-house.png

C:/> dotnet run -pipe mypipe.txt -input in/ output out -saveall

| C:/

| in/

| | cat.png

| | greys.png

| | house.png

| out/

| | mypipe-cat/

| | | cat-01-crop.png

| | | cat-02-convolve.png

| | | cat-03-noise.png

| | | cat-04-greyscale.png

| | mypipe-greys/

| | | greys-01-crop.png

| | | greys-02-convolve.png

| | | greys-03-noise.png

| | | greys-04-greyscale.png

| | mypipe-house/

| | | house-01-crop.png

| | | house-02-convolve.png

| | | house-03-noise.png

| | | house-04-greyscale.png

C:/> dotnet run -help

Usage: dotnet run [options] -pipe <path> -input <path> -output <path>

Required parameters:

-pipe <path> : the path to the pipe txt file

-input <path> : the path to the input image or image directory

-output <path> : the path to the output (file or directory)

(must be a directory if -saveall is enabled or -input is a directory

Options:

-verbose : use this option to enable verbose logging

-saveall : use this option to save all intermediate images

-help : display this help

C:/> dotnet run -pipe pipefile.txt -input cat.png -output out -saveall

C:/> dotnet run -saveall -output out -pipe pipefile.txt -input cat.png

If the -verbose option is specified, logging should be enabled during processing (from part B).

Regardless of the -verbose option, useful error messages should always be output to the console

when they occur.

If the -saveall option is specified, all intermediate results (the results of each node) should also

be saved by the program. If intermediate results are saved, the output path must be a directory.

If many images are being processed, and intermediate results are needed, a folder for each input

image should be created containing all results.

If the -help option is specified, the help output is displayed.

Command-line argument parsing tips

It is recommended that all the work for this part is written in Program.cs , within the Program

class.

It is possible to check if a directory or a file exists using System.IO.Directory.Exists and

System.IO.File.Exists . It is possible to create a directory using

System.IO.Directory.CreateDirectory .

It is recommended that you write helper methods that check for the existence or return the

values of parameters. Some helper method ideas are given below.

C:/> dotnet run

-pipe missing!

-input missing!

-output missing!

Usage: dotnet run [options] pipe path> input path> output path>

use -h option for detailed help

public static void Main(string[] args)

{

 returns true or false depending on whether args contains -verbose

bool verboseExists = CheckSingularArg(args, "-verbose");

 returns the value to the right of -input if it exists

 otherwise an empty string

string inputPath = GetArgValue(args, "-input");

}


版权所有:留学生作业网 2018 All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。