9 # include <vcl_msvc_warnings.h> 36 unsigned int sbi = blk.
ni(), sbj = blk.
nj();
39 for (
unsigned int dj = 0; dj<sbj; ++dj)
41 unsigned int r = 0, j0 = 2*dj;
47 for (
unsigned int di = 0; di<sbi; ++di)
49 unsigned int c = 0, i0 = 2*di;
57 0.25f*(blk(i0, j0)+blk(i0+1,j0)+blk(i0,j0+1)+blk(i0+1,j0+1));
58 dec_block(di, dj) =
v;
68 if (!blk)
return false;
71 unsigned int ni = blk->ni(), nj = blk->nj();
72 unsigned int np = blk->nplanes();
76 for (
unsigned int p = 0; p<np; ++p){
78 for (
unsigned int j = 0; j<nj; ++j)
79 for (
unsigned int i= 0; i<ni; ++i)
88 for (
unsigned int p = 0; p<np; ++p){
90 for (
unsigned int j = 0; j<nj; ++j)
91 for (
unsigned int i= 0; i<ni; ++i)
104 unsigned int ni = fblk[0].ni(), nj = fblk[0].nj();
105 auto np = (
unsigned int)(fblk.size());
106 for (
unsigned int p = 0; p<np; ++p)
107 for (
unsigned int j = 0; j<nj; ++j)
108 for (
unsigned int i= 0; i<ni; ++i)
109 blk(i,j,p) = static_cast<unsigned char>(fblk[p](i,j));
116 unsigned int ni = fblk[0].ni(), nj = fblk[0].nj();
117 auto np = (
unsigned int)(fblk.size());
118 for (
unsigned int p = 0; p<np; ++p)
119 for (
unsigned int j = 0; j<nj; ++j)
120 for (
unsigned int i= 0; i<ni; ++i)
121 blk(i,j,p) = static_cast<unsigned short>(fblk[p](i,j));
130 unsigned int nbi = brsc->n_block_i(), nbj = brsc->n_block_j();
133 unsigned int np = brsc->nplanes();
136 unsigned int sbi_src = brsc->size_block_i(), sbj_src = brsc->size_block_j();
137 unsigned int sbi_dec = dec_resc->size_block_i(),
138 sbj_dec = dec_resc->size_block_j();
139 if (sbi_src!=sbi_dec||sbj_src!=sbj_dec)
164 std::vector<std::vector<vil_image_view<float> > > buf(2), nbrhd(2);
165 for (
unsigned int k =0; k<2; ++k)
167 buf[k] = std::vector<vil_image_view<float> >(nbi);
168 nbrhd[k] = std::vector<vil_image_view<float> >(2);
171 for (
unsigned int bj=0; bj<nbj; bj+=2)
174 for (
unsigned int bi = 0; bi<nbi; ++bi)
181 buf[1][bi]=buf[0][bi];
183 for (
unsigned int bi=0; bi<nbi; bi+=2)
186 for (
unsigned int r = 0; r<2; ++r)
187 for (
unsigned int c = 0; c<2; ++c)
189 unsigned int ki = bi+c;
192 nbrhd[r][c] = buf[r][ki];
195 dec_blk = decimate_block(nbrhd);
199 #define CONVERT_BLOCK_CASE(FORMAT, T) \ 201 vil_image_view<T> out_blk; \ 202 vil_convert_cast(dec_blk, out_blk); \ 203 if (!dec_resc->put_block(bi/2, bj/2, out_blk )) \ 215 #undef CONVERT_BLOCK_CASE 218 assert(!
"Unknown vil data type in pyramid image construction");
228 std::vector<std::vector<std::vector<vil_image_view<float> > > > buf(2);
229 std::vector<std::vector<vil_image_view<float> > > nbrhd(2);
230 for (
unsigned int k =0; k<2; ++k)
232 buf[k] = std::vector<std::vector<vil_image_view<float> > >(nbi);
233 nbrhd[k] = std::vector<vil_image_view<float> >(2);
238 for (
unsigned int bj=0; bj<nbj; bj+=2)
241 for (
unsigned int bi = 0; bi<nbi; ++bi)
244 std::vector<vil_image_view<float> > fbij;
246 if (!convert_multi_plane_to_float(bij, fbij))
return false;
250 bij = brsc->get_block(bi,bj+1);
252 if (!convert_multi_plane_to_float(bij, fbij))
return false;
256 buf[1][bi]=buf[0][bi];
258 for (
unsigned int bi=0; bi<nbi; bi+=2)
260 std::vector<vil_image_view<float> >dec_fblk(np);
262 for (
unsigned int p = 0; p<np; ++p){
263 for (
unsigned int r = 0; r<2; ++r)
264 for (
unsigned int c = 0; c<2; ++c)
266 unsigned int ki = bi+c;
269 nbrhd[r][c] = buf[r][ki][p];
279 convert_multi_plane_from_float(dec_fblk, dblk);
280 dec_resc->put_block(bi/2, bj/2, dblk);
284 convert_multi_plane_from_float(dec_fblk, dblk);
285 dec_resc->put_block(bi/2, bj/2, dblk);
313 case VIL_PIXEL_FORMAT_UINT_64:
321 std::cout <<
"unrecognized pixel format in vil_pyramid_image_resource::decimate()\n";
326 if (brsc&&(brsc->size_block_i()%2!=0||brsc->size_block_j()%2!=0))
328 std::cout <<
"Blocked pyramid images must have even block sizes\n";
336 unsigned int rni = resc->ni(), rnj = resc->nj();
337 unsigned int np = resc->nplanes();
339 unsigned int dni = rni/2, dnj = rnj/2;
341 dni += rni%2; dnj += rnj%2;
344 fmt, brsc->size_block_i(),
345 brsc->size_block_j(),
A templated smart pointer class.
#define CONVERT_BLOCK_CASE(FORMAT, T)
Concrete view of image data of type T held in memory.
static vil_image_resource_sptr decimate(vil_image_resource_sptr const &resc, char const *filename, char const *format="tiff")
Utility for decimating a resource to create a new pyramid level.
void set_size(unsigned ni, unsigned nj) override
resize current planes to ni x nj.
void vil_convert_cast(const vil_image_view< inP > &src, vil_image_view< outP > &dest)
Cast one pixel type to another.
Some standard conversion functions.
vil_blocked_image_resource_sptr vil_new_blocked_image_resource(vil_stream *os, unsigned ni, unsigned nj, unsigned nplanes, vil_pixel_format format, unsigned size_block_i, unsigned size_block_j, char const *file_format)
Make a new blocked resource file.
read an image from a file
unsigned ni() const
Width.
~vil_pyramid_image_resource() override
unsigned nj() const
Height.
A blocked representation of the image_resource.
vil_blocked_image_resource_sptr blocked_image_resource(const vil_image_resource_sptr &ir)
cast to blocked resource if possible.
A blocked image facade for any image resource.
Representation of a pyramid resolution hierarchy.
A base class reference-counting view of some image data.
There is no class or function called vil_property.
vil_image_resource_sptr vil_load_image_resource(char const *filename, bool verbose=true)
Load an image resource object from a file.
static bool blocked_decimate(vil_blocked_image_resource_sptr const &brsc, vil_blocked_image_resource_sptr &dec_resc)
A utility function to decimate a resource using blocks.
bool get_property(char const *tag, void *property_value=nullptr) const override
Extra property information.
vil_pyramid_image_resource()
#define vil_property_pyramid
true if image resource is a pyramid image.