def METHOD_NAME(ser, folded_image, output_filename):
    cnt = 0
    print('Please reset the device!')
    if (folded_image is None):
        print("image is captured from camera, result is displayed here!")
    else:
        while True:
            rx = ser.readline()
            rrx = rx[0:len(rx)-1].decode(errors="ignore")
            if rrx == "":
                continue
            print(f"\r\n>> {rrx}")
            if rrx.startswith("READY"):
                break
        for i_seg in range(12):
            current_segment = folded_image[i_seg*4:(i_seg+1)*4, :, :] - 128
            # print(current_segment.min(), current_segment.max())
            tmplst = []
            for i in range(current_segment.shape[1]):
                for j in range(current_segment.shape[2]):
                    hex_arr = ''
                    for ch in range(4):
                        jj = 3 - ch
                        hex_curr = hex(current_segment[jj, i, j])[2:]
                        if len(hex_curr) == 1:
                            hex_curr = '0' + hex_curr
                        hex_arr = ' '.join([hex_arr, hex_curr])
                    tmplst.append(hex_arr[1:])
            for b in tmplst:
                # send 4 bytes
                bb=bytes.fromhex(b)
                ser.write(bb)
                # send crc8
                hash = crc8.crc8()
                hash.update(bb)
                crc=hash.digest()
                ser.write(crc)
                cnt += 1
                # reading = ser.readline()
                print(f'\r{(100*cnt)//92928}%',end="")
                #time.sleep(0.001)
            time.sleep(0.1)
    print('\nWaiting for CNN Output from MAX78000 board')
    while True:
        ser.timeout = 0.1
        #rx = bytearray()
        #rx = ser.read(1)
        #print(f">> {rx}")
        rx = ser.readline()
        if len(rx) > 0: 
            rrx = rx[0:len(rx)-1].decode(errors="ignore")
            print(f">> {rrx}")
            if "SENDING_OUTPUT" in rrx:
                break
    rx_list = []
    print('\nGetting CNN Output\n')
    while len(rx_list) < 16:
        ser.timeout = 0.1
        rx = bytearray()
        while len(rx) < (4*88*88):
            temp = ser.read()
            if temp:
                rx.append(temp[0])
        rx_list.append(rx)
        print(f'\r{len(rx_list)}/16',end="")
    ser.close()
    print(f'\nSaving to the {output_filename}')
    with open(output_filename, "w") as f:
        for rx in rx_list:
            for i in range(len(rx)//4):
                tmp = rx[4*i:(4*i+4)]
                hex_num = '0x' + ''.join(format(x, '02x') for x in tmp[::-1])
                f.write(hex_num + ',')
            f.write('\n')        
    print('Output saved.')