Skip to content

Instantly share code, notes, and snippets.

View prabhuiitdhn's full-sized avatar
🎯
Focusing

Prabhu Kumar prabhuiitdhn

🎯
Focusing
View GitHub Profile
@dmitriykovalev
dmitriykovalev / nv12_to_rgb.py
Last active February 20, 2025 05:14
Convert NV12 YUV image to RGB image using Python
import argparse
from PIL import Image
def nv12_to_rgb(nv12: bytes | bytearray, size: tuple[int, int]) -> Image:
w, h = size
n = w * h
y, u, v = nv12[:n], nv12[n + 0::2], nv12[n + 1::2]
yuv = bytearray(3 * n)
yuv[0::3] = y
yuv[1::3] = Image.frombytes('L', (w // 2, h // 2), u).resize(size).tobytes()
@Jim-Bar
Jim-Bar / YUV_formats.md
Last active April 29, 2025 12:51
About YUV formats

About YUV formats

First of all: YUV pixel formats and Recommended 8-Bit YUV Formats for Video Rendering. Chromium's source code contains good documentation about those formats too: chromium/src/media/base/video_types.h and chromium/src/media/base/video_frame.cc (search for RequiresEvenSizeAllocation(), NumPlanes() and those kinds of functions).

YUV?

You can think of an image as a superposition of several planes (or layers in a more natural language). YUV formats have three planes: Y, U, and V.

Y is the luma plane, and can be seen as the image as grayscale. U and V are reffered to as the chroma planes, which are basically the colours. All the YUV formats have these three planes, and differ by the different orderings of them.

# Print most common words in a corpus collected from Twitter
#
# Full description:
# http://marcobonzanini.com/2015/03/02/mining-twitter-data-with-python-part-1/
# http://marcobonzanini.com/2015/03/09/mining-twitter-data-with-python-part-2/
# http://marcobonzanini.com/2015/03/17/mining-twitter-data-with-python-part-3-term-frequencies/
#
# Run:
# python twitter_most_common_words.py <filename.jsonl>
@bonzanini
bonzanini / sentiment_classification.py
Last active October 30, 2020 23:58
Sentiment analysis with scikit-learn
# You need to install scikit-learn:
# sudo pip install scikit-learn
#
# Dataset: Polarity dataset v2.0
# http://www.cs.cornell.edu/people/pabo/movie-review-data/
#
# Full discussion:
# https://marcobonzanini.wordpress.com/2015/01/19/sentiment-analysis-with-python-and-scikit-learn
@petrklus
petrklus / rgb_to_kelvin.py
Last active May 10, 2025 11:06
Kelvin to RGB in python
"""
Based on: http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
Comments resceived: https://gist.github.com/petrklus/b1f427accdf7438606a6
Original pseudo code:
Set Temperature = Temperature \ 100
Calculate Red:
If Temperature <= 66 Then