Comments (24)
Yes:
SetFormat(SinkFormats.Y16) should do the job.
Stefan
from ic-imaging-control-samples.
Many thanks for the quick reply! This (probably) worked, it changes the image grabbed to (width, height,2) instead of (width, height,3) for the RGB24 case.
Still the dtype is uint8. Do I have "sum" the two layers to get the 16bit image?
from ic-imaging-control-samples.
hmm
to be tested. Currently I work on the property interface, so you may wait until next week, However, did you check my Python code in tisgrabber.py, whether I did the correct things?
The sinkformat must be set, before the live video is started. Did you do so?
Stefan
from ic-imaging-control-samples.
Sure, next week is completely fine!
From the code in tisgrabber.py I indeed understand that two 8bit images are stacked, but my knowledge of interfacing python and C is not very good....
from ic-imaging-control-samples.
I got my today's task nearly done, Thus I will have a look on Monday.
I hope, that is fine for you.
Stefan
from ic-imaging-control-samples.
I have a question related to this issue. How about 12bit RGB image?
Thanks!
from ic-imaging-control-samples.
Hello
I updated the repository at https://github.com/TheImagingSource/IC-Imaging-Control-Samples/tree/master/Python. There is a new sample "Using-Y16.py" and an updated "tisgrabber.py"
RGB64 for 12bit / 10bit RGB is currently not supported. Use Y16 instead, however, that is not debayered.
I will add RGB64 later.
(I must admit, image buffer handling in the tisgrabber.dll is quite primitive. There is space for enhancement.)
Stefan
from ic-imaging-control-samples.
Dear Stefan,
many thanks for the quick update! It seems to work and returns now a 2D array with uint16 as desired but I struggle to make sense of the data. The 2D array in the image variable:
image = Camera.GetImageEx()
is not arranged how it should be. I focused a leaser beam in the middle of the image and would expect lots of saturated values in the middle of the array (as seen in IC capture), but instead these saturated pixels are smeared out over many lines.
-> It seems there is some transformation that is not correct, e.g. how from a long 1D array the 2D array is formed.
from ic-imaging-control-samples.
Hello Jonas
Could you please check for me, whether I made the numpy stuff correct in the tisgrabber.py? I am not an experiecend Python programmer, therefore, I am not sure.
The array should have two dimensions width and height of uint 16.
Thank you in advance!
Stefan
from ic-imaging-control-samples.
Hi Stefan,
nevermind it works well, I just forgot the cv.flip and cv.erode transformations that you are doing in tis-openCV...
Many thanks!
Jonas
from ic-imaging-control-samples.
Hi Jonas
thank you! That is a relief for me,
Stefan
from ic-imaging-control-samples.
Hi Stefan,
one more comment: now the 12bit image is scaled over a 16bit array. The values are then 16 , 32 ,6 4 and so on until 65535. Is this as intended or should it be 1 , 2 ,3 etc until 4096?
For me it makes no difference, but maybe for others.
best
Jonas
from ic-imaging-control-samples.
Hello Jonas
we use the upper 12 bits only. The lower 4 bits are not connected. Therefore, white is 65535, black is 0-15. The lower 4 bits are invalid.
You get a range from 0 to 4096, if you shift 4 bits to the right " >> 4"
Stefan
from ic-imaging-control-samples.
Ok, I did it by using
image=np.right_shift(image,4)
cheers
Jonas
from ic-imaging-control-samples.
Hello
I updated the repository at https://github.com/TheImagingSource/IC-Imaging-Control-Samples/tree/master/Python. There is a new sample "Using-Y16.py" and an updated "tisgrabber.py"
RGB64 for 12bit / 10bit RGB is currently not supported. Use Y16 instead, however, that is not debayered.
I will add RGB64 later.
(I must admit, image buffer handling in the tisgrabber.dll is quite primitive. There is space for enhancement.)
Stefan
Hi, Is the sample about Y16 still available?
from ic-imaging-control-samples.
Hello
The sample exists:
Using-Y16.zip
I did not test it.
Stefan
from ic-imaging-control-samples.
Hello
The sample exists: Using-Y16.zip I did not test it.
Stefan
Thank you for sharing this!
My question is basically how to interpret the output of the Y16 image, which is two 2d array.
Does each 2d array contains 8 bits of the 16 bits for each pixel? I tried to multiplied one of the array by 2**8 and add them up, the result looks not bad, but not as good as the result saved from IC Capture software. I am wondering if I did it correctly.
btw: according to this website, it seems all the bits have to be used to get the final pixel values.
https://www.theimagingsource.com/en-us/documentation/icimagingcontrolcsharp/PixelformatY16.htm
from ic-imaging-control-samples.
The 2D Array should contain ushort values, which is a two byte unsigned integer. It contains the 16 bits. Depending on the used camera model, the upper 12 or the upper 10 bits contain valid image data. How do you display the result?
from ic-imaging-control-samples.
def get_data(self):
buffer_size, width, height, depth = self.get_buffer()
image_pointer = ic.IC_GetImagePtr(self.hGrabber)
image_data = ctypes.cast(image_pointer, ctypes.POINTER(ctypes.c_ubyte * int(buffer_size)))
image = np.array(image_data.contents)
image = np.reshape(image, (int(height.value), int(width.value), depth))
return image[:, :, 0] + image[:, :, 1] * (2 ** 8)
This is what I do on the data. Please correct me if anything is wrong. Thank you!
I am using DMK33UX250, which has the dynamic range of 12 bit.
from ic-imaging-control-samples.
I am not sure what the contents of depth is. It should be 16, because you have 16 bits. Please check this.
The correct usage is:
# Declare variables of image description
Width = ctypes.c_long()
Height = ctypes.c_long()
BitsPerPixel = ctypes.c_int()
colorformat = ctypes.c_int()
# Query the values of image description
ic.IC_GetImageDescription(hGrabber, Width, Height,
BitsPerPixel, colorformat)
# Calculate the buffer size, get the number of bytes per pixel
# and the data type in the numpy array.
elementsperpixel = 1
dtype = np.uint8
if colorformat.value == tis.SinkFormats.Y800:
elementsperpixel = 1 # 1 byte per pixel
if colorformat.value == tis.SinkFormats.Y16:
dtype = np.uint16
elementsperpixel = 1 # 1 uint16 per pixel
if colorformat.value == tis.SinkFormats.RGB24:
elementsperpixel = 3 # BGR format, 3 bytes
if colorformat.value == tis.SinkFormats.RGB32:
elementsperpixel = 4 # BGRA format, 4 bytes
buffer_size = Width.value * Height.value * int(float(BitsPerPixel.value) / 8.0)
# Get the image data
imagePtr = ic.IC_GetImagePtr(hGrabber)
imagedata = ctypes.cast(imagePtr,
ctypes.POINTER(ctypes.c_ubyte *
buffer_size))
# Create the numpy array
image = np.ndarray(buffer=imagedata.contents,
dtype=dtype,
shape=(Height.value,
Width.value,
elementsperpixel))
Surprisingly I found this sample:
12-image-processing-16bit.zip
Stefan
from ic-imaging-control-samples.
I am not sure what the contents of depth is. It should be 16, because you have 16 bits. Please check this. The correct usage is:
# Declare variables of image description Width = ctypes.c_long() Height = ctypes.c_long() BitsPerPixel = ctypes.c_int() colorformat = ctypes.c_int() # Query the values of image description ic.IC_GetImageDescription(hGrabber, Width, Height, BitsPerPixel, colorformat) # Calculate the buffer size, get the number of bytes per pixel # and the data type in the numpy array. elementsperpixel = 1 dtype = np.uint8 if colorformat.value == tis.SinkFormats.Y800: elementsperpixel = 1 # 1 byte per pixel if colorformat.value == tis.SinkFormats.Y16: dtype = np.uint16 elementsperpixel = 1 # 1 uint16 per pixel if colorformat.value == tis.SinkFormats.RGB24: elementsperpixel = 3 # BGR format, 3 bytes if colorformat.value == tis.SinkFormats.RGB32: elementsperpixel = 4 # BGRA format, 4 bytes buffer_size = Width.value * Height.value * int(float(BitsPerPixel.value) / 8.0) # Get the image data imagePtr = ic.IC_GetImagePtr(hGrabber) imagedata = ctypes.cast(imagePtr, ctypes.POINTER(ctypes.c_ubyte * buffer_size)) # Create the numpy array image = np.ndarray(buffer=imagedata.contents, dtype=dtype, shape=(Height.value, Width.value, elementsperpixel))Surprisingly I found this sample: 12-image-processing-16bit.zip
Stefan
Thank you for the finding! I finally realize why the images saved from python are not as good as the images saved from the software. It is due to the noise reduction. I set the noise reduction to 8 frames in the IC Capture, but the python code I only set the denoise property. I will just need to figure out how to set the noise reduction function then it should be the same quality. Is there any example code that set the noise deduction function? Is it relates to the framefilter stuff?
from ic-imaging-control-samples.
IC Capture makes averaging of images on its own, therefore, it is not a camera nor an IC Imaging Control property. You can use OpenCV for that with cv2.accumulateWeighted()
# Convert 16bit image to 8 bit image
if img.dtype == np.dtype('uint16'):
self.display_image = cv2.convertScaleAbs(img, alpha=(1.0/256.0))
else:
self.display_image = img
if self.avg is None:
self.avg= np.float32(img)
cv2.accumulateWeighted(self.display_image, self.avg, 0.075)
I am not sure, why I convert the 16 bit ot 8 bits and whether that is necessary. This copied from a motion detection sample I found in the depth of my hard disc.
Stefan
from ic-imaging-control-samples.
IC Capture makes averaging of images on its own, therefore, it is not a camera nor an IC Imaging Control property. You can use OpenCV for that with cv2.accumulateWeighted()
# Convert 16bit image to 8 bit image if img.dtype == np.dtype('uint16'): self.display_image = cv2.convertScaleAbs(img, alpha=(1.0/256.0)) else: self.display_image = img if self.avg is None: self.avg= np.float32(img) cv2.accumulateWeighted(self.display_image, self.avg, 0.075)I am not sure, why I convert the 16 bit ot 8 bits and whether that is necessary. This copied from a motion detection sample I found in the depth of my hard disc.
Stefan
I see. Then I can just take multiple frames and average them in python. I think the problem is solved! Thank you very much.
from ic-imaging-control-samples.
Consider using OpenCV, because it is fast than programming the same stuff in Python.
Stefan
from ic-imaging-control-samples.
Related Issues (20)
- Confusion about version of tisgrabber.dll HOT 3
- Framesnapsink/Framequesink HOT 3
- Noise Reduction HOT 18
- Taking images after external trigger for a fixed time HOT 13
- How to operate multiple cameras at the same time get image through python HOT 2
- Knowing when callback fails HOT 8
- Detailed trigger mode setting HOT 2
- Capture AVI program is not working HOT 12
- Activate/deactivate external trigger using python script HOT 4
- Exception: A set operation on a VCDProperty object failed HOT 10
- IC_StartLive fail HOT 3
- Cannot get Map Strings for Strobe Mode in python HOT 18
- Get crashed on create MediaStreamSink object in C# in .net core 7 HOT 2
- Web browser stream HOT 5
- Getting the exposure time HOT 3
- IC Imaging source upgrade to 3.5 from 3.4 HOT 1
- Ic imaging control 3.5 HOT 3
- tisfrabber LoadDeviceStateFromFile() and SnapImage HOT 1
- Python (tisgrabber): interaction with camera livestream IC_StartLive HOT 5
- Wondering if it's possible to make the video window scrollable in python HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ic-imaging-control-samples.