-
Notifications
You must be signed in to change notification settings - Fork 0
Hw1 #1
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
Open
gsvgit
wants to merge
3
commits into
main
Choose a base branch
from
HW1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Hw1 #1
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "version": 1, | ||
| "isRoot": true, | ||
| "tools": { | ||
| "fantomas": { | ||
| "version": "6.3.15", | ||
| "commands": [ | ||
| "fantomas" | ||
| ] | ||
| }, | ||
| "dotnet-fsharplint": { | ||
| "version": "0.24.2", | ||
| "commands": [ | ||
| "dotnet-fsharplint" | ||
| ] | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,7 @@ name: .NET | |
|
|
||
| on: | ||
| push: | ||
| branches: [ "main" ] | ||
| pull_request: | ||
| branches: [ "main" ] | ||
|
|
||
| jobs: | ||
| build: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="Program.fs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="BenchmarkDotNet" Version="0.14.0" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| namespace Benchmarks | ||
|
|
||
| open BenchmarkDotNet.Running | ||
| open BenchmarkDotNet.Attributes | ||
|
|
||
| type SortsBenchmark() = | ||
|
|
||
| static member ArrayLengths = [|10000..10000..100000|] | ||
| //static member ArrayLengths = [|0..100..1000|] | ||
|
|
||
| member this.Random = System.Random() | ||
|
|
||
| [<ParamsSource("ArrayLengths")>] | ||
| member val ArrayLength = 0 with get, set | ||
|
|
||
| member val ArrayToSort = [|0.0|] with get, set | ||
|
|
||
| [<IterationSetup>] | ||
| member this.GetArrayToSort () = | ||
| this.ArrayToSort <- Array.init this.ArrayLength (fun _ -> this.Random.NextDouble()) | ||
|
|
||
| [<Benchmark>] | ||
| member this.Benchmark () = Array.sort this.ArrayToSort | ||
|
|
||
| module main = | ||
| [<EntryPoint>] | ||
| let main argv = | ||
| let benchmarks = | ||
| BenchmarkSwitcher [| typeof<SortsBenchmark> |] | ||
|
|
||
| benchmarks.Run argv |> ignore | ||
| 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,9 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="Library.fs" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| module ImageProcessing | ||
|
|
||
| open System | ||
| open SixLabors.ImageSharp | ||
| open SixLabors.ImageSharp.PixelFormats | ||
|
|
||
| [<Struct>] | ||
| type Image = | ||
| val Data: array<byte> | ||
| val Width: int | ||
| val Height: int | ||
| val Name: string | ||
|
|
||
| new(data, width, height, name) = | ||
| { | ||
| Data = data | ||
| Width = width | ||
| Height = height | ||
| Name = name | ||
| } | ||
|
|
||
| let loadAs2DArray (file: string) = | ||
| let img = Image.Load<L8> file | ||
| let res = Array2D.zeroCreate img.Height img.Width | ||
|
|
||
| for i in 0 .. img.Width - 1 do | ||
| for j in 0 .. img.Height - 1 do | ||
| res.[j, i] <- img.Item(i, j).PackedValue | ||
|
|
||
| printfn $"H=%A{img.Height} W=%A{img.Width}" | ||
| res | ||
|
|
||
| let loadAsImage (file: string) = | ||
| let img = Image.Load<L8> file | ||
|
|
||
| let buf = Array.zeroCreate<byte> (img.Width * img.Height) | ||
|
|
||
| img.CopyPixelDataTo(Span<byte> buf) | ||
| Image(buf, img.Width, img.Height, System.IO.Path.GetFileName file) | ||
|
|
||
| let save2DByteArrayAsImage (imageData: byte[,]) file = | ||
| let h = imageData.GetLength 0 | ||
| let w = imageData.GetLength 1 | ||
| printfn $"H=%A{h} W=%A{w}" | ||
|
|
||
| let flat2Darray array2D = | ||
| [| | ||
| for x in [0 .. (Array2D.length1 array2D) - 1] do | ||
| for y in [0 .. (Array2D.length2 array2D) - 1] do | ||
| yield array2D.[x, y] | ||
| |] | ||
|
|
||
| let img = Image.LoadPixelData<L8>(flat2Darray imageData, w, h) | ||
| img.Save file | ||
|
|
||
| let saveImage (image: Image) file = | ||
| let img = Image.LoadPixelData<L8>(image.Data, image.Width, image.Height) | ||
| img.Save file | ||
|
|
||
| let gaussianBlurKernel = | ||
| [| | ||
| [| 1; 4; 6; 4; 1 |] | ||
| [| 4; 16; 24; 16; 4 |] | ||
| [| 6; 24; 36; 24; 6 |] | ||
| [| 4; 16; 24; 16; 4 |] | ||
| [| 1; 4; 6; 4; 1 |] | ||
| |] | ||
| |> Array.map (Array.map (fun x -> (float32 x) / 256.0f)) | ||
|
|
||
| let edgesKernel = | ||
| [| | ||
| [| 0; 0; -1; 0; 0 |] | ||
| [| 0; 0; -1; 0; 0 |] | ||
| [| 0; 0; 2; 0; 0 |] | ||
| [| 0; 0; 0; 0; 0 |] | ||
| [| 0; 0; 0; 0; 0 |] | ||
| |] | ||
| |> Array.map (Array.map float32) | ||
|
|
||
| let applyFilter (filter: float32[][]) (img: byte[,]) = | ||
| let imgH = img.GetLength 0 | ||
| let imgW = img.GetLength 1 | ||
|
|
||
| let filterD = (Array.length filter) / 2 | ||
|
|
||
| let filter = Array.concat filter | ||
|
|
||
| let processPixel px py = | ||
| let dataToHandle = [| | ||
| for i in px - filterD .. px + filterD do | ||
| for j in py - filterD .. py + filterD do | ||
| if i < 0 | ||
| || i >= imgH | ||
| || j < 0 | ||
| || j >= imgW | ||
| then float32 img.[px, py] | ||
| else float32 img.[i, j] | ||
| |] | ||
|
|
||
| Array.fold2 (fun s x y -> s + x * y) 0.0f filter dataToHandle | ||
|
|
||
| Array2D.mapi (fun x y _ -> byte (processPixel x y)) img |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="ImageProcessing.fs" /> | ||
| <Compile Include="Program.fs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Argu" Version="6.2.4" /> | ||
| <PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| open ImageProcessing | ||
| open Argu | ||
|
|
||
| let pathToExamples = "/home/gsv/Projects/TestProj2020/src/ImgProcessing/Examples" | ||
| let inputFolder = System.IO.Path.Combine(pathToExamples, "input") | ||
|
|
||
| let demoFile = | ||
| System.IO.Path.Combine(inputFolder, "armin-djuhic-ohc29QXbS-s-unsplash.jpg") | ||
|
|
||
| type CmdArgs = | ||
| | [<Mandatory>] Input_File of string | ||
| | [<Mandatory>] Out_File of string | ||
| interface IArgParserTemplate with | ||
| member this.Usage = | ||
| match this with | ||
| | Input_File _ -> "File to process." | ||
| | Out_File _ -> "Where to save result." | ||
|
|
||
| [<EntryPoint>] | ||
| let main argv = | ||
| printfn "%A" argv | ||
| let parser = ArgumentParser.Create<CmdArgs>(programName = "ImageProcessing") | ||
| let usage = parser.PrintUsage() | ||
| let results = parser.Parse argv | ||
| let inFile = results.GetResult Input_File | ||
| let outFile = results.GetResult Out_File | ||
| let inImage = loadAs2DArray inFile | ||
| let resultImage = | ||
| applyFilter gaussianBlurKernel inImage | ||
| //|> applyFilter gaussianBlurKernel | ||
| //|> applyFilter gaussianBlurKernel | ||
| //|> applyFilter gaussianBlurKernel | ||
| //|> applyFilter edgesKernel | ||
| save2DByteArrayAsImage resultImage outFile | ||
| 0 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Переделать!