DateTime class object from .Net. dateTimeNow = System.DateTime.Now isnetsupported = NET.isNETSupported AddMinutes dateTimeNow = dateTimeNow.AddMinutes(10) Date: [1x1 System.DateTime] Day: 21 DayOfWeek: [1x1 System.DayOfWeek] DayOfYear: 111 Hour: 13 Kind: [1x1 System.DateTimeKind] Millisecond: 160 Minute: 49 Month: 4 Now: [1x1 System.DateTime] UtcNow: [1x1 System.DateTime] Second: 56 Ticks: 635021489961600559 TimeOfDay: [1x1 System.TimeSpan] Today: [1x1 System.DateTime] Year: 2013 MinValue: [1x1 System.DateTime] MaxValue: [1x1 System.DateTime] Algorithms.dll algorithm for finding the upper left corner of the bounding rectangle of a binary image. using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Algorithms { public class ImageProcessor { public ImageProcessor() {} /// <summary> /// coordinates /// . - {-1,-1} /// </summary> /// <param name="bitmap"> </param> /// <param name="coordinates"> </param> public void GetLeftUpperCornerBB(Bitmap bitmap, out int[] coordinates) { coordinates = null; var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb); unsafe { // uint* p = (uint*) bitmapData.Scan0.ToPointer(); coordinates = new int[2]{-1,-1}; // for (int i = 0; i < bitmap.Height*bitmap.Width; i++) { if( (*p & 0xFFFFFF) == 0) // { coordinates[0] = i / bitmap.Width; break; } p++; } p = (uint*) bitmapData.Scan0.ToPointer(); for (int i = 0; i < bitmap.Height*bitmap.Width; i++) { if( (p[( i % bitmap.Height) * bitmap.Width + ( i / bitmap.Height) ] & 0xFFFFFF) == 0) // { coordinates[1] = i / bitmap.Height; break; } } } bitmap.UnlockBits(bitmapData); } } } GetLeftUpperCornerBB method takes as input a Bitmap class object that contains a binary image and returns the coordinates of the first left upper black pixel in the coordinates array (if there is no such image, for example, in the case of an empty image, null returned).Example.m , next to which we place the Algorithms.dll obtained in the previous step (see screenshot below)
addAssembly function, addAssembly load the assembly into Matlab. netAssembly = NET.addAssembly('D:\Work\MatlabNetIntegrationExample\Algorithms.dll') netAssembly.Classes ans = 'Algorithms.ImageProcessor' import Algorithms.* ImageProcessor class and load the input image into the bitmap variable imageProcessor = ImageProcessor(); bitmap = System.Drawing.Bitmap('picture.bmp') picture.bmp file is located in the current working directory. methods (imageProcessor) Methods for class Algorithms.ImageProcessor: Equals delete le GetHashCode eq lt GetLeftUpperCornerBB findobj ne GetType findprop notify ImageProcessor ge ToString gt addlistener isvalid GetLeftUpperCornerBB and get the result coords = imageProcessor.GetLeftUpperCornerBB(bitmap); out parameters (suppose, as many as three arrays with coordinates), then we would write such code to get them [coords, cords2, cords3] = imageProcessor.GetLeftUpperCornerBB(bitmap); System.Int32[] , so for the possible convenience of working with it, it is possible to convert this array into a native Matlab array. For example: arrayOfDoubles = coords.double; arrayOfIntegers = coords.int32; NET.convertArray function. netAssembly = NET.addAssembly('D:\Work\MatlabNetIntegrationExample\Algorithms.dll'); netAssembly.Classes; import Algorithms.*; imageProcessor = ImageProcessor(); bitmap = System.Drawing.Bitmap('picture.bmp'); methods (imageProcessor); coords = imageProcessor.GetLeftUpperCornerBB(bitmap); arrayOfIntegers = coords.int32; Source: https://habr.com/ru/post/177449/
All Articles