Skip to content

Commit

Permalink
WIP: also compute max, min of ROI
Browse files Browse the repository at this point in the history
  • Loading branch information
ZLLentz committed Dec 20, 2024
1 parent 7c2ec6c commit ef273c5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions camviewer_ui_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ def __init__(
self.updateRoiText()
self.updateMarkerText(True, True, 0, 15)

self.max_px = 0
self.min_px = 0

sizeProjX = QSize(self.viewwidth, self.projsize)
self.ui.projH.doResize(sizeProjX)

Expand Down Expand Up @@ -1378,13 +1381,16 @@ def updateProj(self):
projXmax,
projYmin,
projYmax,
self.max_px,
self.min_px,
) = pycaqtimage.pyUpdateProj(
self.imageBuffer,
self.ui.checkBoxProjAutoRange.isChecked(),
self.iRangeMin,
self.iRangeMax,
self.ui.display_image.rectRoi.oriented(),
)
print(self.min_px, self.max_px)
(projXmin, projXmax) = self.ui.projH.makeImage(
projXmin, projXmax, projYmin, projYmax
)
Expand Down
23 changes: 21 additions & 2 deletions pycaqtimage/pycaqtimage.sip
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ struct ImageBuffer
int imgwidth, imgheight;
int size;
int iRoiW, iRoiH;
uint32_t max_px, min_px;

int32_t iProjXmin, iProjXmax;
int32_t iProjYmin, iProjYmax;
Expand Down Expand Up @@ -271,6 +272,8 @@ PyObject* pyCreateImageBuffer(QImage* imageDisp, PyObject *px_, PyObject *py_, P
memset(imageBuffer->projSumY, 0, leny * sizeof(double) );
memset(imageBuffer->imageData, 0, imageBuffer->size * sizeof(uint32_t) );
memset(imageBuffer->imageDataF, 0, imageBuffer->size * sizeof(float) );
imageBuffer->max_px = 0;
imageBuffer->min_px = 0;

PyObject* pyImageBuffer = PyCapsule_New(imageBuffer, PYC_IB, _pyFreeImageBuffer);
return pyImageBuffer;
Expand Down Expand Up @@ -506,6 +509,8 @@ static void _computeRoiProj(ImageBuffer* imageBuffer, QRectF* rectRoi, bool bPro
double* projSumY = imageBuffer->projSumY;
int width = imageBuffer->imgwidth;
int height = imageBuffer->imgheight;
uint32_t max_px = 0;
uint32_t min_px = 4294967295;

for (int iX = 0; iX < width; projSumX[iX++] = 0);
for (int iY = 0; iY < height; projSumY[iY++] = 0);
Expand Down Expand Up @@ -557,9 +562,14 @@ static void _computeRoiProj(ImageBuffer* imageBuffer, QRectF* rectRoi, bool bPro
u64PixelSum += iValue;
/* Sigh... if iValue > 49000 or so, the square of an int will be negative! */
u64PixelSqSum += iValue*(uint64_t) iValue;
max_px = std::max(iValue, max_px);
min_px = std::min(iValue, min_px);
}
}

imageBuffer->max_px = max_px;
imageBuffer->min_px = min_px;

imageBuffer->iRoiW = x2 - x1 + 1;
imageBuffer->iRoiH = y2 - y1 + 1;
const float w = imageBuffer->iRoiW;
Expand Down Expand Up @@ -641,8 +651,17 @@ PyObject* pyUpdateProj(PyObject* pyImageBuffer, bool bProjAutoRange,
imageBuffer->iProjYmax = uMax;
}

return Py_BuildValue("ffiiii", imageBuffer->fRoiPixelMean, imageBuffer->fRoiPixelVar,
imageBuffer->iProjXmin, imageBuffer->iProjXmax, imageBuffer->iProjYmin, imageBuffer->iProjYmax);
return Py_BuildValue(
"ffiiiiii",
imageBuffer->fRoiPixelMean,
imageBuffer->fRoiPixelVar,
imageBuffer->iProjXmin,
imageBuffer->iProjXmax,
imageBuffer->iProjYmin,
imageBuffer->iProjYmax,
imageBuffer->max_px,
imageBuffer->min_px
);
}

/*
Expand Down

0 comments on commit ef273c5

Please sign in to comment.