33 #include "Core/include/private/DImage.hpp"
72 PixelSequence(
size_t off,
size_t siz) : offset(off), size(siz)
83 vector<PixelSequence> sequences;
84 typedef vector<PixelSequence>::iterator sequences_iterator;
85 typedef vector<PixelSequence>::const_iterator sequences_const_iterator;
86 typedef vector<PixelSequence>::const_reverse_iterator
87 sequences_const_reverse_iterator;
102 ASSERT(CHECK_ALLOCATED(&imIn), RES_ERR_BAD_ALLOCATION, blobs);
104 typename ImDtTypes<T>::sliceType lines = imIn.
getLines();
105 typename ImDtTypes<T>::lineType pixels;
111 for (
size_t l = 0; l < nlines; l++) {
113 size_t curStart = l * npix;
117 if (curVal != 0 || !onlyNonZero)
120 for (
size_t i = 1; i < npix; i++) {
121 if (pixels[i] == curVal)
124 if (curVal != 0 || !onlyNonZero)
125 blobs[curVal].sequences.push_back(
PixelSequence(curStart, curSize));
126 curStart = i + l * npix;
131 if (curVal != 0 || !onlyNonZero)
132 blobs[curVal].sequences.push_back(
PixelSequence(curStart, curSize));
150 template <
class labelT,
class T>
153 T defaultValue = T(0))
155 ASSERT_ALLOCATED(&imOut);
160 ASSERT(
fill(imOut, defaultValue) == RES_OK);
162 typename ImDtTypes<T>::lineType pixels = imOut.getPixels();
163 size_t pixCount = imOut.getPixelCount();
164 bool allBlobsFit =
true;
166 typename map<labelT, Blob>::const_iterator blob_it;
167 for (blob_it = blobs.begin(); blob_it != blobs.end(); blob_it++) {
169 Blob::sequences_const_reverse_iterator last =
170 blob_it->second.sequences.rbegin();
171 if ((*last).offset + (*last).size > pixCount) {
174 Blob::sequences_const_iterator it = blob_it->second.sequences.begin();
175 Blob::sequences_const_iterator it_end = blob_it->second.sequences.end();
177 T outVal = blobsValue != defaultValue ? blobsValue : blob_it->first;
178 for (; it != it_end; it++) {
179 typename ImDtTypes<T>::lineType line = pixels + (*it).offset;
180 for (
size_t i = 0; i < it->size; i++)
187 ASSERT(allBlobsFit,
"Some blobs are outside the image", RES_ERR);
202 template <
class labelT,
class T>
203 RES_T
drawBlobs(map<labelT, Blob> &blobs, map<labelT, T> &lut,
204 Image<T> &imOut,
bool fillFirst =
true, T defaultValue = T(0))
206 ASSERT_ALLOCATED(&imOut);
211 ASSERT(
fill(imOut, defaultValue) == RES_OK);
213 typename ImDtTypes<T>::lineType pixels = imOut.getPixels();
214 size_t pixCount = imOut.getPixelCount();
215 bool allBlobsFit =
true;
217 typename map<labelT, Blob>::const_iterator blob_it;
218 for (blob_it = blobs.begin(); blob_it != blobs.end(); blob_it++) {
220 Blob::sequences_const_reverse_iterator last =
221 blob_it->second.sequences.rbegin();
222 if ((*last).offset + (*last).size > pixCount) {
225 Blob::sequences_const_iterator it = blob_it->second.sequences.begin();
226 Blob::sequences_const_iterator it_end = blob_it->second.sequences.end();
228 typename map<labelT, T>::const_iterator valIt =
229 lut.find(blob_it->first);
230 T outVal = valIt != lut.end() ? valIt->second : defaultValue;
231 for (; it != it_end; it++) {
232 typename ImDtTypes<T>::lineType line = pixels + (*it).offset;
233 for (
size_t i = 0; i < it->size; i++)
240 ASSERT(allBlobsFit,
"Some blobs are outside the image", RES_ERR);
255 template <
class labelT>
260 typename map<labelT, Blob>::const_iterator blob_it;
261 typedef typename Blob::sequences_const_iterator seqit_t;
263 for (blob_it = blobs.begin(); blob_it != blobs.end(); blob_it++) {
264 seqit_t it_end = blob_it->second.sequences.end();
266 for(seqit_t it = blob_it->second.sequences.begin(); it != it_end; it++)
268 if (offset >= it->offset && offset < it->offset + it->size)
289 template <
class labelT,
class T>
296 typename map<labelT, Blob>::const_iterator blob_it;
297 typedef typename Blob::sequences_const_iterator seqit_t;
299 for (blob_it = blobs.begin(); blob_it != blobs.end(); blob_it++) {
300 seqit_t it_end = blob_it->second.sequences.end();
302 for(seqit_t it = blob_it->second.sequences.begin(); it != it_end; it++)
304 if (offset >= it->offset && offset < it->offset + it->size)
size_t getOffsetFromCoords(size_t x, size_t y, size_t z=0) const
Get an offset for given x,y(,z) coordinates.
Definition: DBaseImage.h:263
size_t getWidth() const
Get image width.
Definition: DBaseImage.h:80
size_t getLineCount() const
Get the number of lines.
Definition: DBaseImage.h:165
Definition: DBaseImage.h:386
Main Image class.
Definition: DImage.hpp:57
sliceType getLines() const
Get an array containing the start offset of each line.
Definition: DImage.hpp:111
RES_T fill(Image< T > &imOut, const T &value)
fill() - Fill an image with a given value.
Definition: DImageArith.hpp:1456
int getBlobIDFromOffset(Image< T > imIn, map< labelT, Blob > &blobs, int x, int y, int z=0)
getBlobIDFromOffset() - get the blob ID which contains a pixel (or voxel) given its coordinates
Definition: DBlob.hpp:290
map< T, Blob > computeBlobs(const Image< T > &imIn, bool onlyNonZero=true)
Create a map of blobs from a labeled image.
Definition: DBlob.hpp:98
RES_T drawBlobs(map< labelT, Blob > &blobs, map< labelT, T > &lut, Image< T > &imOut, bool fillFirst=true, T defaultValue=T(0))
Represent Blobs in an image with a lookup map.
Definition: DBlob.hpp:203
List of offset and size of line contiguous pixels.
Definition: DBlob.hpp:82
Definition: DTypes.hpp:88
Start offset and length of pixels in an image.
Definition: DBlob.hpp:63