Skip to main content

Python wrappers for native image filter libraries (CPU, CUDA, OpenACC).

Project description

myPyImageFilters

Resumen

  • Propósito: Biblioteca Python que actúa como wrapper sobre librerías nativas (C/CUDA/OpenACC) para aplicar filtros de imagen (RGB->Gris, Gaussian Blur, Sobel).
  • Ubicación: Código Python en src/. Las librerías nativas compartidas deben estar en ./bin/.

Estructura

  • src/: Contiene los wrappers Python:
    • cpu_image_lib.py : wrapper para bin/libfiltersseq.so (implementación secuencial / CPU)
    • cuda_image_lib.py: wrapper para bin/libfilterscuda.so (implementación usando CUDA)
    • openacc_image_lib.py: wrapper para bin/libfiltersacc.so (implementación usando OpenACC / nvc)
  • bin/: Debería contener las bibliotecas compartidas .so generadas desde el código C/C++/CUDA/OpenACC.

Requisitos

  • Python 3.x
  • ctypes (parte de la stdlib)
  • Bibliotecas nativas compiladas y colocadas en ./bin/:
    • libfiltersseq.so (CPU)
    • libfilterscuda.so (CUDA)
    • libfiltersacc.so (OpenACC)
  • Para CUDA: controlador NVIDIA y CUDA Toolkit instalados.
  • Para OpenACC (nvc): NVIDIA HPC SDK (o compilador compatible) y runtime disponibles.

Compilación (resumen)

  • Si el proyecto incluye un Makefile en la raíz, prueba:
make
  • Si no hay Makefile, ejemplos genéricos de compilación (ajusta según fuentes reales):
# Compilar versión secuencial (C)
gcc -fPIC -shared -o bin/libfiltersseq.so src_c/*.c -I/path/to/include -lm

# Compilar versión CUDA
nvcc -Xcompiler -fPIC --shared -o bin/libfilterscuda.so src_cuda/*.cu src_c/*.c -I/path/to/include

# Compilar versión OpenACC (nvc)
nvc -acc -Minfo=accel -fPIC -shared -o bin/libfiltersacc.so src_openacc/*.c src_c/*.c -I/path/to/include
  • Si usas libfiltersacc.so, puede ser necesario exportar LD_LIBRARY_PATH para encontrar dependencias en tiempo de ejecución:
export LD_LIBRARY_PATH=/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/compilers/lib:$LD_LIBRARY_PATH

Uso (ejemplos)

  • Ejemplo con la implementación CPU (src/cpu_image_lib.py):
from src.cpu_image_lib import CPUFilterLib

lib = CPUFilterLib()
lib.rgb_to_gray('input.jpg', 'out_gray.jpg')
lib.gaussian_blur('input.jpg', 'out_blur.jpg', kernel_dim=5, stdev=2.0)
lib.sobel('input.jpg', 'out_sobel.jpg')
  • Ejemplo con CUDA (src/cuda_image_lib.py):
from src.cuda_image_lib import CudaImageLib

lib = CudaImageLib()
lib.rgb_to_gray('input.jpg', 'out_gray_cuda.jpg')
lib.gaussian_blur('input.jpg', 'out_blur_cuda.jpg', kernel_dim=7, stdev=2.0)
lib.sobel('input.jpg', 'out_sobel_cuda.jpg')
  • Ejemplo con OpenACC (src/openacc_image_lib.py):
from src.openacc_image_lib import OpenACCFilterLib

lib = OpenACCFilterLib()
lib.rgb_to_gray('input.jpg', 'out_gray_acc.jpg')
lib.gaussian_blur('input.jpg', 'out_blur_acc.jpg', kernel_dim=5, stdev=10.0)
lib.sobel('input.jpg', 'out_sobel_acc.jpg')

Detalles importantes (según wrappers)

  • Los wrappers usan ctypes y esperan que las funciones C expongan estas firmas (según cada archivo):

    • image2arr(const char *file) -> devuelve Image * (estructura CImage)
    • saveImg(Image *img, const char *filename) -> void
    • freeImage(Image *img) -> void (liberar memoria interna)
    • rgb2gray(Image *image) -> Image *
    • GaussianBlur(Image *image, int kdim, float stdev) -> Image *
    • Sobel(Image *image) -> Image *
  • Asegúrate de que los nombres de las funciones y la estructura Image en el código nativo coincidan con las expectativas del wrapper (CImage).

Solución de problemas

  • Error FileNotFoundError al cargar .so: verifica que los archivos existan en ./bin/ y que las rutas sean correctas.
  • OSError al cargar la librería OpenACC/CUDA: comprueba LD_LIBRARY_PATH y que los runtimes (CUDA, NVIDIA libs) estén disponibles.
  • Fallos en tiempo de ejecución o corrupciones de memoria: puede indicar incompatibilidad en la definición de struct Image entre C y el wrapper; revísala cuidadosamente.

Descargar en pip

pip install mypyimagefilters

Fin del README

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mypyimagefilters-0.1.3.tar.gz (706.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mypyimagefilters-0.1.3-py3-none-any.whl (707.9 kB view details)

Uploaded Python 3

File details

Details for the file mypyimagefilters-0.1.3.tar.gz.

File metadata

  • Download URL: mypyimagefilters-0.1.3.tar.gz
  • Upload date:
  • Size: 706.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for mypyimagefilters-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e03cdaf54c9ab6a4c82790ff9512d27df7c6e2a23b2a0aef8e0d499be5b6446e
MD5 ebf3186070c8db2d9d39a608a222b86b
BLAKE2b-256 6ade7de18c46c085705bce24c8691ccefb9ba2e58f1b4ed1787f9fd11b948b99

See more details on using hashes here.

File details

Details for the file mypyimagefilters-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mypyimagefilters-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c01c7a098a2998fbd629bdfbc4205fec472b19d9e72de5ec57386cd7ee561a09
MD5 2c7af50a0da3a415860ad13c5386e568
BLAKE2b-256 3e02019e91f42428f5fe15d3d4b3be5db8c01a25e1b1ba8af90852105bad2f37

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page