본문 바로가기
반응형

분류 전체보기574

[Python] convert uint16 to uint8 uint16 은 : 0 ~ 65535 uint8 은 0~255 (RGB 에서 사용하는 타입입니다) uint16에서 uint8 타입으로 변환하는데는 여러 방법이 있지만 normalize를 해야합니다. 단순히 im.astype('uint8') 로 해서는 데이터가 손실됩니다. opencv 사용 : cv2.normalize im_uint8 = cv2.normalize(im_uint16, None, 0, 255, cv2.NORM_MINMAX, dtype=cv2.CV_8U) Skimage 사용 : img_as_ubyte rom skimage import exposure, img_as_ubyte im_uint8 = img_as_ubyte(exposure.rescale_intensity(im_uint16)) 2020... 2021. 5. 28.
[Docker] Build 할때 no cache 옵션주기(--no-cache) Docker Build --no-cache 소스를 바꾸든 무슨 작업을 했는데, 빌드를 했더니 말도안되게 금방 이미지가 만들어졌다. '오~~(?) 뭔가 업데이트 하더니 빨라졌나보다' 하고 container run 했는데 반영이 안됨..-_-ㅋ 이럴 땐 docker build --no-cache -t something:tag . 2021. 5. 17.
[python] queue 를 list 로 (queue to list) list(que.queue) from queue import Queue que = Queue() que.put(111) que.put(222) que.put(333) results = list(que.queue) print(results) # results = [111, 222, 333] print(q.empty()) # False print(q.qsize()) # 3 print(q.get()) # 111 print(q.qsize()) # 2 print(results) # results = [111, 222, 333] 2021. 5. 4.
[Python] InvalidURL Url Encode / Url 한글 처리 InvalidURL urllib.request 를 사용할 때 Url 에 한글이나 특문이 있으면 오류가 발생할 수 있습니다. 아래와 같은 코드는 오류가 발생하죠. from urllib.request import Request, urlopen url = 'https://hello-bryan.tistory.com/manage/여기에 한글이 있다.txt' req = Request(url, headers={'User-Agent': 'Mozilla/5.0'}) res = urlopen(req) if res.status == 200: print('성공') else: print('실패코드 {}'.format(res.status)) InvalidURL URL 에 공백이 있어서 그렇죠. 그럼 공백을 빼고 한글만 있다면? .. 2021. 4. 20.
Python 으로 Crawling 에 필요한 준비 준비 할 사항만 체크해봅니다. 1. Chrome driver 링크 - 본인pc의 크롬 브라우저에 맞는 버전으로 다운로드하고 경로를 기억해둠. 2. python library 설치 - 또는 pip install 명령어 직접 실행. $ pip install selenium 3. Chrome driver 객체 생성 from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.desired_capabilities import DesiredCapabilities chrome_driver_path = 'C:/chromedriver/chromedriver_89/chrome.. 2021. 4. 15.
[C#] Class 를 file 로 저장/로드하기 (class to file, file to class) Serialize Class 를 File 로 저장/로드 대상 class 일단 아래와 같은 class 가 있고, 이 class 를 file 로 저장하려고 하면, 상단에 [Serializable] 을 붙혀줍니다. [Serializable] // 추가 public class CateInfo { public CateInfo(string name, string link, int depth) { this.name = name; this.link = link; this.depth = depth; } public string name { get; set; } public string link { get; set; } public int depth { get; set; } } using 및 선언 - 사용 할 class에서 // 상단에 u.. 2021. 4. 4.
[Python] remove list item. 리스트에서 아이템 삭제 방법(clear, pop, remove, del) Remove item from list 리스트에서 아이템 삭제하는 방법 # 삭제 관련 list function clear() : 모든 item 삭제 pop() : index 로 item을 가져오면서 삭제 remove() : value 로 item 삭제 # python function del : index 로 삭제 1. clear() my_list = [0,1,2,3,4,5] my_list.clear() print(my_list) # [] 2. pop() my_list = ['a', 'b', 'c', 'd', 'e'] one = my_list.pop(2) # index 2 의 값을 빼옴 print(one) # c print(my_list) # ['a', 'b', 'd', 'e'] # 뒤에서 인덱스 two .. 2021. 3. 25.
[Python] PIL jpg png webp 변환 Image.convert() from PIL import Image Image Conversion 이미지 형식 변환하기 Pillow library 를 이용합니다. # PIL 설치 pip install Pillow JPG -> PNG from PIL import Image im = Image.open('hello.jpg').convert('RGB') im.save('bryan.png', 'png') PNG -> JPG from PIL import Image im = Image.open('bryan.png').convert('RGB') im.save('hello.jpg', 'jpeg') JPG -> WEBP from PIL import Image im = Image.open('hello.jpg').convert('RGB') im.sav.. 2021. 3. 25.
[Python] json 파일에 주석 달기 json file 에 주석달기 config.json 이라는 파일의 내용이 아래와 같다고 합시다. { "name": "bryan",/* 여기에 설명 쓰고싶을 때 */ "title": "helllo", "url": "https://hello-bryan.tistory.com/", "bookmark": true /* 여기에도 주석 달고 싶을 때 */ } 이 파일을 json 로드한다면 오류가 나겠죠. with open('config.json') as f: json_data = json.load(f) # error 아래와 같이 사용하시면 됩니다. with open('config.json', 'r', encoding='utf-8') as f: contents = f.read() while "/*" in content.. 2021. 2. 11.
[Python] 숫자를 각 자리수의 list 로 변환 list(map(int, str(n))) n = 12345 n_list = list(map(int, str(n))) // [1, 2, 3, 4, 5] 또 다른 방법 [int(a) for a in str(12345)] 2021. 1. 26.
728x90
반응형