Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ imutils
matplotlib
pytest
pytz

psutil
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
'imutils',
'matplotlib',
'pytz',
'psutil',
],
requires=["setuptools", "cython", "numpy"]
)
4 changes: 2 additions & 2 deletions src/c_modules/fine_movement/module/imagedeform.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static int ImageDeform_init(PyObject *_self, PyObject *args, PyObject *kwds)
return image_deform_init(&self->deform, grid_w, grid_h, image_w, image_h);
}

static void ImageDeform_finalize(PyObject *_self)
static void ImageDeform_dealloc(PyObject *_self)
{
PyObject *error_type, *error_value, *error_traceback;

Expand Down Expand Up @@ -182,6 +182,6 @@ PyTypeObject ImageDeform = {
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew,
.tp_init = ImageDeform_init,
.tp_finalize = ImageDeform_finalize,
.tp_dealloc = ImageDeform_dealloc,
.tp_methods = ImageDeform_methods,
};
4 changes: 2 additions & 2 deletions src/c_modules/fine_movement/module/imagedeform_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static int ImageDeformGC_init(PyObject *_self, PyObject *args, PyObject *kwds)
return 0;
}

static void ImageDeformGC_finalize(PyObject *_self)
static void ImageDeformGC_dealloc(PyObject *_self)
{
struct ImageDeformGlobalCorrelatorObject *self =
(struct ImageDeformGlobalCorrelatorObject *)_self;
Expand Down Expand Up @@ -136,6 +136,6 @@ PyTypeObject ImageDeformGC = {
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew,
.tp_init = ImageDeformGC_init,
.tp_finalize = ImageDeformGC_finalize,
.tp_dealloc = ImageDeformGC_dealloc,
.tp_methods = ImageDeformGC_methods,
};
4 changes: 2 additions & 2 deletions src/c_modules/fine_movement/module/imagedeform_lc.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static int ImageDeformLC_init(PyObject *_self, PyObject *args, PyObject *kwds)
return 0;
}

static void ImageDeformLC_finalize(PyObject *_self)
static void ImageDeformLC_dealloc(PyObject *_self)
{
struct ImageDeformLocalCorrelatorObject *self =
(struct ImageDeformLocalCorrelatorObject *)_self;
Expand Down Expand Up @@ -132,6 +132,6 @@ PyTypeObject ImageDeformLC = {
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew,
.tp_init = ImageDeformLC_init,
.tp_finalize = ImageDeformLC_finalize,
.tp_dealloc = ImageDeformLC_dealloc,
.tp_methods = ImageDeformLC_methods,
};
4 changes: 2 additions & 2 deletions src/c_modules/fine_movement/module/imagegrid.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int ImageGrid_init(PyObject *_self, PyObject *args, PyObject *kwds)
* \brief Destroy ImageGrid
* \param _self ImageGridObject object
*/
static void ImageGrid_finalize(PyObject *_self)
static void ImageGrid_dealloc(PyObject *_self)
{
PyObject *error_type, *error_value, *error_traceback;

Expand Down Expand Up @@ -167,6 +167,6 @@ PyTypeObject ImageGrid = {
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew,
.tp_init = ImageGrid_init,
.tp_finalize = ImageGrid_finalize,
.tp_dealloc = ImageGrid_dealloc,
.tp_methods = ImageGrid_methods,
};
4 changes: 2 additions & 2 deletions src/c_modules/movements/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static int SphereMovements_init(PyObject *_self, PyObject *args, PyObject *kwds)
return 0;
}

static void SphereMovements_finalize(PyObject *_self)
static void SphereMovements_dealloc(PyObject *_self)
{
PyObject *error_type, *error_value, *error_traceback;

Expand Down Expand Up @@ -218,7 +218,7 @@ static PyTypeObject _SphereMovement = {
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew,
.tp_init = SphereMovements_init,
.tp_finalize = SphereMovements_finalize,
.tp_dealloc = SphereMovements_dealloc,
.tp_methods = _SphereMovements_methods,
};

Expand Down
40 changes: 39 additions & 1 deletion tests/test_fine_shift.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2023 Vladislav Tsendrovskii
# Copyright (c) 2023-2024 Vladislav Tsendrovskii
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -16,6 +16,8 @@
import sys
import os
import numpy as np
import gc
import psutil

from vstarstack.library.loaders.classic import readjpeg
from vstarstack.library.fine_movement.module import ImageGrid
Expand Down Expand Up @@ -229,3 +231,39 @@ def test_approximate_by_correlation1():
assert data.shape[2] == 2
assert np.amin(data) == 0
assert np.amax(data) == 0

def test_memory_leak():
N = 5
df1 = next(readjpeg(os.path.join(dir_path, "fine_shift/image1.png")))
df2 = next(readjpeg(os.path.join(dir_path, "fine_shift/image1.png")))

image = df1.get_channel("L")[0].astype('double')
image_ref = df2.get_channel("L")[0].astype('double')

w = image.shape[1]
h = image.shape[0]

prevd = 0
memory1 = psutil.Process().memory_info().rss
deltas = []

for _ in range(N):
grid = ImageGrid(image_w=w, image_h=h)
grid.fill(image)
grid_ref = ImageGrid(image_w=w, image_h=h)
grid_ref.fill(image_ref)

lc = ImageDeformLC(image_w=w, image_h=h, pixels=1)
deform = lc.find(grid, None, grid_ref, None, 5, 5, 1)

lc = None
deform = None
grid = None
grid_ref = None

gc.collect()
memory2 = psutil.Process().memory_info().rss
print(memory1, memory2, memory2 - memory1, memory2 - memory1 - prevd)
deltas.append(memory2 - memory1 - prevd)
prevd = memory2 - memory1
assert deltas[-1] == 0