X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 29 May 2009 02:04 PM by  anon
re-applying masked areas
 8 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
29 May 2009 02:04 PM
    Hello, I am still a new user to ENVI and I am working on a supervised classification, using a hierarchical masking approach.  in other words, i have masked out easy to classify classes, then reclassified the remaining areas.  The problem I am encountering is that now that I have performed the classifications, I would like to "add back" the areas that were already masked out.  I understand I could do this through mosaic, by specifying background values that would allow the other image to show through.  Unfortunately, the class values of the first and second step classifications are the same (i.e. there is data value 1 and 2 in both steps) and when the mosaic is done, it assumes that these are the same class.  therefore i am hoping that there is either another way to add back in the masked classified area, or alternately a way to reclass a classified image (i.e. give class 1 and class 2 data values of 5 and 6 for example.) so that the mosaic process would have entirely distinct classes to work with. Thank you in advance for attending to this confusing request.  

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    03 Jun 2009 12:17 PM
    You can change the value of a class in ENVI using something like band math.  Basically you want to reassign a value to an existing class value.  One example might be: ((b1)*(b1 eq 1) *8 ) + (b1*(b1 ne 1)) Where the first part of the equation creates a mask of all the '1' values in my class image and sets the value of 1 to a value of 8.  Then it adds all the rest of the image classes back into this mask image.  The result of band math is always a standard single band image so if you want the class colors back, you will need to go into the header file and set the file type from ENVI Standard to ENVI Classification.

    Deleted User



    New Member


    Posts:
    New Member


    --
    12 Jun 2009 02:47 PM
    Thank you mminari, A further question: When I try to change the image back to a classification, it classes two data values within the same class.  For example, there will be pixels in class 2 with data values of 8 or 2.  It has somehow put two data values into the same class.  I must be doing something wrong? Possibly it has to do with the second part of the equation.  After ne, what value should go there?  The original value or always 1?  Thanks again, I can clarify if needed.

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    12 Jun 2009 03:00 PM
    Do you mean that the pixel values of 2 and 8 are both coming out as 'class 2' with the same color?  If you run statistics on the file after you do the band math, what is the data range?  This will probably give us a clue as to why 'Class 2' is encompassing both pixel values of 2 and 8. 

    Deleted User



    New Member


    Posts:
    New Member


    --
    15 Jun 2009 10:01 AM
    Yes, both values are in the same class.  In the statistics the data range is correct, in other words, the values of each class are separate (values 2 and 8 for example) and are given those values.  Interestingly, the class number that both values are being put into is not the same value as either value.  In other words, values of 14 and 24 are both being classified as class 6.  It seems to me there is something going wrong when I change the file from a regular single band file to an ENVI Classification file.  Thanks again for your troubleshooting help.

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    15 Jun 2009 10:47 AM
    I need some details about the statistics of the file and how many classes you are defining in the ENVI header.

    Deleted User



    New Member


    Posts:
    New Member


    --
    15 Jun 2009 12:29 PM
    I will do my best to give complete info, starting from the beginning: I am trying to mosaic two files together in a way so that one class of one file is replaced by the numerous classes of the other file.  The first file (image1) is a classification file that divides the image into three classes and a background/masked out class.  The second file (image2)  is also a classification file that was created by classifying to more detail one of the classes in image1.  This was done by creating a mask file with image1, applying it to the original data, and performing a supervised classification.  This generated  4 classes, plus of course the background/masked areas.  The basic statistics for these files are the following: Image1: (ENVI Classification file, byte order host (intel), data type byte, interleave BSQ) Band 1: min 0, max 3, mean .6546, stddev .8980 Histogram Band 1: DN 0, Npts 8231941; DN 1, 4740897; DN 2, 640429; DN 3, 1219678   Image2: (ENVI Classification file, byte order host (intel), data type byte, interleave BSQ) Band 1: min 0, max 4, mean 0.689, stdev 1.143 Histogram Band 1: DN 0, Npts 10092048; DN1, Npts 1188063; DN 2, Npts 2334481; DN 3, Npts 509549; DN 4, Npts 708804. (note that in image2, DN values 1,2,3,4 added together equal DN 1 from image 1; this is the class in image1 that was further classified in image2).   Because image1 and image 2 had overlapping data values that i did not want to be in the same classes, i reclassed image1, using mminari's instructions for bandmath.  This generated Image3: Image3: (ENVI Standard, Byte order Host (intel), Data type integer, interleave BSQ) Histogram, Band1: DN 0, Npts 12972838; DN 14, Npts 640429; DN 24, 1219678; (note: DN 1-13 and DN 15-23 are all 0)   I then took Image3 and changed its format to an ENVI classification file in the header file with 3 classes.  I chose colors for a background class, class#1 and class#2.  However, when I then open this image, both values 14 and 24 are classed in class#2 and given that color and there is no apparent class#1.  I will call this Image3b Image 3b: (ENVI Classification, Byte Order Host (intel), Data type Integer, Interleave BSQ.) Histogram: Band1, DN 0, Npts 12972838; DN 14, Npts 640429; DN 24, Npts 1219678.  Again DN 1-13 and DN 15-23 are all 0.  Side note: I tried to change the data type to byte format and it produced a very strange image, so i left it as integer.    I continued to the mosaic stage, by mosaicing the Image3b (ENVI Classification) with Image2.  This produced an ENVI classification image with everything correct, except that the same problem that was present in Image3b perpetuated, in that values 14 and 24 were both lumped into the same class.  I hadn't expected the mosaic to solve the problem, so this did not come as a surprise.    I hope this is the information that is helpful for solving this.  If not, please specify what else is needed.  thank you once again

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    17 Jun 2009 02:57 PM
    Ok, this is a bit more complicated but I understand more of what you have.  It sounds like: - image 1 is classified into 3 classes (+ unclassified) - image 2 is a mask of a single class from image 1, reclassified into 4 classes; so for my example I masked the original image with class 2 in image 1, then reclassified it so I have the area of class 2 from image 1 divided into 4 classes ranging from 1-4. Yes? - So, I have a total of 6 unique classes I want to combine - 2 classes from image 1 (classes 1 and 3) and 4 classes from image 2 (that is the same area as class 2 in image 1). To make this combining easier, I wrote the band math function below. What it does is find all class 1 and 3 pixels in image 1 and reassigns them a value of 5 and 6.  Then it is combined with the classes and class areas from image 2.  The resulting image contains values 1-6 (+ unclassified) of the appropriate classified areas.  You will still need to change the file type to ENVI Classification and specify 7 total classes, then adjust the colors, but the class values should be correct.  I assume you have access to IDL to compile this.   After it is compiled, call it from band math as: reclass_combine(b1,b2). ==================== function reclass_combine, b1, b2 ; find which pixels in b1 /b2 fall into each class class5 = WHERE(b1 eq 1, count1) class6 = WHERE(b1 eq 3, count2) class1 = WHERE(b2 eq 1, count3) class2 = WHERE(b2 eq 2, count4) class3 = WHERE(b2 eq 3, count5) class4 = WHERE(b2 eq 4, count6) unclassed = where(b1 eq 0, count 7) ; make the classified image ; in this example, we are setting all b1 pixel values of '1' to a new value of '5'and of '2' to a value of '6' ; then use the classes from b2 as 1, 2, 3, 4 classified = BYTE(b1) IF count1 NE 0 THEN classified(class5) = 5B IF count2 NE 0 THEN classified(class6) = 6B IF count3 NE 0 THEN classified(class1) = 1B IF count4 NE 0 THEN classified(class2) = 2B IF count5 NE 0 THEN classified(class3) = 3B IF count6 NE 0 THEN classified(class4) = 4B IF count7 NE 0 THEN classified(unclassed) = 0B ; return the classified image RETURN, classified end

    Deleted User



    New Member


    Posts:
    New Member


    --
    19 Jun 2009 06:00 PM
    Thank you very much mminari!
    You are not authorized to post a reply.