SciSharp / SciSharp/NumSharp

Save NDArray as png image

Open
#384 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
1.5k
Forks
205
Avg merge
7d 7h
Merged PRs (30d)
2

Description

I am looking to save an NDArray to an image.

In Python code, I used the io.imsave() method from skimage.io.

I tried using the approach shown here: https://stackoverflow.com/questions/5113919/how-to-convert-2-d-array-into-image-in-c-sharp

Basically it uses the the Bitmap method in System.Drawing.Bitmap

Is this the correct way to do this?

I tried converting the NDArray to a C# multidimensional array and then using the following type of code:

Bitmap bitmap; unsafe { fixed (int* intPtr = &integers[0,0]) { bitmap = new Bitmap(width, height, stride, PixelFormat.Format32bppRgb, new IntPtr(intPtr)); } }

However, I get this error on the "bitmap =" line: System.ArgumentException: 'Parameter is not valid.'

Ultimately I would like to compare the output from my python code to the output from my C# code to ensure that they are doing the same thing. As I stated, in Python I saved a multidimensional array to png. My thought was to do the same in C# using NumSharp, and then comparing the output images.

Thanks in advance.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue mentions converting a NumSharp NDArray to a C# multidimensional array and using System.Drawing.Bitmap; start by reviewing the array representation and Bitmap constructor requirements. Done means a NumSharp-compatible path can save the array as PNG and its output can be compared with the Python image.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
computer-vision
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.