X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 18 Mar 2003 07:43 PM by  anon
Writing to a specific line of a BIP or BIL file?
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
18 Mar 2003 07:43 PM
    Hi all: I was hoping someone might know, using an IDL and/or ENVI function, how do I write data to a specific LINE of a BIP or BIL file? Its easy to read it (envi_get_slice), but not easy to write that slice (how come no "envi_write_slice"?). The brute force is to load the entire image into memory, assign that specific line the new values, and then rewrite the entire image back to disk. This is EXTREMELY slow. Even using ENVI's spectral tiling routines (which at least minimize the memory used, and allow me to know what line I'm on), I still have to parse an entire BIP or BIL file and rewrite it, when all I want to do is write to a specific line and leave the rest of them as is. Anyone have any suggestions for how to do this? --j

    Deleted User



    New Member


    Posts:
    New Member


    --
    18 Mar 2003 07:43 PM
    One possible way is to use the IDL file I/O with the read/write offset. Once you determine where the exact data (i.e. skip past header information) begins, it is easy to compute the location/s of the exact line/s you want to replace. Of course you will need different location calculations depending on the data type Bip, bil or bsq. Hope this helps. Suresh

    Deleted User



    New Member


    Posts:
    New Member


    --
    18 Mar 2003 07:43 PM
    Hi Jonathan, ENVI won't do this for you. (I haven't checked 3.6, but previous versions won't.) My impression is that ENVI's I/O philosophy is always "process to a new file". But you can most probably do this with IDL code. It goes against the grain of letting ENVI handle your file I/O, but I think it's what you've got to do if you want to edit small bits of an image efficiently. The "flatter" your image the easier it'll be. (e.g., if the image on disk is pretty much exactly like how it ends up in memory then you're away.) I can't go into great detail because of all of the variables, but here's the general idea: 1] Get image info on the open image with ENVI_FILE_QUERY. (Full filename, Data type, file type, organisation, header bytes etc). You'd probably want to cop out if the image is in-memory, the organisation is 'bsq' or the image type isn't ENVI standard. 2] Close the image with ENVI_FILE_MNG. 3] Open the image file with IDL's OPENU,UUPD,FILENAME,/GET_LUN. 4] Navigate to the line that you want to zap with IDL's POINT_LUN. Basically just skip over the initial header (if any) and as many image lines as necessary. (POINT_LUN works with byte offsets. For huge images you can give it 64-bit offsets like 99999999999LL - on some platforms at least. One line's worth of BIL or BIP image is NS*NB*BPE, where BPE is bytes-per-element for the image's datatype and it's something you'll have to come up with yourself. It's pretty straightforward, though. e.g., 1 for byte, 2 for int, 4 for long and float, 8 for double...) 5] Declare an array for a line of image. For a BIP image it would be LINE=MAKE_ARRAY(NB,NS,type=DT) and for BIL it would be LINE=MAKE_ARRAY(NS,NB,type=DT). (DT is the datatype from ENVI_FILE_QUERY.) 6] Save the file pointer with POINT_LUN,-UUPD,PSAVE. (Note -UUPD not UUPD.) Or just save the offset that you used in 4]. 7] Read the line with READU,UUPD,LINE. 8] Do the necessary. 9] Restore the file pointer with POINT_LUN,UUPD,PSAVE. 10] Write the line with WRITEU,UUPD,LINE 11] Close the file with FREE_LUN,UUPD. 12] Re-open the file in ENVI with ENVI_OPEN_FILE,FILENAME. (FILENAME from ENVI_FILE_QUERY in 1].) If you do several lines it might be an idea to use IDL_FILEFLUSHUNIT(UUPD) after each write, but it's probably unnecessary. HTH Cheers Peter Mason
    You are not authorized to post a reply.