Sunday, July 12, 2020

Sunday, July 5, 2020

python binary write/read example

import numpy as np
import json

def read32(bs):
    data = bs.read(4)
    return int.from_bytes(data, byteorder='big', signed=False)

def write32(bs, int_data):
    bs.write(int_data.to_bytes(4, byteorder='big', signed=False))

def writeTest():
    trainImageFile = open('eyedata_set/train-images.ubyte', 'wb')
    count = 4
    width = 1024
    height = 768

    write32(trainImageFile, count)
    write32(trainImageFile, width)
    write32(trainImageFile, height)
   
    trainImageFile.close()
   
    print('[DONE] write test')
   
def readTest():
    trainImageFile = open('eyedata_set/train-images.ubyte', 'rb')
    count = read32(trainImageFile)
    width  = read32(trainImageFile)
    height = read32(trainImageFile)
   
    trainImageFile.close()
       
    print('[DONE] read test')
    print('{}, {}, {}'.format(count, width, height))


Wednesday, July 1, 2020

MNIST 데이터 읽어서 이미지로 저장하기

train-images.idx3-ubyte 파일은 http://yann.lecun.com/exdb/mnist/에서 받으면 되고
보통은 만들어진 파서 사용하면 되지만 파이썬 공부도 할겸. 직접 만들어서 처리.

# train-images.idx3-ubyte
from PIL import Image

f = open('train-images.idx3-ubyte', 'rb')

#[offset] [type]          [value]          [description]
#0000     32 bit integer  0x00000803(2051) magic number
#0004     32 bit integer  60000            number of images
#0008     32 bit integer  28               number of rows
#0012     32 bit integer  28               number of columns
#0016     unsigned byte   ??               pixel
#0017     unsigned byte   ??               pixel
#........
#xxxx     unsigned byte   ??               pixel
#Pixels are organized row-wise. Pixel values are 0

def read32(bs):
    data =  bs.read(4)
    return int.from_bytes(data, byteorder='big', signed=False)

magic = read32(f)
imageCount = read32(f)
imageRow = read32(f)
imageCol = read32(f)

for i in range(0,imageCount):
    # 루프를 돌면서 28x28개수만큼 픽셀을 읽는다.
    imageBuffer = f.read(28*28)
    image = Image.frombytes('L', (28, 28), imageBuffer, 'raw')   
    image.save('extracted/' + str(i) + '.jpg', 'JPEG')
   
print('[DONE] Extracted all the images!')
f.close()

Tuesday, June 30, 2020

Python single line for loop

# example of single line for loop
x = [1,2,3,4]
print( sum(e for e in x) )

I can get 10. What if we don't have a single line for loop?

s = 0
for e in x:
    s += e
print(s)

Wednesday, May 20, 2020

Selector, Sequence

Selector : Executes all the commands until it finds a success.
Sequence : Executes all the command until it finds a fail.

Tuesday, May 12, 2020

Data compression needs!

Many people are not interested about the data compression but it is important!
Recently I'm working on a project which is using GLTF and there is a library 'draco' but it seems animation data compression feature is a little bit missing as expected.

If the model has really big animations then size of the model will be big. This is not acceptable in some cases where passing the model data via network and so on.

I hope someone should be working on this issue ASAP! then you will get a credit!

Thursday, May 7, 2020

Logarithmic Depth Buffer


If your model is big then you should use logarithmic depth buffer like down below

renderer = new THREE.WebGLRenderer( { antialias: true, logarithmicDepthBuffer: true } );

or just scale down the models. :)


Task in UnrealEngine

 https://www.youtube.com/watch?v=1lBadANnJaw