2016년 9월 27일 화요일

c# Bitmap Size Limits

  • The max is object size is 2GB : 2,147,483,648
  • Default bitmap is 32bpp (4 bytes), the largest area we can have is 2GB / 4 = 536,870,912
  • If we want a square, the largest we can get is sqrt(2GB/4) = 23,170

따라서 

2바이트 = 16bpp(bit per pixel)

1바이트 = 8bpp

0.5바이트 = 4bpp

등으로 픽셀당 비트수를 낮추면 좀더 큰 Array 의 비트맵을 만들 수 있다. 

2016년 9월 26일 월요일

2016년 9월 21일 수요일

c# Get All Enum Value

1. Enum Value
        public enum eRangeI { AUTO, OFF, R1uA, R10uA, R100uA, R1mA, R10mA, R100mA, R1A }
        static void Main(string[] args)
        {
           
            foreach (var item in Enum.GetValues(typeof(eRangeI)))
            {
                Console.WriteLine($"{item}");

            }
            Console.Read();
        }

2.Enum index

        public enum eRangeI { AUTO, OFF, R1uA, R10uA, R100uA, R1mA, R10mA, R100mA, R1A }
        static void Main(string[] args)
        {
           
            foreach (var item in Enum.GetValues(typeof(eRangeI)))
            {
                int value = (int)item;
                Console.WriteLine($"{value}");

            }
            Console.Read();
        }

c# Get Enum Value by index

public enum eRangeI { AUTO, OFF, R1uA, R10uA, R100uA, R1mA, R10mA, R100mA, R1A }
        static void Main(string[] args)
        {

            eRangeI value = (eRangeI)0;
            Console.WriteLine(value.ToString());
            Console.Read();
        }


--- output = AUTO

C# winform All Enum insert in comboBox

cmbSrcRange.DataSource = Enum.GetValues(typeof(eRangeI));

python for 문 사용시 주의해야할 점

--- 잘못된 예  (i는 0부터 시작한다.  밑줄 부분은 1부터 시작해야 한다.)
def Michalewicz(self,dim,x,m):
        sum = 0
        for i in range(dim):
            new = np.sin(x[i]) * ((np.sin(i*(x[i]**2) / np.pi))**2*m)
            sum  = sum + new
        return -1 * sum


----- 잘된 예 ( i + 1 로 했다.)
def Michalewicz(self,dim,x,m):
        sum = 0
        for i in range(dim):
            new = np.sin(x[i]) * ((np.sin((i+1)*(x[i]**2) / np.pi))**2*m)
            sum  = sum + new
        return -1 * sum

이런거 잘 보자. 이것때메 엄청 삽질했다.

2016년 9월 20일 화요일

C# Image to byte[]

Image 가 가로 4 세로 2 이고

1 2 3 4
5 6 7 8 을 array 로 바꾸면


1 5 2 6 3 7 4 8 의 배열이 생긴다.

이걸 다시 Reshape(4,2) -> Transpose 하면

원래대로 돌아온다.

1 = 0,0

5 = 0,1

2 = 1,0

6 = 1,1

에서
1 = 0,0

5 = 1,0

2 = 0,1

6 = 1,1
.
.
.
.

c# Accord ReShape

arr1 = [1 2 3 4 5 6]
arr2 = [1 2 3 4 5 6]

Array = Concatenate(arr1,arr2) =  [1 2 3 4 5 6 1 2 3 4 5 6 ]

Reshape(Array,6,2)
=
[1 2
3 4
5 6
1 2
3 4
5 6]


2016년 9월 18일 일요일

c# Image to grayscale byte array

http://stackoverflow.com/questions/18766004/how-to-convert-from-system-drawing-bitmap-to-grayscale-then-to-array-of-doubles

----------------------------------------------------------------------

        public static byte[,] ToGrayscale(Bitmap bitmap)
        {
            var result = new byte[bitmap.Width, bitmap.Height];
            for (int x = 0; x < bitmap.Width; x++)
                for (int y = 0; y < bitmap.Height; y++)
                {
                    var grayColor = ToGrayscaleColor(bitmap.GetPixel(x, y));
                    result[x, y] = (byte)grayColor;
                }
            return result;
        }

        public static byte ToGrayscaleColor(Color color)
        {
            var level = (byte)((color.R + color.G + color.B) / 3);
            return level;
        }