Skip to content

Commit 6a3ea22

Browse files
author
Erika
committed
modified saveTiff function with issues
1 parent d56ee39 commit 6a3ea22

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

depthmap/depthmap.cpp

+24-18
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ bool Depthmap::loadTiff(const char *tiff, vector<float> &values, uint32_t &w, ui
223223

224224
uint16_t samplesPerPixel = 1;
225225
TIFFGetField(inTiff, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel);
226-
if(samplesPerPixel != 1) {
226+
if(samplesPerPixel !=
227+
1) {
227228
cerr << "Not a depthmap, expecting just 1 channel" << endl;
228229
TIFFClose(inTiff);
229230
return false;
@@ -245,6 +246,7 @@ bool Depthmap::loadTiff(const char *tiff, vector<float> &values, uint32_t &w, ui
245246
return false;
246247
}
247248

249+
248250
values.resize(w * h);
249251

250252
// Check if the TIFF is tiled
@@ -427,11 +429,11 @@ bool Depthmap::loadMask(const char *tifPath){
427429
return true;
428430

429431
}
432+
430433
//1. scrivere la depth map e la masq fai tif .save con i nomi.
431434
//2. prendi la superficie dell rti e trovi la media delle due superfici della depth e della rti. sottraiamo la media del rti per vedere se hanno la stessa media.
432435
//void Depthmap::
433436

434-
435437
bool Depthmap::loadNormals(const char *normals_path){
436438

437439
QImage normalmap(normals_path);
@@ -469,13 +471,25 @@ void Depthmap::saveTiff(const char *mask_path, vector<float> &values, uint32_t &
469471
return;
470472
}
471473

472-
TIFFSetField(maskTiff, TIFFTAG_IMAGEWIDTH, w);
473-
TIFFSetField(maskTiff, TIFFTAG_IMAGELENGTH, h);
474-
//TIFFSetField(maskTiff, TIFFTAG_SAMPLESPERPIXEL, 1);
474+
TIFFSetField(maskTiff, TIFFTAG_IMAGEWIDTH, &w);
475+
TIFFSetField(maskTiff, TIFFTAG_IMAGELENGTH, &h);
476+
TIFFSetField(maskTiff, TIFFTAG_SAMPLESPERPIXEL, 1);
477+
478+
if (bitsPerSample == 32) {
479+
TIFFSetField(maskTiff, TIFFTAG_BITSPERSAMPLE, bitsPerSample);
480+
TIFFSetField(maskTiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
481+
TIFFSetField(maskTiff, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
482+
} else if (bitsPerSample == 1) {
483+
TIFFSetField(maskTiff, TIFFTAG_BITSPERSAMPLE, 1);
484+
TIFFSetField(maskTiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
485+
TIFFSetField(maskTiff, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
486+
}
487+
488+
475489

476490
tsize_t scanLineSize = TIFFScanlineSize(maskTiff);
477491
if (scanLineSize == 0) {
478-
cerr << "Error computing scanline size for 1-bit TIFF." << endl;
492+
cerr << "Error computing scanline size." << endl;
479493
TIFFClose(maskTiff);
480494
return;
481495
}
@@ -484,10 +498,6 @@ void Depthmap::saveTiff(const char *mask_path, vector<float> &values, uint32_t &
484498
for (uint32_t y = 0; y < h; ++y) {
485499
if (bitsPerSample == 32) {
486500

487-
TIFFSetField(maskTiff, TIFFTAG_BITSPERSAMPLE, 32);
488-
TIFFSetField(maskTiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
489-
TIFFSetField(maskTiff, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
490-
491501
std::vector<float> stripData(scanLineSize / sizeof(float));
492502
for (uint32_t x = 0; x < w; ++x) {
493503
uint32_t index = y * w + x;
@@ -502,10 +512,6 @@ void Depthmap::saveTiff(const char *mask_path, vector<float> &values, uint32_t &
502512
}
503513
if (bitsPerSample == 1) {
504514

505-
TIFFSetField(maskTiff, TIFFTAG_BITSPERSAMPLE, 1);
506-
TIFFSetField(maskTiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
507-
TIFFSetField(maskTiff, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
508-
509515
unsigned char * scanline= new unsigned char [scanLineSize];
510516
memset(scanline, 0, scanLineSize);
511517

@@ -529,12 +535,12 @@ void Depthmap::saveTiff(const char *mask_path, vector<float> &values, uint32_t &
529535
}
530536
delete[] scanline;
531537
}
538+
TIFFClose(maskTiff);
532539

533540
}
534-
TIFFClose(maskTiff);
535-
536541
}
537542

543+
538544
void Depthmap::saveDepth(const char *depth_path){
539545
saveTiff(depth_path, elevation, width, height, 32);
540546
}
@@ -693,7 +699,7 @@ void Depthmap::resizeNormals (int factorPowerOfTwo, int step) {
693699
//depthIntegrateNormals();
694700

695701
}
696-
/*void Depthmap::sampleDepth() {
702+
void Depthmap::sampleDepth() {
697703
std::vector<float> sampledDepths;
698704
float sum = 0.0f;
699705

@@ -714,7 +720,7 @@ void Depthmap::resizeNormals (int factorPowerOfTwo, int step) {
714720
for (int i = 0; i < sampledDepths.size(); i++) {
715721
cout << "Sampled Depth[" << i << "]: " << sampledDepths[i] << endl;
716722
}
717-
}*/
723+
}
718724

719725
//take the x=160,14 e y=140
720726
//the coordinates of the pixel step 0.016 are in the depth map xml Z_num etc.

depthmap/main.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ int main(int argc, char *argv[]) {
2828

2929
//output
3030
QString outputPath = base + "testcenterRel_copia/photogrammetry/depthmap_projectL05C13.png";
31-
QString output_mask = base + "testcenterRel_copia/photogrammetry/mask_test.png";
32-
QString output_depth = base + "testcenterRel_copia/photogrammetry/depth_test.png";
31+
QString output_mask = base + "testcenterRel_copia/photogrammetry/mask_test.tif";
32+
QString output_depth = base + "testcenterRel_copia/photogrammetry/depth_test.tif";
3333

3434
OrthoDepthmap ortho;
3535

@@ -40,6 +40,7 @@ int main(int argc, char *argv[]) {
4040
//ortho.computeNormals();
4141
//ortho.saveNormals(qPrintable(base + "testcenterRel_copia/photogrammetry/original.png"));
4242
//ortho.saveObj(qPrintable(base + "testcenterRel_copia/photogrammetry/original.obj"));
43+
4344
ortho.saveDepth(qPrintable(output_depth));
4445
ortho.saveMask(qPrintable(output_mask));
4546

0 commit comments

Comments
 (0)