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

Initialize MagickImage from ushort array #1142

Closed
InternalHigh opened this issue Feb 21, 2022 · 9 comments
Closed

Initialize MagickImage from ushort array #1142

InternalHigh opened this issue Feb 21, 2022 · 9 comments
Milestone

Comments

@InternalHigh
Copy link

InternalHigh commented Feb 21, 2022

Hello,

would it make sense to implement a MagickImage constructor which takes a ushort array instead of a byte array (for Q16)?

My input data is a ushort array and at the moment I have to convert it into a byte array using Buffer.BlockCopy. This conversion takes ~30 ms for large images. Can this conversion be avoided or does the internal C API require bytes?

@dlemstra
Copy link
Owner

The internal API requires a byte array. Why is your image data an ushort array?

@InternalHigh
Copy link
Author

My input is from an industrial camera: ushort array of 16-bit gray values. But if the internal API requires a byte array this conversion can not be avoided. Thanks. :)

@dlemstra
Copy link
Owner

If those are just pixels you could also do this:

var width = 100;
var height = 100;
ushort[] data = GetData();
using var image = new MagickImage();
using var pixels = image.GetPixels();
pixels.SetArea(0, 0, width, height, data);

@InternalHigh
Copy link
Author

If those are just pixels you could also do this:

var width = 100;
var height = 100;
ushort[] data = GetData();
using var image = new MagickImage();
using var pixels = image.GetPixels();
pixels.SetArea(0, 0, width, height, data);

This fails for me with "Invalid X coordinate: 0. Parametername: x'"

I think this is because Height and Width are not set for the MagickImage.

@dlemstra
Copy link
Owner

dlemstra commented Feb 21, 2022

Woops sorry :) You should indeed set the size of the image, that should be: new MagickImage(MagickColors.Black, width, height);

@InternalHigh
Copy link
Author

Woops sorry :) You should indeed set the size of the image, that should be: new MagickImage(MagickColors.Black, width, height);

I couldn't get it working. It wants three channels, I only have one. ;)
I also tried with "image.Format = MagickFormat.Gray" after constructor.

System.ArgumentException: 'Values should have 3 channels. Parametername: values'

@dlemstra
Copy link
Owner

I keep forgetting that I have a ReadPixels method in the MagickImage class. It does seem that this could use an extra overload where you can read the pixels in the quantum type of the image. I will add that later this week.

@dlemstra dlemstra reopened this Feb 21, 2022
@dlemstra dlemstra added this to the 11.0.0 milestone Mar 20, 2022
@InternalHigh
Copy link
Author

Thank you @dlemstra :)

What "mapping" can I use for PixelReadSettings when I have gray values? I tried "R" and it works, but it feels wrong. ;)

@dlemstra
Copy link
Owner

Maybe I for intensity?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants