[gdal-dev] Re: TIFF write and comparison
Akhil Jaggarwal
axj4159 at cs.rit.edu
Tue Sep 14 23:07:14 EDT 2010
Hi,
Any comments/suggestions on this issue would be immensely helpful!
I'm storing the pixel values in a buffer like this:
pafScanline = (short int*)CPLMalloc(sizeof(short int)*nxSize*nySize);
I can read the data alright. The call to GDALRasterIO is being made
correctly, which I do with:
GDALRasterIO(hBand, GF_Read, 0, 0, nxSize, nySize,
pafScanline,
nxSize,nySize,
GDT_Int16,
0, 0);
However, when it comes to the part of writing a pixel data to an
output file, the call to GDALRasterIO fails:
for(i = 0; i < nySize; i++) {
for(j = 0; j < nxSize; j++) {
if( CE_Failure == GDALRasterIO( hDestDS,
GF_Write, 0, 0, j, i,
change1, j, i , GDT_Int16, 0,0) ) {
printf("Write Error!");
return 1;
}
}
}
Where change1 is a variable to hold pixel data that I want to change.
It's declared in the following manner:
short int*change1;
change1 = malloc(sizeof(short int));
*change1 = 1;
I can't get what exactly am I missing. The file i'm using is a tiled,
16 bit signed TIFF.
How do I change the value at a pixel location?
Thanks!
On Mon, Sep 13, 2010 at 11:54 PM, Akhil Jaggarwal <axj4159 at cs.rit.edu> wrote:
> Hi,
>
> Thank you for the reply.
>
> Calls to GDALRasterIO() are OK. Which I assume in a line interleaved
> format look like this:
>
> GDALRasterIO(hBand, GF_Read, 0,0, i, j, pafScanline,
> nBlockXSize, nBlockYSize,
> GDT_Int16,
> 0, 0);
>
> Is that correct?
>
> Also, the statement: if(pafScanline[j] == pixel_value), is that a
> correct way to check if a pixel value at the jth col is equal to some
> constant?
>
> pafScanline is declared as follows: short int * pafScanline. In the
> API, pdata is a void *.
>
> Is this way to substitute the value of a pixel (of short int type)
> according to a rule, and then writing the pixel back to the TIFF a
> correct way? -
>
> short int rule1 = 1;
> void *change = malloc(sizeof(short int));
> change1 = &rule1;
> ...
> ...
> ...
> GDALRasterIO( hDestDS, GF_Write, 0,0, i,j, change1,
> nBlockXSize,nBlockYSize , GDT_Int16, 0,0);
>
> Thanks.
>
> On Mon, Sep 13, 2010 at 4:40 PM, Chaitanya kumar CH
> <chaitanya.ch at gmail.com> wrote:
>> Akhil,
>>
>> Check which of the GDALRasterIO() calls are made.
>>
>> Also, I noticed that you are calling GDALRasterIO() to read the data pixel
>> by pixel. Line by line will be faster, especially if the data is line
>> interleaved.
>>
>> On Mon, Sep 13, 2010 at 8:30 PM, Akhil Jaggarwal <axj4159 at cs.rit.edu> wrote:
>>>
>>> Hi,
>>>
>>> I've shortened my questions to exactly this part of the code:
>>>
>>> // read datasets, compare data and write
>>> if ( (pafScanline2[j] > 6 || pafScanline3[j] > 950)
>>> &&
>>> pafScanline[j] == 2) {
>>> GDALRasterIO( hDestDS, GF_Write, 0,0, i,j,
>>> change1, i, j, GDT_Byte,
>>> 0,0);
>>> }
>>> else if( (pafScanline4[j] < -700) &&
>>> pafScanline[j] == 6 ) {
>>> GDALRasterIO( hDestDS, GF_Write, 0,0, i,j,
>>> change2, i, j, GDT_Byte,
>>> 0,0);
>>> }
>>> else if( (pafScanline2[j] > 6) && pafScanline[j] ==
>>> 3 ) {
>>> GDALRasterIO( hDestDS, GF_Write, 0,0, i,j,
>>> change2, i, j, GDT_Byte,
>>> 0,0);
>>> }
>>> else if((pafScanline3[j]>1500) && pafScanline[j] ==
>>> 6) {
>>> GDALRasterIO( hDestDS, GF_Write, 0,0, i,j,
>>> change1, i, j, GDT_Byte,
>>> 0,0);
>>> }
>>> else
>>> GDALRasterIO( hDestDS, GF_Write, 0,0, i,j,
>>> &pafScanline[j], i, j,
>>> GDT_Byte, 0,0);
>>> // printf("%u\n", pafScanline[j]);
>>>
>>>
>>> 1) Am I writing pixels the correct way?
>>>
>>> As of now I am getting just the exact copy of the input TIFF without
>>> any pixel modifications. Where step am I doing wrong.
>>>
>>> Any help would be great!
>>>
>>> Thanks.
>>> _______________________________________________
>>> gdal-dev mailing list
>>> gdal-dev at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>>
>>
>> --
>> Best regards,
>> Chaitanya kumar CH.
>> /tʃaɪθənjə/ /kʊmɑr/
>> +91-9494447584
>> 17.2416N 80.1426E
>>
>
More information about the gdal-dev
mailing list