당신 수 LibTIFF 함께 할, 내가 아니라 나중에 기반으로 대답을 추가 할 수 있지만, 설치 및 사용의 용이성을 위해, 내가하는 C++ 헤더 전용 라이브러리 인 CImg
볼 것 귀하의 목적에 매우 강력하고 이상적입니다. 헤더 전용이므로 포함 (하나의 파일)하기가 쉽고 특별한 연결이나 건물이 필요하지 않습니다. 여기
는 RGB의 TIFF 수레 읽을 수있는 방법은 다음과 같습니다
그들은 평면으로 배열되어 있기 때문에 처음 세 개의 빨간 픽셀을 출력
#define cimg_display 0
#define cimg_use_tiff
#include "CImg.h"
#include <iostream>
using namespace cimg_library;
using namespace std;
int main(){
// Read in an image
CImg <float>img("image.tif");
// Get its width and height and tell user
int w=img.width();
int h=img.height();
cout << "Dimensions: " << w << "x" << h << endl;
// Get pointer to buffer/array of floats
float* buffer = img.data();
cout << buffer[0] << "," << buffer[1] << "," << buffer[2] << endl;
}
- 즉, 모든 적색 픽셀 첫째, 모든 녹색 픽셀 다음 모든 파란색 픽셀. 원하는 경우
g++-6 -std=c++11 read.cpp -I/usr/local/include -L/usr/local/lib -ltiff -o read
, 당신은 약간 다른 방식으로 같은 픽셀에 액세스 할 수 있습니다 : 함께
당신은 컴파일 할
#define cimg_display 0
#define cimg_use_tiff
#include "CImg.h"
#include <iostream>
using namespace cimg_library;
using namespace std;
int main(){
// Read in an image
CImg <float>img("image.tif");
// Get its width and height and tell user
int w=img.width();
int h=img.height();
cout << "Dimensions: " << w << "x" << h << endl;
// Dump the pixels
for(int y=0;y<h;y++)
for(int x=0;x<w;x++)
cout << x << "," << y << ": "
<< img(x,y,0,0) << "/"
<< img(x,y,0,1) << "/"
<< img(x,y,0,2) << endl;
}
샘플 출력
Dimensions: 512x256
0,0: 3.91318e-06/0.232721/128
1,0: 1.06577/0.342173/128
2,0: 2.3778/0.405881/128
3,0: 3.22933/0.137184/128
4,0: 4.26638/0.152943/128
5,0: 5.10948/0.00773837/128
6,0: 6.02352/0.058757/128
7,0: 7.33943/0.02835/128
8,0: 8.33965/0.478541/128
9,0: 9.46735/0.335981/128
10,0: 10.1918/0.340277/128
...
...
귀하의 정보를 위해 테스트 이미지 파일도 만들었습니다. 이 같은 CImg
와 함께 - 기본적으로 각 빨간색 픽셀은 x 좌표에 0.5보다 작은 작은 임의의 플롯을 더한 값으로 설정됩니다. 각 녹색 픽셀은 y 좌표에 0.5보다 작은 작은 무작위 부동 소수점을 더한 값으로 설정되고 각 파란색 픽셀은 중간 톤으로 설정됩니다.당신이 순수 libTIFF을 함께하고 싶어
#define cimg_display 0
#define cimg_use_tiff
#define cimg_use_png
#include "CImg.h"
#include <cstdlib>
using namespace cimg_library;
int main(){
const int w=512;
const int h=256;
const int channels=3;
float* buffer = new float[w*h*channels];
float* fp=buffer;
for(int y=0;y<h;y++){
for(int x=0;x<w;x++){
*fp++=x+float(rand())/(2.0*RAND_MAX); // red
}
}
for(int y=0;y<h;y++){
for(int x=0;x<w;x++){
*fp++=y+float(rand())/(2.0*RAND_MAX); // green
}
}
for(int y=0;y<h;y++){
for(int x=0;x<w;x++){
*fp++=128; // blue
}
}
CImg <float>img(buffer,w,h,1,channels);
img.save_tiff("result.tif");
}
내 대답 또는 다른 문제가 귀하의 문제를 정리 했습니까? 그렇다면 투표 수 옆의 빈 녹색 체크/체크 표시를 클릭하여 답변으로 수락하십시오. 그렇지 않은 경우, 나 또는 다른 누군가가 귀하를 더 멀리 도울 수 있도록 작동하지 않은 것을 말하십시오. 감사. http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235 –
'Dropbox '를 사용하여 TIFF에 대한 링크를 공유하거나 Microsoft의'OneDrive '또는 'Imgur' 또는 somesuch. –
뷰어에 관해서는 ImageMagick의 일부인'gimp','feh' 또는'display'를 시도 할 수 있습니다. –