21 #if defined(FFTW_AVAILABLE) 70 char c = tolower(s.FirstChar());
87 atexit (Raster::FinalCleanUp);
155 map<RasterPtr, RasterPtr>::iterator idx;
156 for (idx = allocatedRasterInstances.begin (); idx != allocatedRasterInstances.end (); ++idx)
160 << r->Height () <<
"\t" 161 << r->Width () <<
"\t" 205 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
206 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
207 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
208 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
209 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
210 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
211 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
212 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
216 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
217 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
218 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
219 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
220 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
221 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
222 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
223 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15
351 AllocateImageArea ();
397 AllocateImageArea ();
437 AllocateImageArea ();
441 for (row = 0; row <
height; row++)
444 memcpy (green[row], imageRow, width);
448 memcpy (blue[row], blueRow, width);
451 memcpy (red[row], redRow, width);
492 AllocateImageArea ();
494 memcpy (greenArea, _raster.greenArea, totPixels);
500 memcpy (redArea, _raster.redArea, totPixels);
501 memcpy (blueArea, _raster.blueArea, totPixels);
506 AllocateFourierMagnitudeTable ();
508 memcpy (fourierMagArea, _raster.fourierMagArea,
sizeof (
float) * totPixels);
691 uchar* _grayScaleData,
692 uchar** _grayScaleRows
718 green (_grayScaleRows),
729 const uchar* _grayScaleData
760 AllocateImageArea ();
762 memcpy (greenArea, _grayScaleData, totPixels);
768 const uchar* _redChannel,
769 const uchar* _greenChannel,
770 const uchar* _blueChannel
801 AllocateImageArea ();
802 if ((!_redChannel) || (!_greenChannel) || (!_blueChannel))
805 errMsg <<
"Raster::Raster ***ERROR*** One of the provided channels is 'NULL'.";
806 cerr << std::endl << std::endl << errMsg << std::endl << std::endl;
813 errMsg <<
"Raster::Raster ***ERROR*** Not all channels were allocated.";
814 cerr << std::endl << std::endl << errMsg << std::endl << std::endl;
818 memcpy (redArea, _redChannel, totPixels);
819 memcpy (greenArea, _greenChannel, totPixels);
820 memcpy (blueArea, _blueChannel, totPixels);
834 void Raster::CleanUpMemory ()
859 DeleteExistingBlobIds ();
876 pixelMem = pixelMem * 3;
878 kkint32 memoryConsumedEstimated =
884 sizeof (
uchar*) * 3 +
885 sizeof (
uchar**) * 3 +
886 sizeof (
float*) * 1 +
887 sizeof (
float**) * 1 +
893 return memoryConsumedEstimated;
907 AllocateImageArea ();
919 uchar* _grayScaleData,
920 uchar** _grayScaleRows,
930 if (_grayScaleData == NULL)
931 throw KKException ("Raster::Initialize _grayScaleData == NULL");
933 if (_grayScaleRows == NULL)
934 throw KKException ("Raster::Initialize _grayScaleRows == NULL");
937 green = _grayScaleRows;
962 if ((_red == NULL) || (_redArea == NULL) ||
963 (_green == NULL) || (_greenArea == NULL) ||
964 (_blue == NULL) || (_blueArea == NULL)
966 throw KKException ("Raster::Initialize One or more of the Color channels == NULL");
1038 return new Raster (_raster
, _row
, _col
, _height
, _width
);
1058 return (ForegroundPixel (
green[row][col]));
1088 kkint32 totalBackgroundPixels = 0;
1092 ++totalBackgroundPixels;
1094 return totalBackgroundPixels;
1105 float centroidColWeighted;
1106 float centroidRowWeighted;
1121 float centroidColWeighted;
1122 float centroidRowWeighted;
1138 kkint32 newWidth = oldWidth + 2 * padding;
1139 kkint32 newHeight = oldHeight + 2 * padding;
1151 kkint32 paddedForgroudPixelCount = 0;
1153 for (row = 0; row < oldHeight; row++)
1158 for (col = 0; col < oldWidth; col++)
1160 if (oldRow[col] > 0)
1161 paddedForgroudPixelCount++;
1163 newRows[newRow][newCol] = oldRow[col];
1172 return paddedRaster;
1219 void Raster::AllocateImageArea ()
1227 cerr << std::endl << std::endl
1228 <<
"Raster::AllocateImageArea ***ERROR*** Error allocating memory" << std::endl
1236 memset (greenArea, backgroundPixelValue, totPixels);
1242 memset (redArea, backgroundPixelValue, totPixels);
1245 memset (blueArea, backgroundPixelValue, totPixels);
1256 for (row = 0; row <
height; row++)
1258 green[row] = greenPtr;
1259 greenPtr = greenPtr +
width;
1264 redPtr = redPtr +
width;
1266 blue[row] = bluePtr;
1267 bluePtr = bluePtr +
width;
1273 void Raster::AllocateFourierMagnitudeTable ()
1283 rowPtr = rowPtr +
width;
1297 cerr <<
"Raster::GetPixelValue *** ERROR ***, Raster Dimensions Exceeded." << std::endl;
1298 cerr <<
" Height[" << height <<
"] Width[" << width <<
"]." << std::endl;
1299 cerr <<
" Row[" << row <<
"] Col[" << col <<
"]." << std::endl;
1303 return green[row][col];
1320 cerr <<
"Raster::GetPixelValue *** ERROR ***, Raster Dimensions Exceeded." << std::endl;
1321 cerr <<
" Height[" << height <<
"] Width[" << width <<
"]." << std::endl;
1322 cerr <<
" Row[" << row <<
"] Col[" << col <<
"]." << std::endl;
1326 g =
green [row][col];
1331 b =
blue [row][col];
1366 cerr <<
"Raster::GetPixelValue *** ERROR ***, Raster Dimensions Exceeded." << std::endl;
1367 cerr <<
" Height[" << height <<
"] Width[" << width <<
"]." << std::endl;
1368 cerr <<
" Row[" << row <<
"] Col[" << col <<
"]." << std::endl;
1373 return green [row][col];
1377 cerr <<
"***ERROR*** Raster::GetPixelValue *** ERROR ***, Not a Color Raster." << std::endl;
1382 return red [row][col];
1384 return blue[row][col];
1400 cerr <<
"***ERROR*** Raster::SetPixelValue *** ERROR ***, Raster Dimensions Exceeded." << std::endl;
1401 cerr <<
" Height[" << height <<
"] Width[" << width <<
"]." << std::endl;
1402 cerr <<
" Row[" << row <<
"] Col[" << col <<
"]." << std::endl;
1406 green[row][col] = pixVal;
1423 cerr <<
"***ERROR*** Raster::SetPixelValue *** ERROR ***, Raster Dimensions Exceeded." << std::endl;
1424 cerr <<
" Height[" << height <<
"] Width[" << width <<
"]." << std::endl;
1425 cerr <<
" Row[" << row <<
"] Col[" << col <<
"]." << std::endl;
1432 red [row][col] = pixVal
.r;
1433 blue [row][col] = pixVal
.b;
1462 cerr <<
"***ERROR*** Raster::SetPixelValue *** ERROR ***, Raster Dimensions Exceeded." << std::endl;
1463 cerr <<
" Height[" << height <<
"] Width[" << width <<
"]." << std::endl;
1464 cerr <<
" Row[" << row <<
"] Col[" << col <<
"]." << std::endl;
1468 green[row][col] = g;
1472 blue [row][col] = b;
1490 cerr <<
"***ERROR*** Raster::SetPixelValue *** ERROR ***, Raster Dimensions Exceeded." << std::endl;
1491 cerr <<
" Height[" << height <<
"] Width[" << width <<
"]." << std::endl;
1492 cerr <<
" Row[" << row <<
"] Col[" << col <<
"]." << std::endl;
1498 green[row][col] = pixVal;
1504 cerr <<
"***ERROR*** Raster::SetPixelValue *** ERROR ***, Not a Color Raster." << std::endl;
1508 red [row][col] = pixVal;
1510 blue [row][col] = pixVal;
1518 for (
kkint32 edgeIdx = 0; edgeIdx < edgeWidth; ++edgeIdx)
1523 for (
int c = 0; c <
width; ++c)
1532 for (
int r = 0; r <
height; ++r)
1558 int hashPos = (
int)((
float)x * pixelsPerMinor + 0.5f);
1559 if (hashPos >= (
height - hashLen))
1562 if ((x % minorsPerMajor) == 0)
1579 int hashPos = (
int)((
float)x * pixelsPerMinor + 0.5f);
1580 if (hashPos >=
width)
1583 if ((x % minorsPerMajor) == 0)
1607 if ((row < 0) || (row >=
height))
1610 if ((col < 0) || (col >=
width))
1613 if (ForegroundPixel (
green[row][col]))
1616 totVal = totVal +
green[row][col];
1628 kkint32 resultForegroundPixelCount = 0;
1635 uchar numNeighbors = 0;
1637 uchar* resultRow = NULL;
1639 for (row = 0; row <
height; row++)
1641 resultRow = resultRows[row];
1642 for (col = 0; col <
width; col++)
1644 if (BackgroundPixel (resultRow[col]))
1650 CalcDialatedValue (row - 1, col - 1, totValue, numNeighbors);
1651 CalcDialatedValue (row - 1, col, totValue, numNeighbors);
1652 CalcDialatedValue (row - 1, col + 1, totValue, numNeighbors);
1654 CalcDialatedValue (row , col - 1, totValue, numNeighbors);
1655 CalcDialatedValue (row , col + 1, totValue, numNeighbors);
1657 CalcDialatedValue (row + 1, col - 1, totValue, numNeighbors);
1658 CalcDialatedValue (row + 1, col , totValue, numNeighbors);
1659 CalcDialatedValue (row + 1, col + 1, totValue, numNeighbors);
1661 if (numNeighbors > 0)
1663 resultRow[col] = (
uchar)(totValue / numNeighbors);
1664 resultForegroundPixelCount++;
1669 resultForegroundPixelCount++;
1724 kkint32 resultForegroundPixelCount = 0;
1725 uchar* resultRow = NULL;
1727 for (row = 0; row <
height; row++)
1729 resultRow = resultRows[row];
1730 for (col = 0; col <
width; col++)
1732 if (BackgroundPixel (resultRow[col]))
1734 pixelValue = Hit (mask, row, col);
1735 resultRow[col] = pixelValue;
1736 if (!BackgroundPixel (pixelValue))
1737 resultForegroundPixelCount++;
1741 resultForegroundPixelCount++;
1815 memset (destArea, 0, totPixels);
1822 uchar* srcRow0 = srcRows[0];
1823 uchar* srcRow1 = srcRows[1];
1827 uchar* destRow0 = destRows[0];
1829 for (c = 1; c < (
width - 1); ++c)
1843 destRowBot[c] = 255;
1852 for (r = 1; r < (
height - 1); ++r)
1859 destRows[r][0] = 255;
1869 destRows[r][
width - 1] = 255;
1878 for (r = 1; r < (
height - 1); ++r)
1880 uchar* srcRow0 = srcRows[r - 1];
1881 uchar* srcRow1 = srcRows[r ];
1882 uchar* srcRow2 = srcRows[r + 1];
1884 for (c = 1; c < (
width - 1); ++c)
1891 destRows[r][c] = 255;
1916 memset (destArea, 0, totPixels);
1924 for (r = 0; r <
height; ++r)
1926 for (c = 0; c <
width; ++c)
1928 if (IsThereANeighbor (mask, r, c))
1930 destRows[r][c] = 255;
1954 tlRow = Min (tlRow, height - 1);
1955 brRow = Min (brRow, height - 1);
1957 tlCol = Min (tlCol, width - 1);
1958 brCol = Min (brCol, width - 1);
1960 for (
kkint32 row = tlRow; row <= brRow; ++row)
1967 for (
kkint32 col = tlCol; col <= brCol; ++col)
1969 rowRed [col] = fillColor
.r;
1970 rowGreen[col] = fillColor
.g;
1971 rowBlue [col] = fillColor
.b;
1977 for (
kkint32 col = tlCol; col <= brCol; ++col)
1978 rowGreen[col] = fillColor
.g;
1992 expandList.PushOnBack (
new Point (_row, _col));
1994 while (expandList.QueueSize () > 0)
1996 PointPtr nextPixel = expandList.PopFromFront ();
1998 kkint32 r = nextPixel->Row ();
1999 kkint32 c = nextPixel->Col ();
2001 green[r][c] = foregroundPixelValue;
2005 if (BackgroundPixel (green[r - 1][c]))
2007 green[r - 1][c] = foregroundPixelValue;
2008 expandList.PushOnBack (
new Point (r - 1, c));
2012 if (r < (height - 1))
2014 if (BackgroundPixel (green[r + 1][c]))
2016 green[r + 1][c] = foregroundPixelValue;
2017 expandList.PushOnBack (
new Point (r + 1, c));
2023 if (BackgroundPixel (green[r][c - 1]))
2025 green[r][c - 1] = foregroundPixelValue;
2026 expandList.PushOnBack (
new Point (r, c - 1));
2030 if (c < (width - 1))
2032 if (BackgroundPixel (green[r][c + 1]))
2034 green[r][c + 1] = foregroundPixelValue;
2035 expandList.PushOnBack (
new Point (r, c + 1));
2039 delete nextPixel; nextPixel = NULL;
2058 for (c = 0; c <
width; c++)
2060 if (BackgroundPixel (maskRows[0][c]))
2061 mask.FillHoleGrow (0, c);
2063 if (BackgroundPixel (maskRows[lastRow][c]))
2064 mask.FillHoleGrow (lastRow, c);
2067 for (r = 0; r <
height; r++)
2069 if (BackgroundPixel (maskRows[r][0]))
2070 mask.FillHoleGrow (r, 0);
2072 if (BackgroundPixel (maskRows[r][lastCol]))
2073 mask.FillHoleGrow (r, lastCol);
2079 uchar* curRow = NULL;
2080 for (r = 0; r <
height; r++)
2083 for (c = 0; c <
width; c++)
2085 if (BackgroundPixel (curRow[c]))
2087 if (BackgroundPixel (maskRows[r][c]))
2118 memset (maskArea, 0, totPixels);
2130 uchar* rowTop = maskRows[0];
2133 for (c = 0; c <
width; ++c)
2144 uchar* leftCol = maskArea;
2146 for (r = 0; r <
height; ++r)
2161 bool fillInFound =
false;
2164 fillInFound =
false;
2167 uchar* rowPrev = maskArea;
2171 for (r = 1; r < (
height - 1); ++r)
2173 for (c = 1; c < (
width - 1); ++c)
2177 if ((rowPrev[c ] == 1) ||
2178 (rowCur [c - 1] == 1) ||
2179 (rowCur [c + 1] == 1) ||
2196 rowPrev = maskRows[
height - 1];
2197 rowCur = rowPrev -
width;
2198 rowNext = rowCur -
width;
2200 for (r = (
height - 2); r > 0; --r)
2202 for (c = (
width - 2); c > 0; --c)
2206 if ((rowPrev[c ] == 1) ||
2207 (rowCur [c - 1] == 1) ||
2208 (rowCur [c + 1] == 1) ||
2222 }
while (fillInFound);
2229 if (maskArea[x] == 0)
2255 uchar* rowLast = NULL;
2256 uchar* rowCur = NULL;
2257 uchar* rowNext = NULL;
2259 for (r = 1; r < lastRow; r++)
2261 rowLast = origRows[r - 1];
2262 rowCur = origRows[r ];
2263 rowNext = origRows[r + 1];
2265 for (c = 1; c < lastCol; c++)
2267 if (!BackgroundPixel (
green[r][c]))
2301 kkint32 maskRowStart = 0 - bias;
2302 kkint32 maskRowEnd = 0 + bias;
2303 kkint32 maskColStart = 0 - bias;
2304 kkint32 maskColEnd = 0 + bias;
2312 uchar* tempRowData = NULL;
2315 for (r = 0; r <
height; r++)
2317 maskColStart = 0 - bias;
2318 maskColEnd = 0 + bias;
2320 tempRowData = tempGreen[r];
2322 for (c = 0; c <
width; c++)
2324 if (ForegroundPixel (
green[r][c]))
2327 if ((maskRowStart < 0) || (maskRowEnd >=
height) || (maskColStart < 0) || (maskColStart >=
width))
2332 for (maskRow = maskRowStart; ((maskRow <= maskRowEnd) && fit); maskRow++)
2334 tempRowData = tempGreen[maskRow];
2335 for (maskCol = maskColStart; maskCol <= maskColEnd; maskCol++)
2337 if (BackgroundPixel (tempRowData[maskCol]))
2348 for (maskRow = maskRowStart; maskRow <= maskRowEnd; maskRow++)
2350 if (BackgroundPixel (tempGreen[maskRow][c]))
2357 tempRowData = tempGreen[maskRow];
2358 for (maskCol = maskColStart; maskCol <= maskColEnd; maskCol++)
2360 if (BackgroundPixel (tempRowData[maskCol]))
2424 memset (destArea, 0, totPixels);
2431 uchar* srcRow0 = srcRows[0];
2432 uchar* srcRow1 = srcRows[1];
2436 uchar* destRow0 = destRows[0];
2438 for (c = 1; c < (
width - 1); ++c)
2452 destRowBot[c] = 255;
2461 for (r = 1; r < (
height - 1); ++r)
2468 destRows[r][0] = 255;
2478 destRows[r][
width - 1] = 255;
2487 for (r = 1; r < (
height - 1); ++r)
2489 uchar* srcRow0 = srcRows[r - 1];
2490 uchar* srcRow1 = srcRows[r ];
2491 uchar* srcRow2 = srcRows[r + 1];
2493 for (c = 1; c < (
width - 1); ++c)
2500 destRows[r][c] = 255;
2525 memset (destArea, 0, totPixels);
2532 for (r = 0; r <
height; ++r)
2535 for (c = 0; c <
width; ++c)
2537 if (ForegroundPixel (rowData[c]))
2539 if (Fit (mask, r, c))
2541 destRows[r][c] = 255;
2572 maskRowStart = 0 - bias;
2573 maskRowEnd = 0+ bias;
2574 maskColStart = 0 - bias;
2575 maskColEnd = 0 + bias;
2584 uchar* tempRowData = NULL;
2587 for (r = row- 150; r < row+150; r++)
2591 maskColStart = 0 - bias;
2592 maskColEnd = 0 + bias;
2594 tempRowData = tempGreen[r];
2596 for (c = col - 10; c < col + 10; c++)
2602 if (ForegroundPixel (
green[r][c]))
2605 if ((maskRowStart < row - 100) ||
2606 (maskRowEnd >= row + 100) ||
2607 (maskColStart < col - 10) ||
2608 (maskColStart >= col + 10)
2616 for (maskRow = row - 150; ((maskRow <= row + 150) && fit); maskRow++)
2618 tempRowData = tempGreen[maskRow];
2619 for (maskCol = col - 10; maskCol <= col + 10 ; maskCol++)
2621 if (BackgroundPixel (tempRowData[maskCol]))
2633 for (maskRow = row-20; maskRow <= row+20; maskRow++)
2635 if (BackgroundPixel (tempGreen[maskRow][c]))
2642 tempRowData = tempGreen[maskRow];
2643 for (maskCol = col-20; maskCol <= col+20; maskCol++)
2645 if (BackgroundPixel (tempRowData[maskCol]))
2686 maskRowStart = 0 - bias;
2687 maskRowEnd = 0 + bias;
2688 maskColStart = 0 - bias;
2689 maskColEnd = 0 + bias;
2700 uchar* tempRowData = NULL;
2703 for (r = row- 20; r < row+20; r++)
2708 maskColStart = 0 - bias;
2709 maskColEnd = 0 + bias;
2711 tempRowData = tempGreen[r];
2713 for (c = col - 150; c < col + 150; c++)
2719 if (ForegroundPixel (
green[r][c]))
2722 if ((maskRowStart < row - 50) ||
2723 (maskRowEnd >= row + 50) ||
2724 (maskColStart < col - 100) ||
2725 (maskColStart >= col+100)
2733 for (maskRow = row - 20; ((maskRow <= row + 20) && fit); maskRow++)
2735 tempRowData = tempGreen[maskRow];
2736 for (maskCol = col - 150; maskCol <= col + 150 ; maskCol++)
2738 if (BackgroundPixel (tempRowData[maskCol]))
2750 for (maskRow = row-20; maskRow <= row+20; maskRow++)
2752 if (BackgroundPixel (tempGreen[maskRow][c]))
2759 tempRowData = tempGreen[maskRow];
2760 for (maskCol = col-20; maskCol <= col+20; maskCol++)
2762 if (BackgroundPixel (tempRowData[maskCol]))
2799 kkint32 maskRowStart = 0 - bias;
2800 kkint32 maskRowEnd = 0 + bias;
2801 kkint32 maskColStart = 0 - bias;
2802 kkint32 maskColEnd = 0 + bias;
2812 uchar* tempRowData = NULL;
2816 for (r = 0; r <
height; r++)
2823 maskColStart = 0 - bias;
2824 maskColEnd = 0 + bias;
2826 tempRowData = tempGreen[r];
2828 for (c = 0; c <
width; c++)
2830 if ((c >= blobcolstart + 100) && (c <= blobcolend - 100))
2835 if (ForegroundPixel (
green[r][c]))
2838 if ((maskRowStart < 0) ||
2839 (maskRowEnd >=
height) ||
2840 (maskColStart < 0) ||
2841 (maskColStart >=
width)
2849 for (maskRow = maskRowStart; ((maskRow <= maskRowEnd) && fit); maskRow++)
2851 tempRowData = tempGreen[maskRow];
2852 for (maskCol = maskColStart; maskCol <= maskColEnd; maskCol++)
2854 if (BackgroundPixel (tempRowData[maskCol]))
2865 for (maskRow = maskRowStart; maskRow <= maskRowEnd; maskRow++)
2867 if (BackgroundPixel (tempGreen[maskRow][c]))
2874 tempRowData = tempGreen[maskRow];
2875 for (maskCol = maskColStart; maskCol <= maskColEnd; maskCol++)
2877 if (BackgroundPixel (tempRowData[maskCol]))
2913 uchar* srcRow = NULL;
2915 uchar* destRow = NULL;
2919 for (r = 0; r <
height; ++r)
2921 destRow = destGreen[r];
2924 for (c = 0; c <
width; ++c)
2926 if (ForegroundPixel (srcRow[c]))
2928 if (!Fit (mask, r, c))
2931 erodedForegroundPixelCount--;
2939 return erodedRaster;
2990 if (BackgroundPixel (
green[row - 1][col - 1]))
2994 if (BackgroundPixel (
green[row - 1][col]))
2997 if (col < (
width - 1))
2999 if (BackgroundPixel (
green[row - 1][col + 1]))
3006 if (BackgroundPixel (
green[row][col - 1]))
3010 if (BackgroundPixel (
green[row][col]))
3013 if (col < (
width - 1))
3015 if (BackgroundPixel (
green[row][col + 1]))
3023 if (BackgroundPixel (
green[row + 1][col - 1]))
3027 if (BackgroundPixel (
green[row + 1][col]))
3030 if (row < (
width - 1))
3032 if (BackgroundPixel (
green[row + 1][col + 1]))
3065 uchar* origRowLast = NULL;
3066 uchar* origRowCur = NULL;
3067 uchar* origRowNext = NULL;
3074 for (r = 1; r < lastRow; ++r)
3076 origRowLast = origRows[r - 1];
3077 origRowCur = origRows[r];
3078 origRowNext = origRows[r + 1];
3080 uchar* destRow = destRows[r];
3082 for (c = 1; c < lastCol; c++)
3084 if (ForegroundPixel (origRowCur[c]))
3086 if ((ForegroundPixel (origRowLast [c - 1])) &&
3087 (ForegroundPixel (origRowLast [c] )) &&
3088 (ForegroundPixel (origRowLast [c + 1])) &&
3089 (ForegroundPixel (origRowCur [c - 1])) &&
3090 (ForegroundPixel (origRowCur [c] )) &&
3091 (ForegroundPixel (origRowCur [c + 1])) &&
3092 (ForegroundPixel (origRowNext [c - 1])) &&
3093 (ForegroundPixel (origRowNext [c] )) &&
3094 (ForegroundPixel (origRowNext [c + 1]))
3120 if ((row < 0) || (row >=
height) ||
3121 (col < 0) || (col >=
width))
3138 kkint32 c, r, startCol, blobID;
3142 for (r = row - dist; r < row; ++r)
3146 for (c = startCol; c <= col; ++c)
3151 if (blobID > nearestBlob)
3152 nearestBlob = blobID;
3176 for (r = row - dist; r < row; ++r)
3180 if (endCol >=
width)
3183 for (c = col + 1; c <= endCol; ++c)
3186 if (blobID > nearestBlob)
3187 nearestBlob = blobID;
3202 uchar* curRow = NULL;
3203 kkint32* curRowBlobIds = NULL;
3208 BlobPtr curBlob = NULL;
3218 for (row = 0; row <
height; ++row)
3220 curRow =
green[row];
3228 if (ForegroundPixel (curRow[col]))
3230 blankColsInARow = 0;
3232 nearBlobId = NearestNeighborUpperLeft (row, col, dist);
3234 nearBlobId = NearestNeighborUpperRight (row, col, dist);
3239 if (nearBlobId >= 0)
3241 if (nearBlobId != curBlobId)
3244 curBlobId = curBlob
->Id ();
3248 curRowBlobIds[col] = curBlobId;
3249 curBlob->colRight = Max (curBlob->colRight, col);
3250 curBlob->rowBot = Max (curBlob->rowBot, row);
3256 if (nearBlobId >= 0)
3260 curBlobId = curBlob
->id;
3266 if (!curBlob)
throw KKException(" Raster::ExtractBlobs curBlob == NULL");
3268 curBlobId = curBlob
->id;
3276 KKStr errMsg =
"Raster::ExtractBlobs ***ERROR*** allocation of new 'curBlob' failed.";
3277 cerr << endl << errMsg << endl << endl;
3280 curBlobId = curBlob
->id;
3283 curRowBlobIds[col] = curBlobId;
3284 curBlob->colLeft = Min (curBlob->colLeft, col);
3285 curBlob->colRight = Max (curBlob->colRight, col);
3286 curBlob->rowBot = Max (curBlob->rowBot, row);
3287 curBlob->rowTop = Min (curBlob->rowTop, row);
3296 nearBlobId = NearestNeighborUpperLeft (row, col, dist);
3298 if (nearBlobId >= 0)
3300 if (nearBlobId != curBlobId)
3303 curBlobId = curBlob
->Id ();
3309 if (blankColsInARow > dist)
3340 BlobList::iterator idx;
3341 for (idx = blobs->begin (); idx != blobs->end (); ++idx)
3343 BlobPtr blob = idx->second;
3360 kkint32 rowStart = Min (blob->RowTop (), height - 1);
3361 kkint32 rowEnd = Min (blob->RowBot (), height - 1);
3362 kkint32 colStart = Min (blob->ColLeft (), width - 1);
3363 kkint32 colEnd = Min (blob->ColRight (), width - 1);
3365 for (row = rowStart; row <= rowEnd; ++row)
3367 for (col = colStart; col <= colEnd; ++col)
3369 if (
blobIds[row][col] == blobId)
3393 BlobList::iterator idx;
3394 for (idx = blobs->begin (); idx != blobs->end (); ++idx)
3396 BlobPtr blob = idx->second;
3400 kkint32 rowStart = Min (blob->RowTop (), height - 1);
3401 kkint32 rowEnd = Min (blob->RowBot (), height - 1);
3402 kkint32 colStart = Min (blob->ColLeft (), width - 1);
3403 kkint32 colEnd = Min (blob->ColRight (), width - 1);
3407 for (row = rowStart; row <= rowEnd; ++row)
3409 for (col = colStart; col <= colEnd; ++col)
3411 if (
blobIds[row][col] == blobId)
3427 void Raster::DeleteExistingBlobIds ()
3445 void Raster::AllocateBlobIds ()
3449 DeleteExistingBlobIds ();
3453 for (row = 0; row <
height; row++)
3456 for (col = 0; col <
width; col++)
3468 if (connectedComponentDist < 1)
3469 connectedComponentDist = 3;
3481 memset (newImageArea, 0, totPixels);
3482 uchar* newImageAreaPtr = newImageArea;
3486 for (row = 0; row <
height; row++)
3488 newRows[row] = newImageAreaPtr;
3490 for (col = 0; col <
width; col++)
3492 if (
blobIds[row][col] == blobId)
3494 newRows[row][col] =
green[row][col];
3498 newImageAreaPtr = newImageAreaPtr +
width;
3508 for (row = 0; row <
height; row++)
3513 delete blobs; blobs = NULL;
3524 if (connectedComponentDist < 1)
3525 connectedComponentDist = 3;
3537 memset (newImageArea, 0, totPixels);
3538 uchar* newImageAreaPtr = newImageArea;
3542 for (row = 0; row <
height; row++)
3544 newRows[row] = newImageAreaPtr;
3546 for (col = 0; col <
width; col++)
3548 if (
blobIds[row][col] == blobId)
3550 newRows[row][col] =
green[row][col];
3554 newImageAreaPtr = newImageAreaPtr +
width;
3564 for (row = 0; row <
height; row++)
3569 delete blobs; blobs = NULL;
3579 uchar* curRow = NULL;
3580 kkint32* curRowBlobIds = NULL;
3581 kkint32* prevRowBlobIds = NULL;
3586 BlobPtr curBlob = NULL;
3596 for (row = 0; row <
height; row++)
3599 for (col = 0; col <
width; col++)
3607 for (row = 1; row <
height - 1; row++)
3609 curRow =
green[row];
3611 prevRowBlobIds =
blobIds[row - 1];
3617 while (col < (
width - 1))
3619 if (ForegroundPixel (curRow[col]))
3621 blankColsInARow = 0;
3623 nearBlobId = Max (prevRowBlobIds[col - 1],
3624 prevRowBlobIds[col],
3625 prevRowBlobIds[col + 1]
3629 if (nearBlobId >= 0)
3631 if (nearBlobId != curBlobId)
3637 curRowBlobIds[col] = curBlobId;
3638 curBlob->colRight = Max (curBlob->colRight, col);
3639 curBlob->rowBot = Max (curBlob->rowBot, row);
3645 if (nearBlobId >= 0)
3648 curBlobId = curBlob
->id;
3653 curBlobId = curBlob
->id;
3656 curRowBlobIds[col] = curBlobId;
3657 curBlob->colLeft = Min (curBlob->colLeft, col);
3658 curBlob->colRight = Max (curBlob->colRight, col);
3659 curBlob->rowBot = Max (curBlob->rowBot, row);
3660 curBlob->rowTop = Min (curBlob->rowTop, row);
3681 memset (newImageArea, 0, totPixels);
3682 uchar* newImageAreaPtr = newImageArea;
3686 for (row = 0; row <
height; row++)
3688 newRows[row] = newImageAreaPtr;
3690 for (col = 0; col <
width; col++)
3692 if (
blobIds[row][col] == blobId)
3694 newRows[row][col] =
green[row][col];
3698 newImageAreaPtr = newImageAreaPtr +
width;
3708 for (row = 0; row <
height; row++)
3713 delete blobs; blobs = NULL;
3747 blobRaster
->red [blobRow][blobCol] =
red [row][col];
3748 blobRaster
->blue[blobRow][blobCol] =
blue[row][col];
3777 blobRaster
->red [row][col] =
red [row][col];
3799 for (r = 0; r <
height; r++)
3801 for (c = 0; c <
width; c++)
3803 pixVal =
green[r][c];
3805 if (ForegroundPixel (pixVal))
3841 for (x = 0; x < 8; x++)
3842 intensityHistBuckets[x] = 0;
3848 uchar* curRow = NULL;
3849 uchar* curMaskRow = NULL;
3851 for (r = 0; r <
height; r++)
3853 curMaskRow = mask
.green[r];
3855 for (c = 0; c <
width; c++)
3857 if (ForegroundPixel (curMaskRow[c]))
3881 for (
kkint32 x = 0; x < 8; x++)
3882 intensityHistBuckets[x] = 0;
3888 for (r = 0; r <
height; r++)
3890 for (c = 0; c <
width; c++)
3892 pixVal =
green[r][c];
3894 if (ForegroundPixel (pixVal))
3913 float& weightedSize,
3916 kkuint32 intensityHistBucketsWhiteSpace[8]
3928 long totalPixelValues = 0;
3931 weightedSize = 0.0f;
3932 areaWithWhiteSpace = 0;
3935 for (x = 0; x < 8; x++)
3937 intensityHistBuckets[x] = 0;
3938 intensityHistBucketsWhiteSpace[x] = 0;
3950 if (ForegroundPixel (maskGreenArea[x]))
3952 areaWithWhiteSpace++;
3957 if (ForegroundPixel (pixVal))
3961 totalPixelValues += pixVal;
3968 weightedSize = (
float)totalPixelValues / (
float)
maxPixVal;
3982 long totalPixelValues = 0;
3988 for (x = 0; x < 16; x++)
3990 intensityHistBuckets[x] = 0;
4001 if (ForegroundPixel (pixVal))
4005 totalPixelValues += pixVal;
4011 weighedSize = (
float)totalPixelValues / (
float)
maxPixVal;
4019 float& weightedSize,
4026 long totalPixelValues = 0;
4029 weightedSize = 0.0f;
4031 for (x = 0; x < 8; x++)
4032 intensityHistBuckets[x] = 0;
4046 totalPixelValues += pixVal;
4052 weightedSize = (
float)totalPixelValues / (
float)255.0f;
4071 for (r = 0; r <
height; r++)
4073 for (c = 0; c <
width; c++)
4075 pixVal =
green[r][c];
4076 if (ForegroundPixel (pixVal))
4078 area = area + (
float)pixVal;
4079 if (pixVal > maxPixValFound)
4080 maxPixValFound = pixVal;
4085 area = area / (
float)maxPixValFound;
4103 Moment (m00, m10, m01);
4110 float cm00 = (
float)m00;
4111 float gamma2 = (
float)m00 * (
float)m00;
4112 float gamma3 = gamma2 * (
float)sqrt ((
float)m00);
4128 float deltaCol = 0.0f;
4129 float deltaRow = 0.0f;
4131 for (row = 0; row <
height; ++row)
4134 float rowPow0 = 1.0;
4135 float rowPow1 = deltaRow;
4136 float rowPow2 = deltaRow * deltaRow;
4137 float rowPow3 = rowPow2 * deltaRow;
4139 for (col = 0; col <
width; ++col)
4144 float colPow0 = 1.0f;
4145 float colPow1 = deltaCol;
4146 float colPow2 = deltaCol * deltaCol;
4147 float colPow3 = colPow2 * deltaCol;
4149 cm20 += colPow2 * rowPow0;
4150 cm02 += colPow0 * rowPow2;
4151 cm11 += colPow1 * rowPow1;
4152 cm30 += colPow3 * rowPow0;
4153 cm03 += colPow0 * rowPow3;
4155 cm12 += colPow1 * rowPow2;
4156 cm21 += colPow2 * rowPow1;
4162 cm20 = cm20 / gamma2;
4163 cm02 = cm02 / gamma2;
4164 cm11 = cm11 / gamma2;
4166 cm30 = cm30 / gamma3;
4167 cm03 = cm03 / gamma3;
4168 cm12 = cm12 / gamma3;
4169 cm21 = cm21 / gamma3;
4173 features[1] = cm20 + cm02;
4175 features[2] = (cm20 - cm02) * (cm20 - cm02) +
4178 features[3] = (cm30 - 3.0f * cm12) * (cm30 - 3.0f * cm12) +
4179 (3.0f * cm21 - cm03) * (3.0f * cm21 - cm03);
4181 features[4] = (cm30 + cm12) * (cm30 + cm12) + (cm21 + cm03) * (cm21 + cm03);
4183 features[5] = (cm30 - 3.0f * cm12) * (cm30 + cm12) * ((cm30 + cm12) * (cm30 + cm12) -
4184 3.0f * (cm21 + cm03) * (cm21 + cm03)) + (3.0f * cm21 - cm03) * (cm21 + cm03) *
4185 (3.0f * (cm30 + cm12) * (cm30 + cm12) - (cm21 + cm03) * (cm21 + cm03));
4187 features[6] = (cm20 - cm02) *
4188 ((cm30 + cm12) * (cm30 + cm12) - (cm21 + cm03) * (cm21 + cm03))
4189 + 4.0f * cm11 * (cm30 + cm12) * (cm21 + cm03);
4191 features[7] = (3.0f * cm21 - cm03) * (cm30 + cm12) *
4192 ((cm30 + cm12) * (cm30 + cm12) - 3.0f * (cm21 + cm03) * (cm21 + cm03) )
4193 -(cm30 - 3.0f * cm12) * (cm21 + cm03) *
4194 (3.0f * (cm30 + cm12) * (cm30 + cm12) - (cm21 + cm03) * (cm21 + cm03) );
4197 features[8] = (((cm20 - cm02) * (cm20 - cm02)) -
4198 (4.0f * cm11 * cm11))/((cm20 + cm02) * (cm20 + cm02));
4219 for (row = 0; row <
height; ++row)
4222 for (col = 0; col <
width; ++col)
4246 float m00, m10, m01;
4247 MomentWeighted (m00, m10, m01);
4249 float ew = m10 / m00;
4250 float eh = m01 / m00;
4253 float gamma2 = m00 * m00;
4254 float gamma3 = gamma2 * (
float)sqrt (m00);
4272 for (row = 0; row <
height; ++row)
4275 float deltaRow = row - eh;
4278 float rowPow1 = deltaRow;
4279 float rowPow2 = deltaRow * deltaRow;
4280 float rowPow3 = rowPow2 * deltaRow;
4282 for (col = 0; col <
width; ++col)
4284 uchar pv = rowData[col];
4290 float deltaCol = col - ew;
4292 float colPow1 = deltaCol;
4293 float colPow2 = deltaCol * deltaCol;
4294 float colPow3 = colPow2 * deltaCol;
4296 float pvFloat = (
float)pv;
4298 cm20 += pvFloat * colPow2 * rowPow0;
4299 cm02 += pvFloat * colPow0 * rowPow2;
4300 cm30 += pvFloat * colPow3 * rowPow0;
4301 cm03 += pvFloat * colPow0 * rowPow3;
4302 cm12 += pvFloat * colPow1 * rowPow2;
4303 cm21 += pvFloat * colPow2 * rowPow1;
4308 cm20 = cm20 / (
float)maxPixVal;
4309 cm02 = cm02 / (
float)maxPixVal;
4310 cm30 = cm30 / (
float)maxPixVal;
4311 cm03 = cm03 / (
float)maxPixVal;
4312 cm12 = cm12 / (
float)maxPixVal;
4313 cm21 = cm21 / (
float)maxPixVal;
4316 cm20 = cm20 / gamma2;
4317 cm02 = cm02 / gamma2;
4318 cm11 = cm11 / gamma2;
4320 cm30 = cm30 / gamma3;
4321 cm03 = cm03 / gamma3;
4322 cm12 = cm12 / gamma3;
4323 cm21 = cm21 / gamma3;
4327 features[1] = cm20 + cm02;
4329 features[2] = (cm20 - cm02) * (cm20 - cm02) + (
float)4.0 * cm11 * cm11;
4331 features[3] = (cm30 - (
float)3.0 * cm12) *
4332 (cm30 - (
float)3.0 * cm12) +
4333 ((
float)3.0 * cm21 - cm03) *
4334 ((
float)3.0 * cm21 - cm03);
4336 features[4] = (cm30 + cm12) * (cm30 + cm12) + (cm21 + cm03) * (cm21 + cm03);
4338 features[5] = (cm30 - (
float)3.0 * cm12) * (cm30 + cm12) *
4339 ((cm30 + cm12) * (cm30 + cm12) -
4340 (
float)3.0 * (cm21 + cm03) * (cm21 + cm03)) +
4341 ((
float)3.0 * cm21 - cm03) * (cm21 + cm03) *
4342 ((
float)3.0 * (cm30 + cm12) * (cm30 + cm12) -
4343 (cm21 + cm03) * (cm21 + cm03));
4345 features[6] = (cm20 - cm02) *
4347 (cm30 + cm12) * (cm30 + cm12) -
4348 (cm21 + cm03) * (cm21 + cm03)
4350 (
float)4.0 * cm11 * (cm30 + cm12) * (cm21 + cm03);
4352 features[7] = ((
float)3.0 * cm21 - cm03) *
4353 (cm30 + cm12) * ((cm30 + cm12) *
4354 (cm30 + cm12) - (
float)3.0 *
4355 (cm21 + cm03) * (cm21 + cm03)) -
4356 (cm30 - (
float)3.0 * cm12) *
4357 (cm21 + cm03) * ((
float)3.0 *
4358 (cm30 + cm12) * (cm30 + cm12) -
4359 (cm21 + cm03) * (cm21 + cm03));
4362 features[8] = (
float)((((cm20 - cm02) * (cm20 - cm02)) -
4363 (4.0 * cm11 * cm11))/((cm20 + cm02) * (cm20 + cm02)));
4373 void Raster::MomentWeighted (
float& m00,
4391 for (row = 0; row <
height; ++row)
4394 for (col = 0; col <
width; ++col)
4396 uchar pv = rowData[col];
4400 m10Int = m10Int + col * pv;
4401 m01Int = m01Int + row * pv;
4409 m00 = (
float)m00Int / (
float)maxPixVal;
4410 m10 = (
float)m10Int / (
float)maxPixVal;
4411 m01 = (
float)m01Int / (
float)maxPixVal;
4419 float& weightedPixelCount,
4420 float centralMoments[9],
4421 float centralMomentsWeighted[9]
4426 float mw00, mw10, mw01;
4427 Moments (m00, m10, m01, mw00, mw10, mw01);
4429 foregroundPixelCount = (
kkint32)m00;
4430 weightedPixelCount = mw00;
4435 float centroidColW = mw10 / mw00;
4436 float centroidRowW = mw01 / mw00;
4438 float cm00 = (
float)m00;
4439 float gamma2 = (
float)m00 * (
float)m00;
4440 float gamma3 = gamma2 * (
float)sqrt ((
float)m00);
4452 float gammaW2 = (
float)mw00 * (
float)mw00;
4453 float gammaW3 = (
float)gammaW2 * (
float)sqrt ((
float)mw00);
4470 float deltaCol = 0.0f;
4471 float deltaRow = 0.0f;
4475 for (row = 0; row <
height; ++row)
4480 float deltaRowW = row - centroidRowW;
4482 float rowPow0 = 1.0;
4483 float rowPow1 = deltaRow;
4484 float rowPow2 = deltaRow * deltaRow;
4485 float rowPow3 = rowPow2 * deltaRow;
4488 float rowPowW1 = deltaRowW;
4489 float rowPowW2 = deltaRowW * deltaRowW;
4490 float rowPowW3 = rowPowW2 * deltaRowW;
4492 for (col = 0; col <
width; ++col)
4494 uchar pv = rowData[col];
4499 float colPow0 = 1.0f;
4500 float colPow1 = deltaCol;
4501 float colPow2 = deltaCol * deltaCol;
4502 float colPow3 = colPow2 * deltaCol;
4504 cm20 += colPow2 * rowPow0;
4505 cm02 += colPow0 * rowPow2;
4506 cm11 += colPow1 * rowPow1;
4507 cm30 += colPow3 * rowPow0;
4508 cm03 += colPow0 * rowPow3;
4510 cm12 += colPow1 * rowPow2;
4511 cm21 += colPow2 * rowPow1;
4516 float deltaColW = col - centroidColW;
4518 float colPowW1 = deltaColW;
4519 float colPowW2 = deltaColW * deltaColW;
4520 float colPowW3 = colPowW2 * deltaColW;
4522 cmw20 += colPowW2 * rowPowW0;
4523 cmw02 += colPowW0 * rowPowW2;
4524 cmw30 += colPowW3 * rowPowW0;
4525 cmw03 += colPowW0 * rowPowW3;
4526 cmw12 += colPowW1 * rowPowW2;
4527 cmw21 += colPowW2 * rowPowW1;
4532 cmw20 = cmw20 / (
float)maxPixVal;
4533 cmw02 = cmw02 / (
float)maxPixVal;
4534 cmw30 = cmw30 / (
float)maxPixVal;
4535 cmw03 = cmw03 / (
float)maxPixVal;
4536 cmw12 = cmw12 / (
float)maxPixVal;
4537 cmw21 = cmw21 / (
float)maxPixVal;
4540 cm20 = cm20 / gamma2;
4541 cm02 = cm02 / gamma2;
4542 cm11 = cm11 / gamma2;
4544 cm30 = cm30 / gamma3;
4545 cm03 = cm03 / gamma3;
4546 cm12 = cm12 / gamma3;
4547 cm21 = cm21 / gamma3;
4549 cmw20 = cmw20 / gammaW2;
4550 cmw02 = cmw02 / gammaW2;
4551 cmw11 = cmw11 / gammaW2;
4553 cmw30 = cmw30 / gammaW3;
4554 cmw03 = cmw03 / gammaW3;
4555 cmw12 = cmw12 / gammaW3;
4556 cmw21 = cmw21 / gammaW3;
4559 centralMoments[0] = cm00;
4561 centralMoments[1] = cm20 + cm02;
4563 centralMoments[2] = (cm20 - cm02) * (cm20 - cm02) +
4566 centralMoments[3] = (cm30 - 3.0f * cm12) * (cm30 - 3.0f * cm12) +
4567 (3.0f * cm21 - cm03) * (3.0f * cm21 - cm03);
4569 centralMoments[4] = (cm30 + cm12) * (cm30 + cm12) + (cm21 + cm03) * (cm21 + cm03);
4571 centralMoments[5] = (cm30 - 3.0f * cm12) * (cm30 + cm12) * ((cm30 + cm12) * (cm30 + cm12) -
4572 3.0f * (cm21 + cm03) * (cm21 + cm03)) + (3.0f * cm21 - cm03) * (cm21 + cm03) *
4573 (3.0f * (cm30 + cm12) * (cm30 + cm12) - (cm21 + cm03) * (cm21 + cm03));
4575 centralMoments[6] = (cm20 - cm02) *
4576 ((cm30 + cm12) * (cm30 + cm12) - (cm21 + cm03) * (cm21 + cm03))
4577 + 4.0f * cm11 * (cm30 + cm12) * (cm21 + cm03);
4579 centralMoments[7] = (3.0f * cm21 - cm03) * (cm30 + cm12) *
4580 ((cm30 + cm12) * (cm30 + cm12) - 3.0f * (cm21 + cm03) * (cm21 + cm03) )
4581 -(cm30 - 3.0f * cm12) * (cm21 + cm03) *
4582 (3.0f * (cm30 + cm12) * (cm30 + cm12) - (cm21 + cm03) * (cm21 + cm03) );
4585 centralMoments[8] = (((cm20 - cm02) * (cm20 - cm02)) -
4586 (4.0f * cm11 * cm11))/((cm20 + cm02) * (cm20 + cm02));
4590 centralMomentsWeighted[0] = cmw00;
4592 centralMomentsWeighted[1] = cmw20 + cmw02;
4594 centralMomentsWeighted[2] = (cmw20 - cmw02) * (cmw20 - cmw02) + (
float)4.0 * cmw11 * cmw11;
4596 centralMomentsWeighted[3] = (cmw30 - (
float)3.0 * cmw12) *
4597 (cmw30 - (
float)3.0 * cmw12) +
4598 ((
float)3.0 * cmw21 - cmw03) *
4599 ((
float)3.0 * cmw21 - cmw03);
4601 centralMomentsWeighted[4] = (cmw30 + cmw12) * (cmw30 + cmw12) + (cmw21 + cmw03) * (cmw21 + cmw03);
4603 centralMomentsWeighted[5] = (cmw30 - (
float)3.0 * cmw12) * (cmw30 + cmw12) *
4604 ((cmw30 + cmw12) * (cmw30 + cmw12) -
4605 (
float)3.0 * (cmw21 + cmw03) * (cmw21 + cmw03)) +
4606 ((
float)3.0 * cmw21 - cmw03) * (cmw21 + cmw03) *
4607 ((
float)3.0 * (cmw30 + cmw12) * (cmw30 + cmw12) -
4608 (cmw21 + cmw03) * (cmw21 + cmw03));
4610 centralMomentsWeighted[6] = (cmw20 - cmw02) *
4612 (cmw30 + cmw12) * (cmw30 + cmw12) -
4613 (cmw21 + cmw03) * (cmw21 + cmw03)
4615 (
float)4.0 * cmw11 * (cmw30 + cmw12) * (cmw21 + cmw03);
4617 centralMomentsWeighted[7] = ((
float)3.0 * cmw21 - cmw03) *
4618 (cmw30 + cmw12) * ((cmw30 + cmw12) *
4619 (cmw30 + cmw12) - (
float)3.0 *
4620 (cmw21 + cmw03) * (cmw21 + cmw03)) -
4621 (cmw30 - (
float)3.0 * cmw12) *
4622 (cmw21 + cmw03) * ((
float)3.0 *
4623 (cmw30 + cmw12) * (cmw30 + cmw12) -
4624 (cmw21 + cmw03) * (cmw21 + cmw03));
4627 centralMomentsWeighted[8] = (
float)((((cmw20 - cmw02) * (cmw20 - cmw02)) -
4628 (4.0 * cmw11 * cmw11))/((cmw20 + cmw02) * (cmw20 + cmw02)));
4666 for (row = 0; row <
height; ++row)
4669 for (col = 0; col <
width; ++col)
4671 uchar pv = rowData[col];
4675 m10Int = m10Int + col * pv;
4676 m01Int = m01Int + row * pv;
4688 mw00 = (
float)m00Int / (
float)maxPixVal;
4689 mw10 = (
float)m10Int / (
float)maxPixVal;
4690 mw01 = (
float)m01Int / (
float)maxPixVal;
4710 kkint32 endR = _row + _height - 1;
4711 kkint32 endC = _col + _width - 1;
4713 if ((_row < 0) || (endR >=
height) ||
4714 (_col < 0) || (endC >=
width))
4716 cerr <<
"***ERROR***, Raster::Raster *** ERROR ***, Index's Exceed Raster Bounds" << std::endl;
4717 cerr <<
" Raster Dimensions[" << width <<
", " << height <<
"]." << std::endl;
4718 cerr <<
" Requested Coordinates [" << _row <<
", " << _col <<
"], " 4719 <<
" Height[" << _height <<
"], Width[" << _width <<
"]." 4728 kkint32 totalPixelArea = _height * _width;
4729 uchar* subSetArea =
new uchar[totalPixelArea];
4733 for (row = 0; row < _height; row++)
4735 subSet[row] = subSetArea;
4736 for (col = 0; col < _width; col++)
4738 subSet[row][col] = _src[_row + row][_col + col];
4740 subSetArea = subSetArea + _width;
4753 bool Raster::Fit (MaskTypes mask,
4765 if (rStart < 0) rStart = 0;
4767 if (cStart < 0) cStart = 0;
4772 for (r = rStart; r <= rEnd; r++)
4775 for (c = cStart; c <= cEnd; c++)
4777 if (BackgroundPixel (rowData[c]))
4785 for (r = rStart; r <= rEnd; r++)
4787 if (BackgroundPixel (
green[r][col]))
4792 for (c = cStart; c <= cEnd; c++)
4794 if (BackgroundPixel (rowData[c]))
4811 bool Raster::IsThereANeighbor (MaskTypes mask,
4823 if (rStart < 0) rStart = 0;
4825 if (cStart < 0) cStart = 0;
4830 for (r = rStart; r <= rEnd; r++)
4833 for (c = cStart; c <= cEnd; c++)
4835 if (
this->ForegroundPixel (rowData[c]))
4843 for (r = rStart; r <= rEnd; r++)
4845 if (ForegroundPixel (
green[r][col]))
4850 for (c = cStart; c <= cEnd; c++)
4852 if (ForegroundPixel (rowData[c]))
4873 if ((row < maskBias) ||
4874 (row + maskBias >=
height) ||
4876 (col + maskBias >=
width))
4885 kkint32 startRow = Max (row - maskBias, (kkint32)0);
4886 kkint32 endRow = Min (row + maskBias, height - 1);
4887 kkint32 startCol = Max (col - maskBias, (kkint32)0);
4888 kkint32 endCol = Min (col + maskBias, width - 1);
4894 for (r = startRow; r <= endRow; r++)
4896 for (c = startCol; c < endCol; c++)
4898 pixVal =
green[r][c];
4900 if (ForegroundPixel (pixVal))
4903 totPixVal = totPixVal + pixVal;
4911 for (r = startRow, c = startCol; r <= endRow; r++, c++)
4913 pixVal =
green[r][col];
4914 if (ForegroundPixel (pixVal))
4917 totPixVal = totPixVal + pixVal;
4920 pixVal =
green[row][c];
4921 if (ForegroundPixel (pixVal))
4924 totPixVal = totPixVal + pixVal;
4933 return (
uchar)(totPixVal / numOfHits);
4943 KK_DFT2D_Float::DftComplexType** dest;
4944 KK_DFT2D_Float::DftComplexType* destArea;
4945 plan.AllocateArray (destArea, dest);
4947 if (destArea == NULL)
4950 << std::endl << std::endl
4951 <<
"Raster::FastFourierKK ***ERROR*** Allocation of 'dest' failed'" << std::endl
4952 <<
" totPixels[" << totPixels <<
"]" << std::endl
4953 <<
" FileName[" << fileName <<
"]" << std::endl
4958 plan.Transform (green, dest);
4964 fourierImage->AllocateFourierMagnitudeTable ();
4969 float maxAmplitude = 0.0f;
4976 double r = dest[row][col].real ();
4977 double i = dest[row][col].imag ();
4979 mag = (
float)(sqrt (r * r + i * i));
4980 if (mag > maxAmplitude)
4983 fourierMagArray[idx] = mag;
4988 float maxAmplitudeLog = log (maxAmplitude);
4994 mag = fourierMagArray[idx];
5003 destData[idx] = (
uchar)(log (fourierMagArray[idx]) * 255.0f / maxAmplitudeLog);
5006 delete dest; dest = NULL;
5007 delete destArea; destArea = NULL;
5009 return fourierImage;
5018 #if defined(FFTW_AVAILABLE) 5019 fftwf_complex* src = NULL;
5020 fftwf_complex* dest = NULL;
5021 fftwf_plan plan = NULL;
5025 KK_DFT2D_Float::DftComplexType* srcArea = NULL;
5026 KK_DFT2D_Float::DftComplexType** src = NULL;
5028 KK_DFT2D_Float::DftComplexType* destArea = NULL;
5029 KK_DFT2D_Float::DftComplexType** dest = NULL;
5034 cerr << std::endl << std::endl
5035 <<
"Raster::FastFourier ***ERROR*** totPixels == 0." << std::endl
5036 <<
" FileName[" <<
this->FileName () <<
"]" << std::endl
5046 #if defined(FFTW_AVAILABLE) 5047 src = (fftwf_complex*)fftwf_malloc (
sizeof (fftwf_complex) * totPixels);
5048 dest = (fftwf_complex*)fftwf_malloc (
sizeof (fftwf_complex) * totPixels);
5050 plan.AllocateArray (srcArea, src);
5051 plan.AllocateArray (destArea, dest);
5057 << std::endl << std::endl
5058 <<
"Raster::FastFourier ***ERROR*** Allocation of 'src' failed'" << std::endl
5059 <<
" totPixels[" << totPixels <<
"]" << std::endl
5060 <<
" FileName[" << fileName <<
"]" << std::endl
5068 << std::endl << std::endl
5069 <<
"Raster::FastFourier ***ERROR*** Allocation of 'dest' failed'" << std::endl
5070 <<
" totPixels[" << totPixels <<
"]" << std::endl
5071 <<
" FileName[" << fileName <<
"]" << std::endl
5078 for (row = 0; row <
height; row++ )
5080 for (col = 0; col <
width; col++ )
5083 #if defined(FFTW_AVAILABLE) 5084 src[idx][0] = (
float)green[row][col];
5087 srcArea[idx].real ((
float)greenArea[idx]);
5088 srcArea[idx].imag (0.0);
5094 #if defined(FFTW_AVAILABLE) 5095 plan = fftwCreateTwoDPlan (height, width, src, dest, FFTW_FORWARD, FFTW_ESTIMATE);
5096 fftwf_execute (plan);
5097 fftwDestroyPlan (plan);
5099 plan.Transform (src, dest);
5107 fourierImage->AllocateFourierMagnitudeTable ();
5110 float mag = (
float)0;
5112 float maxAmplitude = (
float)0;
5116 #if defined(FFTW_AVAILABLE) 5117 float real = dest[idx][0];
5118 float imag = dest[idx][1];
5120 float real = destArea[idx].real ();
5121 float imag = destArea[idx].imag ();
5125 mag = (
float)(sqrt (real * real + imag * imag));
5127 if (mag > maxAmplitude)
5130 fourierMagArray[idx] = mag;
5133 float maxAmplitudeLog = log (maxAmplitude);
5139 mag = fourierMagArray[idx];
5148 destData[idx] = (
uchar)(log (fourierMagArray[idx]) * 255.0f / maxAmplitudeLog);
5151 #if defined(FFTW_AVAILABLE) 5152 fftwf_free (src); src = NULL;
5153 fftwf_free (dest); dest = NULL;
5155 plan.DestroyArray (srcArea, src);
5156 plan.DestroyArray (destArea, dest);
5159 return fourierImage;
5175 for (r1 = 0, r2 = bottomStart; (r1 < bottomStart) && (r2 <
height); r1++, r2++)
5177 for (c1 = 0, c2 = leftStart; (c1 < leftStart) && (c2 <
width); c1++, c2++)
5221 <<
"*** ERROR *** This Raster image is not the result of a fast Fourier" << std::endl
5227 float cr =
height / (
float)2.0;
5228 float cw =
width / (
float)2.0;
5230 float crSqr = cr * cr;
5231 float cwSqr = cw * cw;
5234 float r1Len = crSqr / (
float)4.0 + cwSqr / (
float)4.0;
5236 float r2Len = (
float)((9.0 / 16.0) * crSqr + (9.0 / 16.0) * cwSqr);
5238 float r3Len = (
float)((81.0 / 100.0) * crSqr + (81.0 / 100.0) * cwSqr);
5240 float r4Len = (
float)((361.0 / 400.0) * crSqr + (361.0 / 400.0) * cwSqr);
5242 fourierFeatures[0] = (
float)0.0;
5243 fourierFeatures[1] = (
float)0.0;
5244 fourierFeatures[2] = (
float)0.0;
5245 fourierFeatures[3] = (
float)0.0;
5246 fourierFeatures[4] = (
float)0.0;
5260 float deltaRowSqr = (
float)0.0;
5263 float deltaColSqr = (
float)0.0;
5267 for (row = 0 ; row <
height; row++)
5269 deltaRow = cr - (
float)row;
5270 deltaRowSqr = deltaRow * deltaRow;
5272 for (col = 0; col < (
kkint32)cw; col++)
5274 deltaCol = cw - (
float)col;
5275 deltaColSqr = deltaCol * deltaCol;
5277 distFromCent = deltaRowSqr + deltaColSqr;
5279 if (distFromCent < r1Len)
5281 fourierFeatures[0] = fourierFeatures[0] +
fourierMag[row][col];
5285 else if (distFromCent < r2Len)
5287 fourierFeatures[1] = fourierFeatures[1] +
fourierMag[row][col];
5291 else if (distFromCent < r3Len)
5293 fourierFeatures[2] = fourierFeatures[2] +
fourierMag[row][col];
5297 else if (distFromCent < r4Len)
5299 fourierFeatures[3] = fourierFeatures[3] +
fourierMag[row][col];
5304 fourierFeatures[4] = fourierFeatures[4] +
fourierMag[row][col];
5312 for (x = 0; x < 5; x++)
5314 fourierFeatures[x] = fourierFeatures[x] / count[x];
5332 float deltaAng = ang2 - ang1;
5334 while (deltaAng > 180.0)
5335 deltaAng = deltaAng - (
float)360.0;
5337 if (deltaAng < -180.0)
5338 deltaAng = deltaAng + (
float)360;
5380 for (x = 0; x < 5; x++)
5382 countourFreq[x] = 0.0;
5390 #if defined(FFTW_AVAILABLE) 5391 fftw_complex* src = (fftw_complex*)fftw_malloc (
sizeof (fftw_complex) * maxNumOfAngles);
5393 KK_DFT1D_Float::DftComplexType* src =
new KK_DFT1D_Float::DftComplexType[maxNumOfAngles];
5399 while ((startCol <
width) && (BackgroundPixel (
green[startRow][startCol])))
5405 if (startCol >=
width)
5415 for (row = 0; ((row <
height) && (!found)); row++)
5417 for (col = 0; ((col <
width) && (!found)); col++)
5419 if (ForegroundPixel (
green[row][col]))
5437 bool nextPixelFound =
false;
5445 fromDir = lastDir + 4;
5447 fromDir = fromDir - 8;
5449 nextPixelFound =
false;
5451 nextDir = fromDir + 2;
5452 while (!nextPixelFound)
5455 nextDir = nextDir - 8;
5460 if ((nextRow < 0) ||
5468 else if (ForegroundPixel (
green[nextRow][nextCol]))
5470 nextPixelFound =
true;
5478 if (numOfAngles >= maxNumOfAngles)
5480 kkint32 newMaxNumOfAngles = maxNumOfAngles * 2;
5482 #if defined(FFTW_AVAILABLE) 5483 fftw_complex* newSrc = (fftw_complex*)fftw_malloc (
sizeof (fftw_complex) * newMaxNumOfAngles);
5485 KK_DFT1D_Float::DftComplexType* newSrc =
new KK_DFT1D_Float::DftComplexType[newMaxNumOfAngles];
5489 for (x = 0; x < maxNumOfAngles; x++)
5491 #if defined(FFTW_AVAILABLE) 5492 newSrc[x][0] = src[x][0];
5493 newSrc[x][1] = src[x][1];
5495 newSrc[x].real (src[x].real ());
5496 newSrc[x].imag (src[x].imag ());
5507 maxNumOfAngles = newMaxNumOfAngles;
5510 #if defined(FFTW_AVAILABLE) 5511 src[numOfAngles][0] = nextRow;
5512 src[numOfAngles][1] = nextCol;
5514 src[x].real ((
float)nextRow);
5515 src[x].imag ((
float)nextCol);
5525 }
while ((curRow != startRow) || (curCol != startCol));
5528 #if defined(FFTW_AVAILABLE) 5529 fftw_complex* dest = (fftw_complex*)fftw_malloc (
sizeof (fftw_complex) * maxNumOfAngles);
5531 plan = fftw_plan_dft_1d (numOfAngles, src, dest, FFTW_FORWARD, FFTW_ESTIMATE);
5532 fftw_execute (plan);
5533 fftw_destroy_plan(plan);
5536 KK_DFT1D_Float::DftComplexType* dest =
new KK_DFT1D_Float::DftComplexType[maxNumOfAngles];
5537 plan.Transform(src, dest);
5541 float middle = (
float)(numOfAngles / 2.0);
5542 float r1 = (
float)(middle / 2.0);
5543 float r2 = (
float)(middle * ( 3.0 / 4.0));
5544 float r3 = (
float)(middle * ( 7.0 / 8.0));
5545 float r4 = (
float)(middle * (15.0 / 16.0));
5550 for (x = 0; x < numOfAngles; x++)
5552 #if defined(FFTW_AVAILABLE) 5553 mag = (
float)log (sqrt (dest[x][0] * dest[x][0] + dest[x][1] * dest[x][1]));
5555 mag = (
float)log (sqrt (dest[x].real () * dest[x].real () + dest[x].imag () * dest[x].imag ()));
5558 deltaX = (
float)fabs ((
float)x - middle);
5562 countourFreq[0] = countourFreq[0] + mag;
5566 else if (deltaX < r2)
5568 countourFreq[1] = countourFreq[1] + mag;
5572 else if (deltaX < r3)
5574 countourFreq[2] = countourFreq[2] + mag;
5578 else if (deltaX < r4)
5580 countourFreq[3] = countourFreq[3] + mag;
5586 countourFreq[4] = countourFreq[4] + mag;
5592 for (x = 0; x < 5; x++)
5593 countourFreq[x] = countourFreq[x] / (
float)count[x];
5595 #if defined(FFTW_AVAILABLE) 5611 float& orientationAngle
5616 float centroidColWeighted;
5617 float centroidRowWeighted;
5635 double colOffset = 0.0;
5636 double rowOffset = 0.0;
5637 double rowOffsetSquare = 0.0;
5639 for (row = 0; row <
height; row++)
5642 rowOffsetSquare = rowOffset * rowOffset;
5644 for (col = 0; col <
width; col++)
5646 pixVal =
green[row][col];
5648 if (ForegroundPixel (pixVal))
5651 cov[0][0] += (colOffset * colOffset);
5652 cov[1][1] += (rowOffsetSquare);
5653 cov[0][1] += (colOffset * rowOffset);
5658 cov[1][0] = cov[0][1];
5664 double origCov00 = cov[0][0];
5665 double origCov11 = cov[1][1];
5666 double origCov10 = cov[1][0];
5682 if (fabs (d[0]) > fabs (d[1]))
5684 ang0 = atan2 (cov[0][0], cov[1][0]);
5685 eigenRatio = (d[0] == 0.0) ? 9999.0f :
float (d[1] / d[0]);
5689 ang0 = atan2 (cov[0][1], cov[1][1]);
5690 eigenRatio = (d[1] == 0.0) ? 9999.0f :
float (d[0] / d[1]);
5694 orientationAngle =
float (-ang0 - 1.57079632679f);
5695 if (fabs (orientationAngle) > 1.57079632679f)
5697 if (orientationAngle < 0.0)
5698 orientationAngle +=
float (
PIE);
5700 orientationAngle -=
float (
PIE);
5714 if (origCov00 > origCov11)
5716 orientationAngle = 0.0f;
5720 orientationAngle = 1.57079632679f;
5736 kkint32 halfDiag = (diag + 1) / 2;
5745 float a11 = (
float)(cos (-turnAngle));
5746 float a12 = (
float)(sin (-turnAngle));
5747 float b1 =
width * 0.5f;
5751 float b2 =
height * 0.5f;
5763 for (centDestRow = -halfDiag; centDestRow < halfDiag; centDestRow++)
5765 for (centDestCol = -halfDiag; centDestCol < halfDiag; centDestCol++)
5767 srcRow = (
kkint32)((
float)(a21 * centDestCol) + (
float)(a22 * centDestRow) + b2 + 0.5);
5768 if ((srcRow >= 0) && (srcRow <
height))
5770 srcCol = (
kkint32)((
float)(a11 * centDestCol) + (
float)(a12 * centDestRow) + b1 + 0.5);
5772 if ((srcCol >= 0) && (srcCol <
width))
5777 destY = centDestRow + halfDiag;
5778 destX = centDestCol + halfDiag;
5786 return rotatedImage;
5794 Point& rotatedPoint,
5799 kkint32 diag = (
kkint32)sqrt ((
float)(height * height + width * width)) + 10;
5801 float a11 = (
float)(cos (-turnAngle));
5802 float a12 = (
float)(sin (-turnAngle));
5803 float b1 = width * 0.5f;
5807 float b2 = height * 0.5f;
5809 kkint32 halfDiag = (diag + 1) / 2;
5814 kkint32 srcY = (
kkint32)((
float)(a21 * centDestCol) + (
float)(a22 * centDestRow) + b2 + 0.5);
5815 kkint32 srcX = (
kkint32)((
float)(a11 * centDestCol) + (
float)(a12 * centDestRow) + b1 + 0.5);
5838 bool firstPixelFound =
false;
5845 if (ForegroundPixel (
green[row][col]))
5851 firstPixelFound =
true;
5858 if (firstPixelFound)
5865 if (!firstPixelFound)
5868 tlRow = tlCol = brRow = brCol = -1;
5875 while ((col <
width) && (BackgroundPixel (
green[row][col])))
5893 if (ForegroundPixel (
green[row][col]))
5901 if (lastColUsed > brCol)
5902 brCol = lastColUsed;
5926 kkint32 resultHeight = Max (height, r.Height ());
5927 kkint32 resultWidth = Max (width, r.Width ());
5939 kkint32 minHeight = Min (height, r.Height ());
5940 kkint32 minWidth = Min (width, r.Width ());
5942 kkint32 resultTotPixels = resultHeight * resultWidth;
5944 memset (result->GreenArea (), 255, resultTotPixels);
5947 memset (result->RedArea (), 255, resultTotPixels);
5948 memset (result->BlueArea (), 255, resultTotPixels);
5951 for (
kkint32 r = 0; r < minHeight; ++r)
5953 for (
kkint32 c = 0; c < minWidth; ++c)
5956 int deltaC = DeltaMagnitude (
green[r][c], otherGreen[r][c]);
5958 deltaC = Min (255, deltaC + 64);
5959 resultGreen[r][c] = deltaC;
5963 resultRed [r][c] = DeltaMagnitude (
red [r][c], otherRed [r][c]);
5964 resultBlue[r][c] = DeltaMagnitude (
blue[r][c], otherBlue[r][c]);
5981 float& rowCenterWeighted,
5982 float& colCenterWeighted
5989 rowCenterWeighted = 0;
5990 colCenterWeighted = 0;
5997 for (row = 0; row <
height; row++)
5999 for (col = 0; col <
width; col++)
6001 intensity =
green[row][col];
6009 rowCenterWeighted += row * intensity;
6010 colCenterWeighted += col * intensity;
6011 weight += intensity;
6022 rowCenterWeighted /= weight;
6023 colCenterWeighted /= weight;
6037 for (x = 0; x < 256; ++x)
6042 for (
int r = 0; r <
height; ++r)
6045 for (
int c = 0; c <
width; ++c)
6047 uchar intensity = rowData[c];
6077 for (
kkint32 x = 0; x <
totPixels; ++x, ++grayPtr, ++redPtr, ++greenPtr, ++bluePtr)
6080 (0.59f) * (
float)(*greenPtr) +
6081 (0.11f) * (
float)(*bluePtr)
6097 for (row = 0; row <
height; row++)
6099 for (col = 0; col <
width; col++)
6126 errMsg <<
"Raster::Histogram ***ERROR*** channel: " <<
ColorChannelToKKStr (channel
) <<
" Is not defined.";
6127 cerr << endl << errMsg << endl << endl;
6147 delete grayScaleHistogram;
6148 grayScaleHistogram = NULL;
6150 delete equalizedHistogram;
6152 return equalizedImage;
6164 <<
"**** ERROR **** Histogram Does not have 256 Buckets[" 6165 << equalizedHistogram->NumOfBuckets () <<
"]" << std::endl
6174 if (!equalizedMapTable)
6177 <<
"**** ERROR **** Histogram Does not have EqualizeMapTable." << std::endl
6189 for (row = 0; row <
height; row++)
6191 for (col = 0; col <
width; col++)
6193 dest[row][col] = (
uchar)(equalizedMapTable[
green[row][col]]);
6197 return equalizedImage;
6222 return histogramImage;
6233 return histogramImage;
6272 if ((bpRow < 0) || (bpRow >=
height) ||
6273 (bpCol < 0) || (bpCol >=
width) ||
6274 (epRow < 0) || (epRow >=
height) ||
6275 (epCol < 0) || (epCol >=
width)
6279 <<
"*** WARNING ***" 6280 <<
"Raster::DrawLine, Out of Raster Boundaries Height[" << height <<
"] width[" << width <<
"]." << std::endl
6281 <<
" BeginPoint" << Point (bpRow, bpCol) <<
" EndPoint" << Point (epRow, epCol) <<
"." << std::endl
6286 kkint32 deltaY = epRow - bpRow;
6287 kkint32 deltaX = epCol - bpCol;
6311 for (col = startCol; col <= endCol; col++)
6313 green[row][col] = g;
6344 for (row = startRow; row <= endRow; row++)
6346 green[row][col] = g;
6357 float m = (
float)deltaY / (
float)deltaX;
6359 float c = bpRow - m * bpCol;
6377 for (col = startCol; col <= endCol; col++)
6379 row = (
kkint32)(m * col + c + 0.5);
6380 green[row][col] = g;
6404 for (row = startRow; row <= endRow; row++)
6406 col = (
kkint32)(((row - c) / m) + 0.5);
6407 green[row][col] = g;
6425 int newPixelValue = (
int)(0.5f + alpha * (
float)alphaPixel + beta * (
float)betaPixel);
6426 if (newPixelValue > 255)
6427 newPixelValue = 255;
6428 return (
uchar)newPixelValue;
6438 if ((row < 0) || (row >=
height) || (col < 0) || (col >=
width))
6441 float beta = 1.0f - alpha;
6443 green[row][col] = Min (255, (
int)(0.5f + alpha * (
float)pv.g + beta * (
float)green[row][col]));
6446 red [row][col] = Min (255, (
int)(0.5f + alpha * (
float)pv.r + beta * (
float)red [row][col]));
6447 blue[row][col] = Min (255, (
int)(0.5f + alpha * (
float)pv.b + beta * (
float)blue[row][col]));
6487 float beta = 1.0f - alpha;
6489 if ((bpRow < 0) || (bpRow >=
height) ||
6490 (bpCol < 0) || (bpCol >=
width) ||
6491 (epRow < 0) || (epRow >=
height) ||
6492 (epCol < 0) || (epCol >=
width)
6496 <<
"*** WARNING ***" 6497 <<
"Raster::DrawLine, Out of Raster Boundaries Height[" << height <<
"] width[" << width <<
"]." << std::endl
6498 <<
" BeginPoint" << Point (bpRow, bpCol) <<
" EndPoint" << Point (epRow, epCol) <<
"." << std::endl
6503 kkint32 deltaY = epRow - bpRow;
6504 kkint32 deltaX = epCol - bpCol;
6528 for (col = startCol; col <= endCol; col++)
6561 for (row = startRow; row <= endRow; row++)
6574 float m = (
float)deltaY / (
float)deltaX;
6576 float c = bpRow - m * bpCol;
6594 for (col = startCol; col <= endCol; col++)
6596 row = (
kkint32)(m * col + c + 0.5);
6621 for (row = startRow; row <= endRow; row++)
6623 col = (
kkint32)(((row - c) / m) + 0.5);
6647 if ((bpRow < 0) || (bpRow >=
height) ||
6648 (bpCol < 0) || (bpCol >=
width) ||
6649 (epRow < 0) || (epRow >=
height) ||
6650 (epCol < 0) || (epCol >=
width)
6654 <<
"*** WARNING ***" 6655 <<
"Raster::DrawFatLine, Out of Raster Boundaries Height[" << height <<
"] width[" << width <<
"]." << std::endl
6656 <<
" BeginPoint" << startPoint <<
" EndPoint" << endPoint <<
"." << std::endl
6661 kkint32 deltaY = epRow - bpRow;
6662 kkint32 deltaX = epCol - bpCol;
6686 for (col = startCol; col <= endCol; col++)
6712 for (row = startRow; row <= endRow; row++)
6718 float m = (
float)deltaY / (
float)deltaX;
6720 float c = bpRow - m * bpCol;
6738 for (col = startCol; col <= endCol; col++)
6740 row = (
kkint32)(m * col + c + 0.5);
6760 for (row = startRow; row <= endRow; row++)
6762 col = (
kkint32)(((row - c) / m) + 0.5);
6795 const Point& endPoint,
6808 const Point& endPoint,
6860 PointList::const_iterator pIDX;
6866 for (pIDX = borderPixs.begin (); pIDX != borderPixs.end (); pIDX++)
6878 green[row][col] = greenVal;
6881 red [row][col] = redVal;
6882 blue[row][col] = blueVal;
6900 PointList::const_iterator pIDX;
6907 for (pIDX = borderPixs.begin (); pIDX != borderPixs.end (); pIDX++)
6915 kkint32 distSquared = deltaRow * deltaRow + deltaCol * deltaCol;
6917 if (distSquared > 5)
6931 (row >= 0) && (col >= 0)
6934 green[row][col] = pixelValue
.g;
6937 red [row][col] = pixelValue
.r;
6938 blue[row][col] = pixelValue
.b;
6955 double radius = (
double)size / 2.0;
6956 double radiusSquared = radius * radius;
6958 kkint32 left = Max ((kkint32)0, (kkint32)floor ((
double)point.Col () - radius));
6959 kkint32 right = Min ((kkint32)(width - 1), (kkint32)ceil ((
double)point.Col () + radius));
6961 kkint32 bot = Max ((kkint32)0, (kkint32)floor ((
double)point.Row () - radius));
6962 kkint32 top = Min ((kkint32)(height - 1), (kkint32)ceil ((
double)point.Row () + radius));
6966 for (row = bot; row <= top; row++)
6969 kkint32 deltaRowSquared = deltaRow * deltaRow;
6971 if (deltaRowSquared <= radiusSquared)
6973 for (col = left; col <= right; col++)
6976 double distFromCenterSquares = deltaRowSquared + deltaCol * deltaCol;
6978 if (distFromCenterSquares <= radiusSquared)
7000 float start = -(
float)ceil (radius);
7001 float end = +(
float)floor (radius);
7003 float radiusSquare = radius * radius;
7005 for (x = start; x <= end; x++)
7007 y = (
float)sqrt (radiusSquare - (x * x));
7008 col = (
kkint32)(x + centerCol + 0.5);
7009 row = (
kkint32)(centerRow + 0.5 + y);
7012 row = (
kkint32)(centerRow + 0.5 - y);
7016 row = (
kkint32)(x + centerRow + 0.5);
7017 col = (
kkint32)(centerCol + 0.5 + y);
7020 col = (
kkint32)(centerCol + 0.5 - y);
7040 while (startAngle < 0.0f)
7041 startAngle += (
float)
TwoPie;
7043 while (startAngle >= (
float)
TwoPie)
7044 startAngle -= (
float)
TwoPie;
7046 while (endAngle < startAngle)
7047 endAngle += (
float)
TwoPie;
7049 while ((endAngle - startAngle) >= (
float)
TwoPie)
7050 endAngle -= (
float)
TwoPie;
7052 float angle = startAngle;
7053 float angleIncrement = asin (0.5f / radius);
7055 while (angle <= endAngle)
7059 float qtrAngle = angle;
7060 while (qtrAngle > (
float)
TwoPie)
7061 qtrAngle -= (
float)
TwoPie;
7063 row = -(radius * cos (angle));
7064 col = (radius * sin (angle));
7069 if ((adjRow >= 0) && (adjRow <
height) &&
7070 (adjCol >= 0) && (adjCol <
width))
7073 angle += angleIncrement;
7107 kkint32 firstMaskRow, firstMaskCol;
7108 kkint32 lastMaskRow, lastMaskCol;
7112 kkint32 maskOffset = maskSize / 2;
7114 for (row = 0; row <
height; row++)
7116 firstMaskRow = row - maskOffset;
7117 lastMaskRow = firstMaskRow + maskSize - 1;
7119 firstMaskRow = Max ((kkint32)0, firstMaskRow);
7120 lastMaskRow = Min (lastMaskRow, (kkint32)(height - 1));
7122 for (col = 0; col <
width; col++)
7124 firstMaskCol = col - maskOffset;
7125 lastMaskCol = firstMaskCol + maskSize - 1;
7126 firstMaskCol = Max (firstMaskCol, (kkint32)0);
7127 lastMaskCol = Min (lastMaskCol, (kkint32)(width - 1));
7132 for (maskRow = firstMaskRow; maskRow <= lastMaskRow; maskRow++)
7134 for (maskCol = firstMaskCol; maskCol <= lastMaskCol; maskCol++)
7136 total += src[maskRow][maskCol];
7141 dest[row][col] = (
uchar)((
kkint32)((
float)((
float)total / (
float)numOfCells) + 0.5f));
7159 SmoothImageChannel (
red, result
->Red (), maskSize);
7174 template<
typename T>
7182 kkint32 right = arraySize - 1;
7185 kkint32 pivotIndex = right;
7187 kkint32 partitionIndex = -1;
7191 while (partitionIndex != Kth)
7193 pv = values[pivotIndex];
7195 partitionIndex = left;
7196 for (kkint32 i = left; i < right; i++)
7198 if (values[i] <= pv)
7200 if (i != partitionIndex)
7203 values[i] = values[partitionIndex];
7204 values[partitionIndex] = temp;
7206 partitionIndex = partitionIndex + 1;
7210 temp = values[partitionIndex];
7211 values[partitionIndex] = values[right];
7212 values[right] = temp;
7214 if (Kth < partitionIndex)
7215 right = partitionIndex - 1;
7217 left = partitionIndex + 1;
7239 kkint32 maxCandidates = maskSize * maskSize;
7240 uchar* candidatesRed = NULL;
7241 uchar* candidatesGreen =
new uchar[maxCandidates];
7242 uchar* candidatesBlue = NULL;
7245 candidatesRed =
new uchar[maxCandidates];
7246 candidatesBlue =
new uchar[maxCandidates];
7254 kkint32 firstMaskRow, firstMaskCol;
7255 kkint32 lastMaskRow, lastMaskCol;
7259 kkint32 maskOffset = maskSize / 2;
7263 for (row = 0; row <
height; row++)
7265 firstMaskRow = row - maskOffset;
7266 lastMaskRow = firstMaskRow + maskSize - 1;
7268 firstMaskRow = Max ((kkint32)0, firstMaskRow);
7269 lastMaskRow = Min (lastMaskRow, (kkint32)(height - 1));
7271 for (col = 0; col <
width; col++)
7273 firstMaskCol = col - maskOffset;
7274 lastMaskCol = firstMaskCol + maskSize - 1;
7275 firstMaskCol = Max (firstMaskCol, (kkint32)0);
7276 lastMaskCol = Min (lastMaskCol, (kkint32)(width - 1));
7282 for (maskRow = firstMaskRow; maskRow <= lastMaskRow; maskRow++)
7284 for (maskCol = firstMaskCol; maskCol <= lastMaskCol; maskCol++)
7288 candidatesGreen[numCandidates] =
green[maskRow][maskCol];
7291 candidatesRed[numCandidates] =
green[maskRow][maskCol];
7292 candidatesBlue[numCandidates] =
green[maskRow][maskCol];
7299 middleCandidate = numCandidates / 2;
7300 uchar medium = FindKthValue (candidatesGreen, numCandidates, middleCandidate);
7301 destG[row][col] = medium;
7305 medium = FindKthValue (candidatesRed, numCandidates, middleCandidate);
7306 destR[row][col] = medium;
7307 medium = FindKthValue (candidatesBlue, numCandidates, middleCandidate);
7308 destB[row][col] = medium;
7314 delete[] candidatesRed; candidatesRed = NULL;
7315 delete[] candidatesGreen; candidatesGreen = NULL;
7316 delete[] candidatesBlue; candidatesBlue = NULL;
7336 for (hRow = 0; hRow < hHeight; hRow++)
7339 for (hCol = 0; hCol < hWidth; hCol++)
7377 uchar* workDivisorRow = NULL;
7379 for (nRow = 0; nRow < nHeight; nRow++)
7382 workRaster[nRow] = workRow;
7384 workDivisorRow =
new uchar[nWidth];
7385 workDivisor[nRow] = workDivisorRow;
7387 for (nCol = 0; nCol < nWidth; nCol++)
7390 workDivisorRow[nCol] = 0;
7397 uchar* srcRow = NULL;
7399 for (row = 0; row <
height; row++)
7401 srcRow =
green[row];
7402 intermediateCol = 0;
7404 workRow = workRaster[nRow];
7405 workDivisorRow = workDivisor[nRow];
7407 for (col = 0; col <
width; col++)
7409 workRow[nCol] += srcRow[col];
7410 workDivisorRow[nCol]++;
7413 if (intermediateCol >= multiple)
7415 intermediateCol = 0;
7421 if (intermediateRow >= multiple)
7423 intermediateRow = 0;
7430 uchar* destRow = NULL;
7434 kkint32 nForegroundPixelCount = 0;
7436 for (nRow = 0; nRow < nHeight; nRow++)
7438 destRow = (reducedRaster
->Green ())[nRow];
7439 workRow = workRaster[nRow];
7440 workDivisorRow = workDivisor[nRow];
7442 for (nCol = 0; nCol < nWidth; nCol++)
7444 newPixelVal = workRow[nCol];
7445 if (newPixelVal > 0)
7447 nForegroundPixelCount++;
7448 newPixelVal = (
kkint32)(0.5f + (
float)(newPixelVal) / (
float)(workDivisorRow[nCol]));
7449 destRow[nCol] = (
uchar)(newPixelVal);
7450 if (newPixelVal > nMaxPixVal)
7451 nMaxPixVal = newPixelVal;
7455 delete workRaster[nRow];
7456 delete workDivisor[nRow];
7457 workRaster[nRow] = NULL;
7458 workDivisor[nRow] = NULL;
7460 delete[] workRaster;
7462 delete[] workDivisor;
7468 return reducedRaster;
7478 else if (factor > 1.0f)
7493 kkint32 newTotal = newHeight * newWidth;
7495 float* accumulatorAreaGreen =
new float[newTotal];
7496 float* accumulatorAreaRed = NULL;
7497 float* accumulatorAreaBlue = NULL;
7500 accumulatorAreaRed =
new float[newTotal];
7501 accumulatorAreaBlue =
new float[newTotal];
7502 memset (accumulatorAreaRed, 0, newTotal *
sizeof (
float));
7503 memset (accumulatorAreaBlue, 0, newTotal *
sizeof (
float));
7506 float* divisorArea =
new float[newTotal];
7508 memset (accumulatorAreaGreen, 0, newTotal *
sizeof (
float));
7509 memset (divisorArea, 0, newTotal *
sizeof (
float));
7511 float** accumulatorRed = NULL;
7512 float** accumulatorGreen =
new float*[newHeight];
7513 float** accumulatorBlue = NULL;
7517 accumulatorRed =
new float*[newHeight];
7518 accumulatorBlue =
new float*[newHeight];
7522 float** divisor =
new float*[newHeight];
7524 float* rowFactor =
new float[
height + 1];
7525 float* colFactor =
new float[
width + 1];
7527 for (r = 0; r <
height; r++)
7528 rowFactor[r] = r * factor;
7529 rowFactor[
height] = (
float)newHeight;
7531 for (c = 0; c <
width; c++)
7532 colFactor[c] = c * factor;
7533 colFactor[
width] = (
float)newWidth;
7535 float* arPtr = accumulatorAreaRed;
7536 float* agPtr = accumulatorAreaGreen;
7537 float* abPtr = accumulatorAreaBlue;
7538 float* daPtr = divisorArea;
7539 for (newR = 0; newR < newHeight; newR++)
7541 accumulatorGreen [newR] = agPtr;
7542 divisor [newR] = daPtr;
7548 accumulatorRed [newR] = arPtr;
7549 accumulatorBlue[newR] = abPtr;
7555 uchar rValue = 0, gValue = 0, bValue = 0;
7557 for (r = 0; r <
height; r++)
7560 if (thisRow >= newHeight)
7561 thisRow = newHeight - 1;
7564 if (nextRow >= newHeight)
7565 nextRow = newHeight - 1;
7567 float amtThisRow = 1.0f;
7568 float amtNextRow = 0.0f;
7570 if (nextRow > thisRow)
7572 amtThisRow = (
float)nextRow - rowFactor[r];
7573 amtNextRow = 1.0f - amtThisRow;
7576 for (c = 0; c <
width; c++)
7578 gValue =
green[r][c];
7581 rValue =
red [r][c];
7582 bValue =
blue[r][c];
7586 if (thisCol >= newWidth)
7587 thisCol = newWidth - 1;
7590 if (nextCol >= newWidth)
7591 nextCol = newWidth - 1;
7593 float amtThisCol = 1.0f;
7594 float amtNextCol = 0.0f;
7596 if (nextCol > thisCol)
7598 amtThisCol = (
float)nextCol - colFactor[c];
7599 amtNextCol = 1.0f - amtThisCol;
7602 accumulatorGreen[thisRow][thisCol] += gValue * amtThisRow * amtThisCol;
7605 accumulatorRed [thisRow][thisCol] += rValue * amtThisRow * amtThisCol;
7606 accumulatorBlue[thisRow][thisCol] += bValue * amtThisRow * amtThisCol;
7609 divisor [thisRow][thisCol] += amtThisRow * amtThisCol;
7611 if (nextRow > thisRow)
7613 accumulatorGreen[nextRow][thisCol] += gValue * amtNextRow * amtThisCol;
7616 accumulatorRed [nextRow][thisCol] += rValue * amtNextRow * amtThisCol;
7617 accumulatorBlue[nextRow][thisCol] += bValue * amtNextRow * amtThisCol;
7619 divisor [nextRow][thisCol] += amtNextRow * amtThisCol;
7621 if (nextCol > thisCol)
7623 accumulatorGreen[nextRow][nextCol] += gValue * amtNextRow * amtNextCol;
7626 accumulatorRed [nextRow][nextCol] += rValue * amtNextRow * amtNextCol;
7627 accumulatorBlue[nextRow][nextCol] += bValue * amtNextRow * amtNextCol;
7629 divisor [nextRow][nextCol] += amtNextRow * amtNextCol;
7634 if (nextCol > thisCol)
7636 accumulatorGreen[thisRow][nextCol] += gValue * amtThisRow * amtNextCol;
7639 accumulatorRed [thisRow][nextCol] += rValue * amtThisRow * amtNextCol;
7640 accumulatorBlue[thisRow][nextCol] += bValue * amtThisRow * amtNextCol;
7642 divisor [thisRow][nextCol] += amtThisRow * amtNextCol;
7653 for (x = 0; x < newTotal; x++)
7655 if (divisorArea[x] == 0.0f)
7657 newGreenArea[x] = 0;
7666 newGreenArea[x] = (
uchar)(accumulatorAreaGreen[x] / divisorArea[x] + 0.5f);
7669 newRedArea [x] = (
uchar)(accumulatorAreaRed [x] / divisorArea[x] + 0.5f);
7670 newBlueArea[x] = (
uchar)(accumulatorAreaBlue[x] / divisorArea[x] + 0.5f);
7676 delete[] accumulatorAreaRed; accumulatorAreaRed = NULL;
7677 delete[] accumulatorAreaGreen; accumulatorAreaGreen = NULL;
7678 delete[] accumulatorAreaBlue; accumulatorAreaBlue = NULL;
7680 delete[] divisorArea; divisorArea = NULL;
7682 delete[] accumulatorRed; accumulatorRed = NULL;
7683 delete[] accumulatorGreen; accumulatorGreen = NULL;
7684 delete[] accumulatorBlue; accumulatorBlue = NULL;
7685 delete[] divisor; divisor = NULL;
7687 delete[] rowFactor; rowFactor = NULL;
7688 delete[] colFactor; colFactor = NULL;
7690 return reducedRaster;
7748 memcpy (dest, src, totPixels);
7769 int heighToUse = Min (height, mask->Height ());
7770 int widthToUse = Min (width, mask->Width ());
7776 for (
int row = 0; row < heighToUse; ++row)
7783 uchar* resultRedRow = NULL;
7784 uchar* srcRedRow = NULL;
7786 uchar* resultBlueRow = NULL;
7787 uchar* srcBlueRow = NULL;
7791 resultRedRow = (result
->Red ())[row];
7792 srcRedRow =
red[row];
7793 resultBlueRow = (result
->Blue ())[row];
7794 srcBlueRow =
blue[row];
7797 for (
int col = 0; col < widthToUse; ++col)
7799 bool backgroundPix = (maskBackgroundValue < 125) ? (maskRow[col] <= maskBackgroundTH) : (maskRow[col] >= maskBackgroundTH);
7800 bool usePixel = !backgroundPix;
7803 resultGreenRow[col] = srcGreenRow[col];
7806 resultRedRow [col] = srcRedRow [col];
7807 resultBlueRow[col] = srcBlueRow [col];
7827 KKStr dirName =
"c:\\Temp\\PolutionImages\\" + rootName;
7832 KKStr baseName = dirName
+ rootName;
7837 bool imageIsWhiteOnBlack =
false;
7843 float backgroundValue;
7844 float forgroundValue;
7879 for (c = 0; c <
Width (); c++)
7881 totalOfPixelVals += g[0][c];
7882 totalOfPixelVals += g[lastRow][c];
7888 totalOfPixelVals += g[r][0];
7889 totalOfPixelVals += g[r][lastCol];
7893 threshold = (
float)totalOfPixelVals / (
float)count;
7895 imageIsWhiteOnBlack = (threshold < (
float)175.0);
7898 imageIsWhiteOnBlack =
false;
7900 if (imageIsWhiteOnBlack)
7923 grayScaleHistogram
->Save (baseName
+ "_Histogram.txt");
7931 grayScaleHistogramSmoothed
->Save (baseName
+ "_HistogramSmoothed.txt");
7937 if (imageIsWhiteOnBlack)
7943 threshold = (
float)(backgroundValue + forgroundValue) / 2.0f;
7951 threshold = (
float)(backgroundValue + forgroundValue) / 2.0f;
7962 for (c = 0; c <
Width (); c++)
7964 if (imageIsWhiteOnBlack)
7966 if (g[r][c] > threshold)
7974 if (g[r][c] < threshold)
7982 delete grayScaleHistogramSmoothed;
7983 delete grayScaleHistogram;
7995 for (c = 0; c <
Width (); c++)
7999 if (imageIsWhiteOnBlack)
8029 if ((numColSplits < 1) || (numColSplits >=
width))
8032 if ((numRowSplits < 1) || (numRowSplits >=
height))
8043 kkint32 colsNeeded = numColSplits * partWidth;
8044 if (colsNeeded >
width)
8047 partStartingCol = (
width - (partWidth * numColSplits)) / 2;
8051 kkint32 rowsNeeded = numRowSplits * partHeight;
8055 rowsNeeded = numRowSplits * partHeight;
8056 partStartingRow = (
height -rowsNeeded) / 2;
8062 kkint32 partStartRow = partStartingRow;
8064 for (splitRow = 0; splitRow < numRowSplits; splitRow++)
8066 kkint32 partEndRow = partStartRow + partHeight - 1;
8068 kkint32 partStartCol = partStartingCol;
8070 for (splitCol = 0; splitCol < numColSplits; splitCol++)
8072 kkint32 partEndCol = partStartCol + partWidth - 1;
8076 parts->PushOnBack (part);
8078 partStartCol = partEndCol + 1;
8081 partStartRow = partEndRow + 1;
8103 for (r = firstRow; r < lastRow; r++)
8105 for (c = firstCol; c < lastCol; c++)
8107 if (ForegroundPixel (
green[r][c]))
8111 if ((BackgroundPixel (origGreen[r - 1][c - 1])) &&
8112 (BackgroundPixel (origGreen[r - 1][c] )) &&
8113 (BackgroundPixel (origGreen[r - 1][c + 1])) &&
8114 (BackgroundPixel (origGreen[r ][c - 1])) &&
8115 (BackgroundPixel (origGreen[r ][c + 1])))
8122 if ((BackgroundPixel (origGreen[r - 1][c - 1])) &&
8123 (BackgroundPixel (origGreen[r ][c - 1])) &&
8124 (BackgroundPixel (origGreen[r + 1][c + 1])) &&
8125 (BackgroundPixel (origGreen[r - 1][c ])) &&
8126 (BackgroundPixel (origGreen[r + 1][c ])))
8133 if ((BackgroundPixel (origGreen[r + 1][c - 1])) &&
8134 (BackgroundPixel (origGreen[r + 1][c ])) &&
8135 (BackgroundPixel (origGreen[r + 1][c + 1])) &&
8136 (BackgroundPixel (origGreen[r ][c - 1])) &&
8137 (BackgroundPixel (origGreen[r ][c + 1])))
8144 if ((BackgroundPixel (origGreen[r - 1][c + 1])) &&
8145 (BackgroundPixel (origGreen[r ][c + 1])) &&
8146 (BackgroundPixel (origGreen[r + 1][c + 1])) &&
8147 (BackgroundPixel (origGreen[r - 1][c ])) &&
8148 (BackgroundPixel (origGreen[r + 1][c ])))
8174 #if defined(DEBUG_ThinContour) 8175 kkint32 rasterGlobalHeight = 0;
8176 kkint32 rasterGlobalWidth = 0;
8189 #if defined(DEBUG_ThinContour) 8190 cout << std::endl << std::endl
8191 <<
"Raster::ThinContour" << std::endl
8194 rasterGlobalHeight = height;
8195 rasterGlobalWidth = width;
8199 bool PointsRemoved =
false;
8200 uchar m_Matrix22[3][3];
8223 PointsRemoved =
false;
8231 kkint32 minCol, maxCol, minRow, maxRow;
8239 if ((minRow > maxRow) || (minRow < 0) || (minCol < 0))
8241 #if defined(DEBUG_ThinContour) 8242 cout << std::endl << std::endl
8243 <<
"Raster::ThinContour 'FindBoundingBox'" << std::endl
8244 <<
" minRow[" << minRow <<
"] maxRow[" << maxRow <<
"]" << std::endl
8252 for (iCountY = minRow; iCountY <= maxRow; iCountY++)
8259 if (ForegroundPixel (workGreen[iCountY][x]))
8261 maxCol = Max (maxCol, x);
8262 minCol = Min (minCol, x);
8266 for (iCountX = minCol; iCountX <= maxCol; iCountX++)
8268 if (ForegroundPixel (workGreen[iCountY][iCountX]))
8273 if (ThinningSearchNeighbors (iCountX, iCountY, workGreen, &m_Matrix22[0]) &&
8279 PointsRemoved =
true;
8280 removeList.PushOnBack (tempPoint);
8284 pointList.PushOnBack (tempPoint);
8290 #if defined(DEBUG_ThinContour) 8291 cout <<
"Total black points:" << pntinpic <<
"\n";
8298 PointPtr pixel = removeList.PopFromFront ();
8303 pixel = removeList.PopFromFront ();
8307 removeList.DeleteContents ();
8313 #if defined(DEBUG_ThinContour) 8314 cout <<
"PointsRemoved = true" << pntinpic <<
"\n";
8320 for (iCountX = 0; iCountX < pointList.QueueSize (); iCountX++)
8322 tempPoint = pointList.IdxToPtr (iCountX);
8323 if (tempPoint == NULL)
8326 if (ThinningSearchNeighbors (tempPoint
->Col (), tempPoint
->Row (), workGreen, &m_Matrix22[0]) &&
8332 PointsRemoved =
true;
8335 pointList.SetIdxToPtr (iCountX, NULL);
8336 removeList.PushOnBack (tempPoint);
8344 PointPtr pixel = removeList.PopFromFront ();
8349 pixel = removeList.PopFromFront ();
8353 removeList.DeleteContents ();
8354 #if defined(DEBUG_ThinContour) 8355 cout <<
"Iteration " << Iter <<
": Points removed: " << prem1 <<
" + " << prem2 <<
" = " << prem1+prem2 <<
"\n";
8359 #if defined(DEBUG_ThinContour) 8360 cout << std::endl <<
"ThinContour Starting Step 1 PointsRemoved[" << (PointsRemoved?
"True":
"False") <<
"]" <<
"\n";
8364 while (PointsRemoved)
8371 PointsRemoved =
false;
8373 for (iCountX = 0; iCountX < pointList.QueueSize (); iCountX++)
8375 tempPoint = pointList.IdxToPtr (iCountX);
8376 if (tempPoint == NULL)
8379 if ((ThinningSearchNeighbors (tempPoint
->Col (), tempPoint
->Row (), workGreen, &m_Matrix22[0])) &&
8385 PointsRemoved =
true;
8390 pointList.SetIdxToPtr (iCountX, NULL);
8391 removeList.PushOnBack (tempPoint);
8397 #if defined(DEBUG_ThinContour) 8398 cout <<
"Set all pixels positions in Remove List in image to white. removeList.size()=[" << removeList.size () <<
"]" <<
"\n";
8403 PointPtr pixel = removeList.PopFromFront ();
8408 pixel = removeList.PopFromFront ();
8411 removeList.DeleteContents ();
8415 #if defined(DEBUG_ThinContour) 8416 cout <<
"ThinContour Starting Step 2" <<
"\n";
8420 for (iCountX = 0; iCountX < pointList.QueueSize (); iCountX++)
8422 tempPoint = pointList.IdxToPtr (iCountX);
8423 if (tempPoint == NULL)
8426 if (ThinningSearchNeighbors (tempPoint
->Col (), tempPoint
->Row (), workGreen, &m_Matrix22[0]) &&
8432 PointsRemoved =
true;
8436 pointList.SetIdxToPtr (iCountX, NULL);
8437 removeList.PushOnBack (tempPoint);
8443 #if defined(DEBUG_ThinContour) 8444 cout <<
"ThinContour LastStep in loop" <<
"\n";
8450 PointPtr pixel = removeList.PopFromFront ();
8455 pixel = removeList.PopFromFront ();
8458 removeList.DeleteContents ();
8461 #if defined(DEBUG_ThinContour) 8462 cout <<
"Iteration " << Iter <<
": Points removed: " << prem1 <<
" + " << prem2 <<
" = " << prem1 + prem2 <<
"\n";
8468 #if defined(DEBUG_ThinContour) 8469 cout <<
"ThinContour Ready to Exit; going to DeleteContents of 'pointList' and 'removeList'." <<
"\n";
8474 pointList.DeleteContents ();
8475 removeList.DeleteContents ();
8477 #if defined(DEBUG_ThinContour) 8478 cout <<
"ThinContour Exiting'." <<
"\n";
8495 if ((m_Matrix22[1][0] + m_Matrix22[2][1] + m_Matrix22[0][1]) &&
8496 (m_Matrix22[1][0] + m_Matrix22[1][2] + m_Matrix22[0][1])
8509 if ((m_Matrix22[1][0] + m_Matrix22[2][1] + m_Matrix22[1][2]) &&
8510 (m_Matrix22[2][1] + m_Matrix22[1][2] + m_Matrix22[0][1])
8524 if ((m_Matrix22[0][0]==1) && (m_Matrix22[1][0]==0)){
8527 if ((m_Matrix22[1][0]==1) && (m_Matrix22[2][0]==0)){
8530 if ((m_Matrix22[2][0]==1) && (m_Matrix22[2][1]==0)){
8533 if ((m_Matrix22[2][1]==1) && (m_Matrix22[2][2]==0)){
8536 if ((m_Matrix22[2][2]==1) && (m_Matrix22[1][2]==0)){
8539 if ((m_Matrix22[1][2]==1) && (m_Matrix22[0][2]==0)){
8542 if ((m_Matrix22[0][2]==1) && (m_Matrix22[0][1]==0)){
8545 if ((m_Matrix22[0][1]==1) && (m_Matrix22[0][0]==0)){
8548 if (iTransitions==1)
8561 uchar m_Matrix22[][3]
8566 #if defined(DEBUG_ThinContour) 8567 if ((x < 1) || (x >= (rasterGlobalWidth - 1)))
8570 <<
"k_ThinningSearchNeighbors x[" << x <<
"] is to close to the edge." <<
"\n" 8574 if ((y < 1) || (y >= (rasterGlobalHeight - 1)))
8577 <<
"k_ThinningSearchNeighbors y[" << y <<
"] is to close to the edge." <<
"\n" 8585 if ((y == 0) || (x == 0) || (y >=
height) || (x >=
width))
8589 m_Matrix22[0][0] = (g[y - 1][x - 1] > 0) ? 0:1;
8590 m_Matrix22[1][0] = (g[y - 1][x ] > 0) ? 0:1;
8591 m_Matrix22[2][0] = (g[y - 1][x + 1] > 0) ? 0:1;
8592 m_Matrix22[0][1] = (g[y ][x - 1] > 0) ? 0:1;
8593 m_Matrix22[2][1] = (g[y ][x + 1] > 0) ? 0:1;
8594 m_Matrix22[0][2] = (g[y + 1][x - 1] > 0) ? 0:1;
8595 m_Matrix22[1][2] = (g[y + 1][x ] > 0) ? 0:1;
8596 m_Matrix22[2][2] = (g[y + 1][x + 1] > 0) ? 0:1;
8597 m_Matrix22[1][1] = (g[y ][x ] > 0) ? 0:1;
8600 if (m_Matrix22[0][0] == 0) {++BlackNeighbor;}
8601 if (m_Matrix22[1][0] == 0) {++BlackNeighbor;}
8602 if (m_Matrix22[2][0] == 0) {++BlackNeighbor;}
8603 if (m_Matrix22[0][1] == 0) {++BlackNeighbor;}
8604 if (m_Matrix22[2][1] == 0) {++BlackNeighbor;}
8605 if (m_Matrix22[0][2] == 0) {++BlackNeighbor;}
8606 if (m_Matrix22[1][2] == 0) {++BlackNeighbor;}
8607 if (m_Matrix22[2][2] == 0) {++BlackNeighbor;}
8610 if ((BlackNeighbor >= 2) && (BlackNeighbor <= 6))
8627 if ((tlRow > brRow) || (tlCol > brCol))
8629 if (borderPixels < 1)
8634 kkint32 newHeight = (brRow - tlRow) + borderPixels * 2 + + 1;
8635 kkint32 newWidth = (brCol - tlCol) + borderPixels * 2 + + 1;
8646 for (oldR = tlRow; oldR <= brRow; oldR++)
8649 for (oldC = tlCol; oldC < brCol; oldC++)
8651 newGreen[newR][newC] =
green[oldR][oldC];
8654 newRed [newR][newC] =
red [oldR][oldC];
8655 newBlue[newR][newC] =
blue[oldR][oldC];
8681 resultGreen[col][row] =
green[row][col];
8684 resultRed [col][row] =
red [row][col];
8685 resultBlue[col][row] =
blue[row][col];
8706 memcpy (r->RedArea (), greenArea, totPixels);
8707 memcpy (r->GreenArea (), greenArea, totPixels);
8708 memcpy (r->BlueArea (), greenArea, totPixels);
8718 uchar pc = (255 - *srcGreen);
8736 float upperFreqBound,
8737 bool retainBackground
8740 #if defined(FFTW_AVAILABLE) 8741 fftwf_complex* src = NULL;
8742 fftwf_complex* dest = NULL;
8743 fftwf_plan plan = NULL;
8744 src = (fftwf_complex*)fftwf_malloc (
sizeof (fftwf_complex) * totPixels);
8745 dest = (fftwf_complex*)fftwf_malloc (
sizeof (fftwf_complex) * totPixels);
8747 KK_DFT2D_Float* forwardPlan =
new KK_DFT2D_Float (height, width,
true);
8749 KK_DFT2D_Float::DftComplexType* srcArea = NULL;
8750 KK_DFT2D_Float::DftComplexType** src = NULL;
8752 KK_DFT2D_Float::DftComplexType* destArea = NULL;
8753 KK_DFT2D_Float::DftComplexType** dest = NULL;
8755 forwardPlan->AllocateArray (srcArea, src);
8756 forwardPlan->AllocateArray (destArea, dest);
8765 double centerCol = (
double)
width / 2.0;
8766 double centerRow = (
double)
height / 2.0;
8768 uchar smallestPixelVal = 255;
8769 uchar largestPixelVal = 0;
8774 for (row = 0; row <
height; row++ )
8776 for (col = 0; col <
width; col++ )
8778 pixelVal =
green[row][col];
8779 if (pixelVal < smallestPixelVal)
8780 smallestPixelVal = pixelVal;
8781 if (pixelVal > largestPixelVal)
8782 largestPixelVal = pixelVal;
8786 #if defined(FFTW_AVAILABLE) 8787 src[idx][0] = (
float)green[row][col];
8792 srcArea[idx].real ((
float)(0.39f * redArea[idx] + 0.59f * greenArea[idx] + 0.11f * blueArea[idx]) / 3.0f);
8796 srcArea[idx].real ((
float)greenArea[idx]);
8798 srcArea[idx].imag (0.0f);
8805 double pixelValRange = largestPixelVal - smallestPixelVal;
8808 #if defined(FFTW_AVAILABLE) 8809 plan = fftwCreateTwoDPlan (height, width, src, dest, FFTW_FORWARD, FFTW_ESTIMATE);
8810 fftwf_execute (plan);
8811 fftwDestroyPlan (plan);
8813 forwardPlan->Transform (src, dest);
8822 double deltaRow = 0.0;
8823 double deltaRowSquared = 0.0;
8824 double deltaCol = 0.0;
8825 double deltaColSquared = 0.0;
8831 double zzz = sqrt ((
double)(centerCol * centerCol + centerRow * centerRow));
8833 double lowerFreqBoundDistFromCenter = (1.0 - (
double)lowerFreqBound) * (
double)zzz;
8834 double upperFreqBoundDistFromCenter = (1.0 - (
double)upperFreqBound) * (
double)zzz;
8836 double lowerFreqBoundDistFromCenterSquared = (lowerFreqBoundDistFromCenter * lowerFreqBoundDistFromCenter + 0.1f);
8837 double upperFreqBoundDistFromCenterSquared = (upperFreqBoundDistFromCenter * upperFreqBoundDistFromCenter - 0.1f);
8841 for (row = 0; row <
height; row++ )
8843 deltaRow = (
double)row - centerRow;
8844 deltaRowSquared = deltaRow * deltaRow;
8846 for (col = 0; col <
width; col++ )
8848 deltaCol = (
double)col - centerCol;
8849 deltaColSquared = deltaCol* deltaCol;
8851 double distFromCenterSquared = deltaRowSquared + deltaColSquared;
8853 if ((distFromCenterSquared > lowerFreqBoundDistFromCenterSquared) ||
8854 (distFromCenterSquared < upperFreqBoundDistFromCenterSquared)
8858 #if defined(FFTW_AVAILABLE) 8859 dest[idx][0] = 0.0f;
8860 dest[idx][1] = 0.0f;
8862 destArea[idx].real (0.0f);
8863 destArea[idx].imag (0.0f);
8870 #if defined(FFTW_AVAILABLE) 8871 plan = fftwCreateTwoDPlan (height, width, src, dest, FFTW_BACKWARD, FFTW_ESTIMATE);
8872 fftwf_execute (plan);
8873 fftwDestroyPlan (plan);
8875 KK_DFT2D_Float* reversePlan =
new KK_DFT2D_Float (height, width,
false);
8876 reversePlan->Transform (dest, src);
8883 #if defined(FFTW_AVAILABLE) 8884 smallestNum = largestNum = src[0][0];
8886 smallestNum = largestNum = srcArea[0].real ();
8893 #if defined(FFTW_AVAILABLE) 8896 zed = srcArea[idx].real ();
8899 if (zed < smallestNum)
8901 else if (zed > largestNum)
8906 double range = largestNum - smallestNum;
8917 if (retainBackground && BackgroundPixel (
greenArea[idx]))
8925 #if defined(FFTW_AVAILABLE) 8928 zed = srcArea[idx].real ();
8930 destData[idx] = smallestPixelVal + Min (largestPixelVal, (uchar)(0.5 + pixelValRange * (zed - smallestNum) / range));
8935 #if defined(FFTW_AVAILABLE) 8939 reversePlan->DestroyArray (srcArea, src);
8940 reversePlan->DestroyArray (destArea, dest);
8952 if (QueueSize () < 1)
8957 RasterPtr firstRaster = IdxToPtr (0);
8960 kkint32 totPixels = height * width;
8963 memset (totGreenArea, 0, totPixels *
sizeof (kkuint32));
8968 for (idx = 0; idx < QueueSize (); idx++)
8970 RasterPtr raster = IdxToPtr (idx);
8983 for (x = 0; x < totPixels; x++)
8985 totGreenArea[x] += (
kkuint32)((
float)redArea[x] * 0.39f +
8986 (
float)greenArea[x] * 0.59f +
8987 (
float)blueArea[x] * 0.11f +
8995 for (x = 0; x < totPixels; x++)
8996 totGreenArea[x] += greenArea[x];
9005 for (x = 0; x < totPixels; x++)
9006 newGreenArea[x] = (
uchar) (totGreenArea[x] / rastersAdded);
9008 delete[] totGreenArea;
9010 return smoothedRaster;
9026 for (x = 0; x < totalPixs; x++)
9057 if (compressedBuff == NULL)
9059 ofstream f (
"c:\\Temp\\Raster_FromSimpleCompression.txt", ios_base::app);
9062 <<
"DateTime" <<
"\t" << osGetLocalDateTime () <<
"\t" 9063 <<
"(compressedBuff==NULL)" 9072 if (uncompressedBuff == NULL)
9074 ofstream f (
"c:\\Temp\\Raster_FromSimpleCompression.txt", ios_base::app);
9077 <<
"DateTime" <<
"\t" << osGetLocalDateTime () <<
"\t" 9078 <<
"(uncompressedBuff==NULL)" <<
"\t" 9079 <<
"unCompressedSize" <<
"\t" << unCompressedSize
9088 kkint32 height = uncompressedBuff[0] * 256 + uncompressedBuff[1];
9089 kkint32 width = uncompressedBuff[2] * 256 + uncompressedBuff[3];
9091 if ((height < 1) || (height > 1000) || (width < 1) || (width > 1000))
9093 ofstream f (
"c:\\Temp\\Raster_FromSimpleCompression.txt", ios_base::app);
9096 <<
"DateTime" <<
"\t" << osGetLocalDateTime () <<
"\t" 9097 <<
"unCompressedSize" <<
"\t" << unCompressedSize <<
"\t" 9098 <<
"Height" <<
"\t" << height <<
"\t" 9099 <<
"Width" <<
"\t" << width
9102 f << (kkint32)compressedBuff [0] <<
"\t" 9103 << (kkint32)compressedBuff [1] <<
"\t" 9104 << (kkint32)compressedBuff [2] <<
"\t" 9105 << (kkint32)compressedBuff [3] <<
"\t" 9106 << (kkint32)compressedBuff [4] <<
"\t" 9107 << (kkint32)compressedBuff [5] <<
"\t" 9108 << (kkint32)compressedBuff [6] <<
"\t" 9109 << (kkint32)compressedBuff [7] <<
"\t" 9110 << (kkint32)compressedBuff [8] <<
"\t" 9111 << (kkint32)compressedBuff [9] <<
"\t" 9112 << (kkint32)compressedBuff[10]
9120 kkuint32 totalPixels = height * width;
9121 if (unCompressedSize > (totalPixels + 4))
9123 ofstream f (
"c:\\Temp\\Raster_FromSimpleCompression.txt", ios_base::app);
9126 <<
"DateTime" <<
"\t" << osGetLocalDateTime () <<
"\t" 9127 <<
"unCompressedSize" <<
"\t" << unCompressedSize <<
"\t" 9128 <<
"totalPixels" <<
"\t" << totalPixels <<
"\t" 9129 <<
"Height" <<
"\t" << height <<
"\t" 9130 <<
"Width" <<
"\t" << width
9133 f << (kkint32)compressedBuff [0] <<
"\t" 9134 << (kkint32)compressedBuff [1] <<
"\t" 9135 << (kkint32)compressedBuff [2] <<
"\t" 9136 << (kkint32)compressedBuff [3] <<
"\t" 9137 << (kkint32)compressedBuff [4] <<
"\t" 9138 << (kkint32)compressedBuff [5] <<
"\t" 9139 << (kkint32)compressedBuff [6] <<
"\t" 9140 << (kkint32)compressedBuff [7] <<
"\t" 9141 << (kkint32)compressedBuff [8] <<
"\t" 9142 << (kkint32)compressedBuff [9] <<
"\t" 9143 << (kkint32)compressedBuff[10]
9157 while ((nextIdx < (
kkuint32)unCompressedSize) && (greanAreaIdx < totalPixels))
9159 greenArea[greanAreaIdx] = uncompressedBuff[nextIdx];
9164 delete uncompressedBuff;
9165 uncompressedBuff = NULL;
9186 memset (buff, 0, totalDataNeeded);
9189 buff[0] = h % 256; h = h / 256;
9190 buff[1] = h % 256; h = h / 256;
9191 buff[2] = h % 256; h = h / 256;
9192 buff[3] = h % 256; h = h / 256;
9197 buff[4] = w % 256; w = w / 256;
9198 buff[5] = w % 256; w = w / 256;
9199 buff[6] = w % 256; w = w / 256;
9200 buff[7] = w % 256; w = w / 256;
9202 buff[8] = (
color ? 1 : 0);
9206 for (x = 0; x <
totPixels; x++, buffIdx++)
9211 for (x = 0; x <
totPixels; x++, buffIdx++)
9214 for (x = 0; x <
totPixels; x++, buffIdx++)
9218 compressedBuffLen = 0;
9220 delete[] buff; buff = NULL;
9221 return compressedBuff;
9234 if (!unCompressedBuff)
9237 if (unCompressedBuffLen < 10)
9239 cerr << std::endl << std::endl <<
"Raster::FromCompressor Compressor did not return any data." << std::endl;
9252 height = unCompressedBuff[0] + unCompressedBuff[1] * 256 + unCompressedBuff[2] * 256 * 256 + unCompressedBuff[3] * 256 * 256 * 256;
9253 width = unCompressedBuff[4] + unCompressedBuff[5] * 256 + unCompressedBuff[6] * 256 * 256 + unCompressedBuff[7] * 256 * 256 * 256;
9255 bool color = (unCompressedBuff[8] == 1);
9257 kkuint32 totalPixels = height * width;
9258 if ((totalPixels > (100 * 1024 * 1024)) || (height < 1) || (width < 1))
9260 cerr << std::endl << std::endl <<
"Raster::FromCompressor Height[" << height <<
"] Width[" << width <<
"] is not valid." << std::endl << std::endl;
9261 delete unCompressedBuff;
9262 unCompressedBuff = NULL;
9266 kkuint32 totalDataNeeded = totalPixels + (color ? (2 * totalPixels) : 0) + 9;
9267 if (totalDataNeeded > unCompressedBuffLen)
9269 cerr << std::endl << std::endl
9270 <<
"Raster::FromCompressor Height[" << height <<
"] Width[" << width <<
"] Color[" << (color ?
"Yes" :
"No") <<
"]" << std::endl
9271 <<
" requires TotalDataNeeded[" << totalDataNeeded <<
"] but UnCompressedBuffLen[" << unCompressedBuffLen <<
"]" << std::endl
9273 delete unCompressedBuff;
9274 unCompressedBuff = NULL;
9285 for (x = 0; x < totalPixels; x++, nextIdx++)
9286 greenArea[x] = unCompressedBuff[nextIdx];
9291 for (x = 0; x < totalPixels; x++, nextIdx++)
9292 redArea[x] = unCompressedBuff[nextIdx];
9295 for (x = 0; x < totalPixels; x++, nextIdx++)
9296 blueArea[x] = unCompressedBuff[nextIdx];
9299 delete unCompressedBuff;
9300 unCompressedBuff = NULL;
9317 for (r = 0; r <
height; r++)
9319 for (c = 0; c <
width; c++)
9325 return paddedRaster;
9335 double prefix = 1.0 / (2.0 *
PIE * sigma * sigma);
9336 double twoSigmaSquared = 2.0 * sigma * sigma;
9344 z = 256.0 * prefix * exp (-(delta * delta / twoSigmaSquared));
9359 for (row = 0; row < len; row++, x++)
9362 for (col = 0; col < len; col++, y++)
9364 double v = exp (-( (x * x + y * y) / twoSigmaSquared));
9370 for (row = 0; row < len; row++)
9372 for (col = 0; col < len; col++)
9390 kkint32 delta = kernelSideLen / 2;
9392 double** kernalData = kernel
.Data ();
9394 for (row = 0; row <
height; row++)
9396 kkint32 maskTop = row - delta;
9397 for (col = 0; col <
width; col++)
9399 kkint32 maskLeft = col - delta;
9402 double kernelTotal = 0.0;
9403 for (
kkint32 kernelRow = 0; (kernelRow < kernelSideLen) && (maskRow <
height); kernelRow++, maskRow++)
9407 double* kernalRowData = kernalData[kernelRow];
9410 for (
kkint32 kernelCol = 0; (kernelCol < kernelSideLen) && (maskCol <
width); kernelCol++, maskCol++)
9414 double fact = kernalRowData[kernelCol];
9415 total += fact * (
float)(src[maskRow][maskCol]);
9416 kernelTotal += fact;
9422 total = total / kernelTotal;
9442 SmoothUsingKernel (*kernel,
red, result
->red);
9443 SmoothUsingKernel (*kernel,
blue, result
->blue);
9464 float tempH, tempS, tempI;
9465 float y, x, r, xOriginalPoint, yOriginalPoint;
9469 xOriginalPoint = thresholdS * cos (thresholdH);
9470 yOriginalPoint = thresholdS * sin (thresholdH);
9483 x = tempS * cos (tempH);
9484 y = tempS * sin (tempH);
9488 r = (
float)(sqrt (pow (xOriginalPoint - x, 2) + pow (yOriginalPoint - y, 2) + pow (thresholdI - tempI, 2)));
9497 return resultingImage;
9518 double* totals =
new double[3];
9519 double* means =
new double[3];
9520 double** centeredVals =
new double*[3];
9521 for (col = 0; col < 3; ++col)
9525 centeredVals[col] =
new double[
totPixels];
9530 totals[0] += (
double)
redArea [row];
9532 totals[2] += (
double)
blueArea [row];
9535 for (col = 0; col < 3; ++col)
9536 means[col] = totals[col] / (
double)
totPixels;
9540 centeredVals[0][row] = (
double)
redArea [row] - means[0];
9541 centeredVals[1][row] = (
double)
greenArea [row] - means[1];
9542 centeredVals[2][row] = (
double)
blueArea [row] - means[2];
9545 for (
kkint32 varIdxX = 0; varIdxX < 3; ++varIdxX)
9547 double* varXs = centeredVals[varIdxX];
9548 for (
kkint32 varIdxY = varIdxX; varIdxY < 3; ++varIdxY)
9552 double* varYs = centeredVals[varIdxY];
9553 double total = 0.0f;
9555 total += varXs[row] * varYs[row];
9561 for (col = 0; col < 3; col++)
9563 delete[] centeredVals[col];
9564 centeredVals[col] = NULL;
9566 delete[] centeredVals; centeredVals = NULL;
9567 delete[] means; means = NULL;
9568 delete[] totals; totals = NULL;
9577 cerr << std::endl << std::endl
9578 <<
"Raster::CreateGrayScaleKLT ***ERROR*** Could not derive Eigen Vectors of covariance matrix." << std::endl
9586 double eigenValueMax = (*eigenValues)[0];
9587 for (x = 1; x < eigenValues->size (); ++x)
9589 if ((*eigenValues)[x] > eigenValueMax)
9591 eigenValueMaxIdx = x;
9592 eigenValueMax = (*eigenValues)[x];
9601 double redFact = eigenVector[0];
9602 double greenFact = eigenVector[1];
9603 double blueFact = eigenVector[2];
9604 double adjVal = 0.0;
9606 double valMin = DBL_MAX;
9607 double valMax = DBL_MIN;
9608 double* adjChannel =
new double [
totPixels];
9611 adjVal = (
double)
redArea [y] * redFact +
9614 if (adjVal < valMin) valMin = adjVal;
9615 if (adjVal > valMax) valMax = adjVal;
9616 adjChannel[y] = adjVal;
9619 if (valMax <= valMin) valMax = valMin + 1.0;
9622 double adjScaleFact = 255.0 / (valMax - valMin);
9629 resultArea[y] = (uchar)Min ((kkint32)((adjChannel[y] - valMin) * adjScaleFact + 0.5), (kkint32)255);
9632 delete[] adjChannel; adjChannel = NULL;
9633 delete cov; cov = NULL;
9634 delete eigenValues; eigenValues = NULL;
9635 delete eigenVectors; eigenVectors = NULL;
9653 cerr << std::endl << std::endl
9654 <<
"Raster::CreateGrayScaleKLTOnMaskedArea ***ERROR*** Mask image dimensions must match !!!!" << std::endl
9655 <<
" Our[" << height <<
"," << width <<
"] Mask[" << mask.height <<
"," << mask.width <<
"]." << std::endl
9670 double* totals =
new double[3];
9671 double* means =
new double[3];
9672 double** centeredVals =
new double*[3];
9673 for (col = 0; col < 3; ++col)
9677 centeredVals[col] =
new double[
totPixels];
9682 if (maskArea[row] > maskTh)
9684 totals[0] += (
double)
redArea [row];
9686 totals[2] += (
double)
blueArea [row];
9690 for (col = 0; col < 3; ++col)
9691 means[col] = totals[col] / (
double)totalMaskPixels;
9695 if (maskArea[row] > maskTh)
9697 centeredVals[0][row] = (
double)
redArea [row] - means[0];
9698 centeredVals[1][row] = (
double)
greenArea [row] - means[1];
9699 centeredVals[2][row] = (
double)
blueArea [row] - means[2];
9703 for (
kkint32 varIdxX = 0; varIdxX < 3; ++varIdxX)
9705 double* varXs = centeredVals[varIdxX];
9706 for (
kkint32 varIdxY = varIdxX; varIdxY < 3; ++varIdxY)
9710 double* varYs = centeredVals[varIdxY];
9711 double total = 0.0f;
9714 if (maskArea[row] > maskTh)
9715 total += varXs[row] * varYs[row];
9722 for (col = 0; col < 3; col++)
9724 delete centeredVals[col];
9725 centeredVals[col] = NULL;
9727 delete[] centeredVals; centeredVals = NULL;
9728 delete[] means; means = NULL;
9729 delete[] totals; totals = NULL;
9738 cerr << std::endl << std::endl
9739 <<
"Raster::CreateGrayScaleKLT ***ERROR*** Could not derive Eigen Vectors of covariance matrix." << std::endl
9747 double eigenValueMax = (*eigenValues)[0];
9748 for (
kkuint32 y = 1; y < eigenValues->size (); ++y)
9750 if ((*eigenValues)[y] > eigenValueMax)
9752 eigenValueMaxIdx = y;
9753 eigenValueMax = (*eigenValues)[y];
9763 double redFact = eigenVector[0];
9764 double greenFact = eigenVector[1];
9765 double blueFact = eigenVector[2];
9766 double adjVal = 0.0;
9768 double valMin = DBL_MAX;
9769 double valMax = -9999999999.99;
9770 double* adjChannel =
new double [
totPixels];
9773 if (maskArea[y] > maskTh)
9775 adjVal = (
double)
redArea [y] * redFact +
9778 if (adjVal < valMin) valMin = adjVal;
9779 if (adjVal > valMax) valMax = adjVal;
9780 adjChannel[y] = adjVal;
9784 adjChannel[y] = 0.0;
9788 if (valMax <= valMin) valMax = valMin + 1.0;
9791 double adjScaleFact = 255.0 / (valMax - valMin);
9798 if (maskArea[y] > maskTh)
9799 resultArea[y] = (uchar)Min ((kkint32)((adjChannel[y] - valMin) * adjScaleFact + 0.5), (kkint32)255);
9804 delete[] adjChannel; adjChannel = NULL;
9805 delete cov; cov = NULL;
9806 delete eigenValues; eigenValues = NULL;
9807 delete eigenVectors; eigenVectors = NULL;
9843 for (x = 0; x < 256; ++x)
9848 multimap<kkint32,uchar> sortedFreqCounts;
9849 for (x = 0; x < 256; ++x)
9851 if (freqCount[x] > 0)
9852 sortedFreqCounts.insert (pair<kkint32,uchar> (freqCount[x], (uchar)x));
9857 kkint32 numUniqueValues = (kkint32)sortedFreqCounts.size ();
9858 multimap<kkint32,uchar>::reverse_iterator idx;
9860 for (idx = sortedFreqCounts.rbegin (); idx != sortedFreqCounts.rend (); ++idx)
9862 kkint32 pixelValue = idx->second;
9875 destGreen[x] = pv
.g;
9876 destBlue [x] = pv
.b;
9902 kkint32 rowStart = Min (blob->RowTop (), height - 1);
9903 kkint32 rowEnd = Min (blob->RowBot (), height - 1);
9904 kkint32 colStart = Min (blob->ColLeft (), width - 1);
9905 kkint32 colEnd = Min (blob->ColRight (), width - 1);
9907 for (row = rowStart; row <= rowEnd; ++row)
9909 for (col = colStart; col <= colEnd; ++col)
9911 if (origImage
->blobIds[row][col] == blobId)
9924 PointListPtr results = NULL;
9927 float orientationAngle;
9936 if ((orientationAngle >
TwoPie) || (orientationAngle < -
TwoPie))
9938 orientationAngle = 0.0;
9953 kkint32 boxWidth = brCol - tlCol;
9954 kkint32 boxHeight = brRow - tlRow;
9956 kkint32 mark1Col = (
kkint32)((
float)boxWidth * 0.05f + 0.5f) + tlCol;
9957 kkint32 mark2Col = (
kkint32)((
float)boxWidth * 0.95f + 0.5f) + tlCol;
9971 for (
kkint32 row = tlRow; row <= brRow; ++row)
9975 uchar* rowData = imageData[row];
9977 for (col = tlCol; col <= mark1Col; ++col)
9979 if (rowData[col] > 2)
9987 for (col = mark1Col + 1; col <= mark2Col; ++col)
9989 if (rowData[col] > 2)
9997 for (col = mark2Col + 1; col <= brCol; ++col)
9999 if (rowData[col] > 2)
10008 a1PixCount = Max ((kkint32)1, a1PixCount);
10009 a2PixCount = Max ((kkint32)1, a2PixCount);
10010 a3PixCount = Max ((kkint32)1, a3PixCount);
10022 results->PushOnBack (
new Point (p1Orig));
10023 results->PushOnBack (
new Point (p2Orig));
10024 results->PushOnBack (
new Point (p3Orig));
10028 delete rotatedImage; rotatedImage = NULL;
10029 delete workRaster; workRaster = NULL;
Row & operator[](kkint32 rowIDX) const
__int16 kkint16
16 bit signed integer.
void Erosion(RasterPtr dest) const
Place into destination a eroded version of this instances image.
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for 'size' characters.
RasterPtr BandPass(float lowerFreqBound, float upperFreqBound, bool retainBackground)
Returns a image that is the result of a BandPass using Fourier Transforms.
void ErosionChanged1(MaskTypes mask, kkint32 row, kkint32 col)
static RasterPtr FromSimpleCompression(const uchar *compressedBuff, kkuint32 compressedBuffLen)
Creates a raster from a compressedBuff created by 'SimpleCompression'.
void CentralMoments(float features[9]) const
returns in 'features' the 8 central moments as defined by Hu plus eccentricity in the eight bucket...
Simple class that will compress and decompress specified buffers using the routines provided in zlib...
RasterListPtr SplitImageIntoEqualParts(kkint32 numColSplits, kkint32 numRowSplits) const
void Add16BitInt(kkuint32 i)
BlobPtr LocateMostComplete()
Locates the blob that covers the greatest part of the raster; that is the one who has the largest (He...
const MovDir movements[8]
RasterPtr ExtractABlobTightly(const BlobPtr blob, kkint32 padding) const
Extracts a specified blob from this image into a tightly bounded image.
RasterPtr CreateFromOrginalImageWithSpecifidBlobsOnly(RasterPtr origImage, BlobListPtr blobs)
Returns a copy of 'origImage' where only the blobs specified in 'blobs' are copied over...
void DrawLine(kkint32 bpRow, kkint32 bpCol, kkint32 epRow, kkint32 epCol, PixelValue pixelVal)
static void RemoveRasterInstance(const RasterPtr r)
void ConnectedComponent(uchar connectedComponentDist)
kkint32 MemoryConsumedEstimated() const
Raster(const Raster &_raster, kkint32 _row, kkint32 _col, kkint32 _height, kkint32 _width)
Constructs a new Raster using a subset of the specified Raster as its source. The dimensions of the r...
void DrawConnectedPointList(Point offset, const PointList &borderPixs, const PixelValue &pixelValue, const PixelValue &linePixelValue)
void FillBlob(RasterPtr origImage, BlobPtr blob, PixelValue color)
Will paint the specified blob with the specified color.
Point RotateDerivePreRotatedPoint(kkint32 height, kkint32 width, Point &rotatedPoint, float turnAngle) const
bool Color() const
Returns true if a Color image.
bool k_ThinningCheckTransitions(uchar m_Matrix22[][3])
void BackgroundPixelTH(uchar _backgroundPixelTH)
void ForegroundCountTH(kkint32 _foregroundCountTH)
void BackgroundCountTH(kkint32 _backgroundCountTH)
void BackgroundPixelValue(uchar _backgroundPixelValue)
void Save(KKStr fileName) const
kkint32 Width()
Number of columns that this blob occupies.
VectorDouble GetCol(kkint32 col) const
void CalcAreaAndIntensityFeatures(kkint32 &area, float &weightedSize, kkuint32 intensityHistBuckets[8], kkint32 &areaWithWhiteSpace, kkuint32 intensityHistBucketsWhiteSpace[8]) const
Calculates both Intensity Histograms, one not including internal background pixels and one with plus ...
RasterPtr CreateGrayScaleKLT() const
Creates a image using a KLT Transform with the goal of weighting in favor the color channels with gre...
RasterPtr Rotate(float turnAngle)
kkint32 NumOfBuckets() const
RasterPtr ToColor() const
void GetPixelValue(kkint32 row, kkint32 col, uchar &r, uchar &g, uchar &b) const
static PixelValue Magenta
void Erosion(MorphOp::StructureType _structure, kkuint16 _structureSize, kkint32 _backgroundCountTH)
RasterPtr CreateDilatedRaster(MaskTypes mask) const
RasterPtr FastFourier() const
Raster(const KKStr &fileName, bool &validFile)
Constructs a Raster image from by reading an existing image File such as a BMP file.
void CalcCentroid(kkint32 &size, kkint32 &weight, float &rowCenter, float &colCenter, float &rowCenterWeighted, float &colCenterWeighted) const
KKStr ColorChannelToKKStr(ColorChannels c)
bool BackgroundPixel(kkint32 row, kkint32 col) const
RasterPtr CreateErodedImage(MaskTypes mask) const
void DrawLine(kkint32 bpRow, kkint32 bpCol, kkint32 epRow, kkint32 epCol, uchar pixelVal)
uchar BackgroundPixelValue() const
Matrix(kkint32 _numOfRows, kkint32 _numOfCols)
static uchar * Decompress(const uchar *compressedBuff, kkuint32 compressedBuffLen, kkuint32 &unCompressedSize)
Point operator+(const Point &r) const
void MaxPixVal(uchar _maxPixVal)
void SetPixelValue(kkint32 row, kkint32 col, uchar pixVal)
virtual RasterPtr AllocateARasterInstance(kkint32 height, kkint32 width, bool color) const
void DrawPointList(const PointList &borderPixs, uchar redVal, uchar greenVal, uchar blueVal)
uchar foregroundPixelValue
BlobListPtr ExtractBlobs(kkint32 dist)
Will extract a list of connected components from this instance.
void DrawCircle(float centerRow, float centerCol, float radius, float startAngle, float endAngle, const PixelValue &pixelValue)
RasterPtr HistogramEqualizedImage(HistogramPtr equalizedHistogram) const
unsigned __int16 kkuint16
16 bit unsigned integer.
uchar * ToCompressor(kkuint32 &compressedBuffLen) const
Compresses the image in Raster using zlib library and returns a pointer to compressed data...
static void Destroy(volatile GoalKeeperPtr &_goalKeeperInstance)
Destroys an existing instance of GoalKeeper.
PixelValue & operator=(const PixelValue &right)
A class that is used by to represent a single image in memory.
void ErodeSpurs()
removes spurs from image.
MorphOpErosion(StructureType _structure, kkuint16 _structureSize)
static void AddRasterInstance(const RasterPtr r)
Supports two dimensional matrices.
RasterPtr HistogramImage(ColorChannels channel) const
void DrawPointList(Point offset, const PointList &borderPixs, uchar redVal, uchar greenVal, uchar blueVal)
float CalcWeightedArea() const
static std::map< RasterPtr, RasterPtr > allocatedRasterInstances
Supports the tracking down of memory leaks in Raster; it will be called every time a new instance of ...
void FourierExtractFeatures(float fourierFeatures[5]) const
static StructureType MaskShapes(MaskTypes mt)
void ReduceToMostCompleteBlob(uchar connectedComponentDist)
Locates most complete blob; that is the one with the largest (Height x Width); and removes all other ...
kkint32 foregroundPixelCount
static kkint32 Biases(MaskTypes mt)
void Initialize(kkint32 _height, kkint32 _width, uchar *_Data, uchar **_Rows, bool _takeOwnership)
Sets an existing instance to specific Raster Data of a image.
RasterPtr CreateGraph() const
static void Create(const KKStr &_name, volatile GoalKeeperPtr &_newGoalKeeper)
Create a GoalKeeper object and avoid a race condition doing it.
BlobPtr NewBlob(kkuint32 rowTop, kkuint32 colLeft)
kkint32 Max6(kkint32 x1, kkint32 x2, kkint32 x3, kkint32 x4, kkint32 x5, kkint32 x6)
bool k_ThinningStep1cdTests(uchar m_Matrix22[][3])
void SetPixelValue(ColorChannels channel, kkint32 row, kkint32 col, uchar pixVal)
Raster(const Raster &_raster, MaskTypes _mask, kkint32 _row, kkint32 _col)
Constructs a Raster that will be the same size as the specified '_mask' with the top left specified b...
const KKStr & FileName() const
KKStr operator+(const char *right) const
void Erosion(MaskTypes mask)
void WhiteOutBackground()
Sets all pixels that are in the Background Range ov values to BackgroundPixelValue.
RasterPtr ExtractABlob(const BlobPtr blob) const
Extracts a specified blob from this image; useful to extract individual detected blobs.
const uchar * RedRow(kkint32 row) const
Returns the specified Row from the Red Channel.
unsigned int uint
Unsigned integer.
void SetPixelValue(kkint32 row, kkint32 col, const PixelValue &pixVal)
unsigned __int32 kkuint32
RasterPtr ReadImage(const KKStr &imageFileName)
Raster(kkint32 _height, kkint32 _width)
Constructs a blank image with given dimensions; all pixels will be initialized to 0...
static void * Decompress(const void *compressedBuff, kkuint32 compressedBuffLen, kkuint32 &unCompressedLen)
void ToHSI(float &hue, float &sat, float &intensity) const
Computes the equivalent HSI values; RGB -> HSI.
kkint32 Height()
Number of rows that the blob occupies.
const uchar * ImageRow(kkint32 row) const
Returns the specified Row from the Green Channel.
virtual RasterPtr PerformOperation(RasterConstPtr _image)
static MatrixPtr BuildGaussian2dKernel(float sigma)
Builds a 2d Gaussian kernel.
uchar MergeAlpfaBeta(float alpha, uchar alphaPixel, float beta, uchar betaPixel)
uchar ForegroundPixelValue() const
kkint32 NumOfCols() const
uchar backgroundPixelValue
void GetPixelValue(kkint32 row, kkint32 col, PixelValue &p) const
void ReSize(kkint32 _height, kkint32 _width, bool _color)
Lets you resize the raster dimensions; old image data will be lost.
double & operator[](kkint32 idx)
void CalcAreaAndIntensityHistogram(kkint32 &area, kkuint32 intensityHistBuckets[8]) const
Calculates the occurrence of different intensity levels.
RasterPtr Padded(kkint32 padding)
static void * CreateCompressedBuffer(void *source, kkuint32 sourceLen, kkuint32 &compressedBuffLen)
RasterPtr ReduceByFactor(float factor) const
KK_DFT2D< float > KK_DFT2D_Float
void Edge(RasterPtr dest)
RasterPtr CreateSmoothedFrame()
Used by Raster class and MorphOp derived classes to denote a single pixel location in Raster image...
RasterPtr ExtractChannel(ColorChannels channel)
Will return a gray-scale image consisting of the specified color channel only.
void DrawDot(const Point &point, const PixelValue &color, kkint32 size)
void EigenVectors(MatrixPtr &eigenVectors, VectorDouble *&eigenValues) const
Will derive the Eigen vectors and values of the matrix.
float AverageOfMaxBucketInRange(kkint32 firstBucket, kkint32 lastBucket) const
void FillHole(RasterPtr mask)
Fills holes in the image using the 'mask' raster as a work area.
void ForegroundPixelValue(uchar _foregroundPixelValue)
RasterList * RasterListPtr
RasterPtr CreateColorImageFromLabels()
Produces a color image using the 'greenArea' channel, assuming that each unique value will be assigne...
KK_DFT1D< float > KK_DFT1D_Float
KKStr operator+(const char *left, const KKStr &right)
float CentroidCol() const
Used to encode and decode BMP Images.
void DrawLine(kkint32 bpRow, kkint32 bpCol, kkint32 epRow, kkint32 epCol, uchar r, uchar g, uchar b)
HistogramPtr HistogramGrayscale() const
RasterPtr CreateColor() const
RasterPtr SobelEdgeDetector() const
KKStr(const KKStr &str)
Copy Constructor.
void StartBlock()
Initiates a Block as long as another thread has not already locked this object.
PixelValue(uchar _r, uchar _g, uchar _b)
Constructs a 'PixelValue' instance using the provided values for the color components.
void CalcAreaAndIntensityFeatures(kkint32 &area, float &weightedSize, kkuint32 intensityHistBuckets[8]) const
Calculates both Intensity Histograms, one not including internal background pixels and one with plus ...
void SaveImage(const Raster &image, const KKStr &imageFileName)
void Initialize(kkint32 _height, kkint32 _width, uchar *_redArea, uchar **_red, uchar *_greenArea, uchar **_green, uchar *_blueArea, uchar **_blue, bool _takeOwnership)
Sets an existing instance to specific Raster Data of a image.
void DrawLine(kkint32 bpRow, kkint32 bpCol, kkint32 epRow, kkint32 epCol)
uchar GetPixelValue(ColorChannels channel, kkint32 row, kkint32 col) const
T FindKthValue(T *values, kkint32 arraySize, kkint32 Kth)
kkint32 Max9(kkint32 x1, kkint32 x2, kkint32 x3, kkint32 x4, kkint32 x5, kkint32 x6, kkint32 x7, kkint32 x8, kkint32 x9)
void Dilation(RasterPtr dest) const
void Dilation(MaskTypes mask)
RasterPtr SwapQuadrants() const
const KKStr & FileName() const
SimpleCompressor(kkuint32 estimatedMaxBuffSize)
ColorChannels ColorChannelFromKKStr(const KKStr &s)
RasterPtr ReduceByEvenMultiple(kkint32 multiple) const
kkint32 BlobId(kkint32 row, kkint32 col) const
Return the ID of the blob that the specified pixel location belongs to.
MorphOpStretcher(float _rowFactor, float _colFactor)
RasterPtr TightlyBounded(kkuint32 borderPixels) const
void EndBlock()
Ends the block and allows other threads to pass through StatBlock.
unsigned char uchar
Unsigned character.
void SetPixelValue(kkint32 row, kkint32 col, uchar r, uchar g, uchar b)
kkint32 ForegroundPixelCount() const
void DrawLine(kkint32 bpRow, kkint32 bpCol, kkint32 epRow, kkint32 epCol, PixelValue pixelVal, float alpha)
Histogram * Smooth(kkint32 smoothWidth)
bool k_ThinningStep2cdTests(uchar m_Matrix22[][3])
void TakeOwnershipOfAnotherRastersData(Raster &otherRaster)
Will take ownership of 'otherRaster' raster dynamically allocated data and copy its non dynamically a...
RasterPtr FindMagnitudeDifferences(const Raster &r)
Returns an image that reflects the differences between this image and the image supplied in the param...
uchar BackgroundPixelTH() const
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
static void PrintOutListOfAllocatedrasterInstances()
void Edge()
reduces image to edge pixels only.
void Dilation(RasterPtr dest, MaskTypes mask) const
RasterPtr SegmentImage(bool save=false)
RasterPtr HistogramGrayscaleImage() const
static RasterPtr FromCompressor(const uchar *compressedBuff, kkuint32 compressedBuffLen)
Creates a new instance of Raster object from zLib compressed data.
void ErosionChanged(MaskTypes mask, kkint32 row, kkint32 col)
void DrawPointList(Point offset, const PointList &borderPixs, const PixelValue &pixelValue)
void Erosion(RasterPtr dest, MaskTypes mask) const
void MergeBlobIds(BlobPtr blob, kkint32 blobId, kkint32 **blobIds)
Used by the Connected component analysis to merge two blobs together.
Histogram(float _minValue, kkint32 _numOfBuckets, float _bucketSize, bool _wrapArround)
static volatile GoalKeeperPtr goalKeeper
void SetPixelValue(const Point &point, const PixelValue &pixVal)
kkint32 freqHist16BucketIdx[256]
kkint32 TotPixels() const
kkint32 TotalBackgroundPixels() const
void DrawCircle(const Point &point, kkint32 radius, const PixelValue &color)
Draw a circle who's center is at 'point' and radius in pixels is 'radius' using color 'color'...
RasterPtr CreateSmoothImage(kkint32 maskSize=3) const
PointListPtr DeriveImageLength() const
KKStr StrFormatInt(kkint32 val, const char *mask)
MorphOpDilation(StructureType _structure, kkuint16 _structureSize)
static RasterPtr CreatePaddedRaster(BmpImage &image, kkint32 padding)
kkint32 * EqualizedMapTable()
Raster(kkint32 _height, kkint32 _width, bool _color)
Constructs a blank image with given dimensions.
Raster(kkint32 _height, kkint32 _width, const uchar *_Data)
Construct a Raster object using provided raw data.
KKStr operator+(const KKStr &right) const
const uchar * BlueRow(kkint32 row) const
Returns the specified Row from the Blue Channel.
uchar * GreenArea() const
uchar ** GetSubSet(uchar **_src, kkint32 _row, kkint32 _col, kkint32 _height, kkint32 _width) const
Returns back a two dimension array that is a copy of the specified region in the image.
RasterPtr ExtractUsingMask(RasterPtr mask)
Extracts the pixel locations where the 'mask' images pixel location is a foreground pixel...
void DrawLine(const Point &beginPoint, const Point &endPoint, uchar pixelVal)
Point(kkint32 _row, kkint32 _col)
void FindBoundingBox(kkint32 &tlRow, kkint32 &tlCol, kkint32 &brRow, kkint32 &brCol) const
void CalcAreaAndIntensityFeatures16(kkint32 &area, float &weighedSize, kkuint32 intensityHistBuckets[16])
virtual RasterPtr AllocateARasterInstance(const Raster &_raster, kkint32 _row, kkint32 _col, kkint32 _height, kkint32 _width) const
static PixelValue FromHSI(float hue, float sat, float intensity)
Will create an instance of PixelValue from the HSI values provided (HSI -> RGB).
virtual RasterPtr PerformOperation(RasterConstPtr _image)
HistogramPtr Histogram(ColorChannels channel) const
static volatile bool rasterInitialized
bool AreThereEdgePixels(kkint32 edgeWidth)
returns true if there are any foreground pixels within 'edgeWidth' pixels of the top, bottom, left, or right edges of the image.
void CalcAreaAndIntensityHistogramWhite(kkint32 &area, kkuint32 intensityHistBuckets[8])
Calculates a Intensity Histogram including Background pixels in the image.
Maintains a list of blobs.
RasterPtr ThresholdInHSI(float thresholdH, float thresholdS, float thresholdI, float distance, const PixelValue &flagValue)
void SaveGraphImage(const KKStr &fileName) const
void ComputeCentralMoments(kkint32 &foregroundPixelCount, float &weightedPixelCount, float centralMoments[9], float centralMomentsWeighted[9]) const
Computes central moments; one set where each pixel is treated as 1 or 0(Foreground/Background) and th...
virtual RasterPtr PerformOperation(RasterConstPtr _image)
Raster(const BmpImage &_bmpImage)
Constructs a Raster from a BMP image loaded from disk.
void tqli(kkint32 n, double *d, double *e, double z[2][2])
void CentralMomentsWeighted(float features[9]) const
Similar to 'CentralMoments' except each pixel position is weighted by its intensity value...
KKException(const char *_exceptionStr)
Raster(kkint32 _height, kkint32 _width, uchar *_Data, uchar **_Rows)
Construct a raster object that will utilize a image already in memory.
KKStr & operator=(const KKStr &src)
Base class for all Morphological operations.
MorphOpBinarize(kkuint16 _pixelValueMin, kkuint16 _pixelValueMax)
BlobPtr LocateLargestBlob()
Will return Blob with largest pixel count.
virtual RasterPtr AllocateARasterInstance(const Raster &r) const
void Tred2(kkint32 n, double a[2][2], double *d, double *e)
void PaintFatPoint(kkint32 row, kkint32 col, const PixelValue pv, float alpha)
Container object used to maintaining a list of pixel locations.
void Increment(float val)
kkint32 MemoryConsumedEstimated() const
void Dilation(MorphOp::StructureType _structure, kkuint16 _structureSize, kkint32 _foregroundCountTH)
void DrawCircle(float centerRow, float centerCol, float radius, const PixelValue &pixelValue)
void DrawLine(const Point &beginPoint, const Point &endPoint, const PixelValue &pixelVal)
Raster(const Raster &_raster)
Copy Constructor.
void DrawPointList(const PointList &borderPixs, const PixelValue &pixelValue)
void Opening(MaskTypes mask)
RasterPtr HistogramEqualizedImage() const
float CentroidRow() const
RasterPtr CreateGrayScaleKLTOnMaskedArea(const Raster &mask) const
Same as 'CreateKLT' except it will only take into account pixels specified by the 'mask' image...
uchar * CreateCompressedBuffer(kkuint32 &compressedBuffserSize)
virtual RasterPtr PerformOperation(Raster const *_image)
kkint32 freqHistBucketIdx[256]
RasterPtr ReversedImage()
void DrawFatLine(Point startPoint, Point endPoint, PixelValue pv, float alpha)
KKException(const KKStr &_exceptionStr)
void FileName(const KKStr &_fileName)
bool ForegroundPixel(kkint32 row, kkint32 col) const
RasterPtr CreateGrayScale() const
void PaintPoint(kkint32 row, kkint32 col, const PixelValue &pv, float alpha)
uchar * SimpleCompression(kkuint32 &buffLen) const
Compresses the image in Raster using a simple Run length algorithm and returns a pointer to compresse...
RasterPtr ThinContour() const
void DrawLine(kkint32 bpRow, kkint32 bpCol, kkint32 epRow, kkint32 epCol, uchar r, uchar g, uchar b, float alpha)
bool osCreateDirectoryPath(KKStr _pathName)
Will create the whole Directory Path not just the final part of the path.
RasterPtr Transpose() const
RasterPtr CreateColorWithBlobsLabeldByColor(BlobListPtr blobs)
Returns image where each blob is labeled with a different color.
Raster(kkint32 _height, kkint32 _width, const uchar *_redChannel, const uchar *_greenChannel, const uchar *_blueChannel)
Construct a Color Raster object using provided raw data,.
void DrawGrid(float pixelsPerMinor, kkuint32 minorsPerMajor, const PixelValue &hashColor, const PixelValue &gridColor)
RasterPtr CreateDilatedRaster() const
void FollowContour(float countourFreq[5]) const
Point(kkint16 _row, kkint16 _col)
BlobPtr LookUpByBlobId(kkint32 blobId)
Will return pointer to blob with 'blobId'; if not found will return NULL.
RasterPtr CreateGaussianSmoothedImage(float sigma) const
Used to manage the construction of a Histogram.
RasterPtr FastFourierKK() const
kkint32 Id()
The unique ID assigned to this blob.
void ErosionBoundary(MaskTypes mask, kkint32 blobrowstart, kkint32 blobrowend, kkint32 blobcolstart, kkint32 blobcolend)
#define INT_MAX
Adapted by Kurt Kramer be a 'class' definition so as to make it more usable in th ePices software wor...
double **const Data() const
void ConnectedComponent8Conected()
static void FinalCleanUp()
Used by the Raster Class to represent the contents of one pixel.
BlobPtr MergeIntoSingleBlob(BlobPtr blob1, kkint32 blob2Id, kkint32 **blobIds)
void CalcOrientationAndEigerRatio(float &eigenRatio, float &orientationAngle)
RasterPtr StreatchImage(float rowFactor, float colFactor) const
std::vector< double > VectorDouble
Vector of doubles.
kkint32 Min(kkint32 x1, kkint32 x2)
virtual RasterPtr PerformOperation(RasterConstPtr _image)
void ForegroundPixelCount(kkint32 _foregroundPixelCount)
KKStr osGetRootName(const KKStr &fullFileName)
float DeltaAngle(float ang1, float ang2)
Returns the difference between two angles in degrees.
void FillRectangle(kkint32 tlRow, kkint32 tlCol, kkint32 brRow, kkint32 brCol, const PixelValue &fillColor)
RasterPtr BinarizeByThreshold(uchar min, uchar max) const
RasterPtr CreateSmoothedMediumImage(kkint32 maskSize) const
void osDisplayWarning(KKStr _message)
void Closing(MaskTypes mask)
void osAddLastSlash(KKStr &fileSpec)
Will add the appropriate Directory separator character to the end of fileSpec if one is not there alr...
uchar GetPixelValue(kkint32 row, kkint32 col) const