NET.addAssembly([pwd, '\Thorlabs.TSI.TLCamera.dll']);
Error using NET.addAssembly
Execution of script addAssembly as a function is not supported:
/MATLAB/toolbox/matlab/winfun/NET/+NET/addAssembly.m
disp('Dot NET assembly loaded.');
tlCameraSDK = Thorlabs.TSI.TLCamera.TLCameraSDK.OpenTLCameraSDK;
serialNumbers = tlCameraSDK.DiscoverAvailableCameras;
disp([num2str(serialNumbers.Count), ' camera was discovered.']);
if (serialNumbers.Count > 0)
disp('Opening the first camera')
tlCamera = tlCameraSDK.OpenCamera(serialNumbers.Item(0), false);
isColorCamera = tlCamera.CameraSensorType == Thorlabs.TSI.TLCameraInterfaces.CameraSensorType.Bayer;
NET.addAssembly([pwd, '\Thorlabs.TSI.Demosaicker.dll']);
NET.addAssembly([pwd, '\Thorlabs.TSI.ColorProcessor.dll']);
demosaicker = Thorlabs.TSI.Demosaicker.Demosaicker;
colorProcessorSDK = Thorlabs.TSI.ColorProcessor.ColorProcessorSDK;
defaultWhiteBalanceMatrix = tlCamera.GetDefaultWhiteBalanceMatrix;
cameraColorCorrectionMatrix = tlCamera.GetCameraColorCorrectionMatrix;
bitDepth = int32(tlCamera.BitDepth);
colorFilterArrayPhase = tlCamera.ColorFilterArrayPhase;
standardRGBColorProcessor = colorProcessorSDK.CreateStandardRGBColorProcessor(defaultWhiteBalanceMatrix,...
cameraColorCorrectionMatrix, bitDepth);
tlCamera.ExposureTime_us = 20000;
gainRange = tlCamera.GainRange;
if (gainRange.Maximum > 0)
tlCamera.MaximumNumberOfFramesToQueue = 5;
disp('Starting software triggered image acquisition.');
tlCamera.OperationMode = Thorlabs.TSI.TLCameraInterfaces.OperationMode.SoftwareTriggered;
tlCamera.FramesPerTrigger_zeroForUnlimited = 1;
maxPixelValue = double(2^tlCamera.BitDepth - 1);
numberOfFramesToAcquire = 50;
for iloop = 1:numberOfFramesToAcquire
tlCamera.IssueSoftwareTrigger;
while (tlCamera.NumberOfQueuedFrames == 0)
if (tlCamera.NumberOfQueuedFrames > 1)
disp(['Data processing falling behind acquisition. ' num2str(tlCamera.NumberOfQueuedFrames) ' remains']);
imageFrame = tlCamera.GetPendingFrameOrNull;
imageData = imageFrame.ImageData.ImageData_monoOrBGR;
disp(['Image frame number: ' num2str(imageFrame.FrameNumber)]);
imageHeight = imageFrame.ImageData.Height_pixels;
imageWidth = imageFrame.ImageData.Width_pixels;
demosaickedImageData = NET.createArray('System.UInt16',imageHeight * imageWidth * 3);
colorFormat = Thorlabs.TSI.ColorInterfaces.ColorFormat.BGRPixel;
demosaicker.Demosaic(imageWidth, imageHeight, int32(0), int32(0), colorFilterArrayPhase,...
colorFormat, Thorlabs.TSI.ColorInterfaces.ColorSensorType.Bayer,...
bitDepth, imageData, demosaickedImageData);
processedImageData = NET.createArray('System.UInt16',imageHeight * imageWidth * 3);
standardRGBColorProcessor.Transform48To48(demosaickedImageData, colorFormat,...
uint16(0), uint16(maxPixelValue), uint16(0), uint16(maxPixelValue),...
uint16(0), uint16(maxPixelValue), int32(0), int32(0), int32(0), processedImageData, colorFormat);
imageColor = reshape(uint16(processedImageData), [3, imageWidth, imageHeight]);
imageColor = double(permute(imageColor,[3 2 1]));
imageColor = flip(imageColor,3);
figure(1),image(imageColor/maxPixelValue), colorbar
imageData2D = reshape(uint16(imageData), [imageWidth, imageHeight]);
figure(1),imagesc(imageData2D'), colormap(gray), colorbar
disp('Stopping software triggered image acquisition.');
disp('Releasing the camera');
standardRGBColorProcessor.Dispose;
delete(standardRGBColorProcessor);
colorProcessorSDK.Dispose;
delete(colorProcessorSDK);