IMAlign: remove n layers of the outside of your scans

Started by PW User, January 19, 2009, 04:58:28 AM

Previous topic - Next topic

PW User

Hello,

Ever noticed that the outside (edges) of your scans tend to lift up and be noisy?

This macro will remove "n" layers (the user decides and inputs how many) at the edge of all scans in IMAlign. Careful to run it only once, there is no check if it has already run...

It's always safe to keep the "raw" scans in a seperate project to be able to go back to easily.

I'll post separately a little "howto" on how to put a macro into a button...

Bernard
Polyworks Application Specialist


--------------------------- copy from the line below ---------------

version "4.0"

# Macro to remove n layers of the outside of scans

DECLARE nb_layers 1
DECLARE nb_images 0
DECLARE i 1

TREEVIEW IMAGE GET_NB(nb_images)

INPUT DOUBLE(nb_layers,"Please input the number of layers to remove",\
    "Please input the number of layers to remove",\
    $nb_layers)
SELECT NONE
while $i <=$nb_images
    TREEVIEW SELECT NONE
    TREEVIEW IMAGE SELECT ( $i, "On" )
    EDIT OBJECT USE ()
    SELECT OBJECT INVERT
    EDIT OBJECT IGNORE ( )
    TREEVIEW SELECT NONE
    TREEVIEW IMAGE SELECT ( $i, "On" )
    SELECT ALL
    CONFIG MODIFY NB_LAYERS ( $nb_layers )
    SELECT SHRINK_ALL
    SELECT INVERT
    EDIT DELETE
    ++ i
endwhile


DataBill

Thank you for the macro. This is cool. One problem I seem to have is if I click on the macro and then decide I don't want to go through with it, it does go through using the default of 1.00. I spoke with someone here who know programming and he seems to have fixed my problem. Here is the update:

version "4.0"
# Macro to remove n layers of the outside of scans

DECLARE nb_layers 1
DECLARE nb_images 0
DECLARE i 1
DECLARE ans 1


TREEVIEW IMAGE GET_NB(nb_images)

INPUT DOUBLE(nb_layers,"Please input the number of layers to remove",\
    "Please input the number of layers to remove",\
    $nb_layers)

INPUT QUESTION(ans, "Do you want to continue?")
SELECT NONE 
while $i <=$nb_images
    if $ans == 0
        break
    endif
    TREEVIEW SELECT NONE
    TREEVIEW IMAGE SELECT ( $i, "On" )
    EDIT OBJECT USE ()
    SELECT OBJECT INVERT
    EDIT OBJECT IGNORE ( )
    TREEVIEW SELECT NONE
    TREEVIEW IMAGE SELECT ( $i, "On" )
    SELECT ALL
    CONFIG MODIFY NB_LAYERS ( $nb_layers )
    SELECT SHRINK_ALL
    SELECT INVERT
    EDIT DELETE
    ++ i
endwhile


You now click "OK", then it will ask if you want to continue, if you don't want to go through with the macro you just hit no.

DataBill

We've made more changes. This will un-ignore and un-select the images in the tree view.

version "4.0"
# Macro to remove n layers of the outside of scans

DECLARE nb_layers 1
DECLARE nb_images 0
DECLARE i 1
DECLARE ans 1


TREEVIEW IMAGE GET_NB(nb_images)

INPUT DOUBLE(nb_layers,"Please input the number of layers to remove",\
    "Please input the number of layers to remove",\
    $nb_layers)

INPUT QUESTION(ans, "Do you want to continue?")
SELECT NONE 
while $i <=$nb_images
    if $ans == 0
        break
    endif
    TREEVIEW SELECT NONE
    TREEVIEW IMAGE SELECT ( $i, "On" )
    EDIT OBJECT USE ()
    SELECT OBJECT INVERT
    EDIT OBJECT IGNORE ( )
    TREEVIEW SELECT NONE
    TREEVIEW IMAGE SELECT ( $i, "On" )
    SELECT ALL
    CONFIG MODIFY NB_LAYERS ( $nb_layers )
    SELECT SHRINK_ALL
    SELECT INVERT
    EDIT DELETE
    ++ i
endwhile

TREEVIEW SELECT IGNORED
EDIT OBJECT USE ()
TREEVIEW SELECT NONE

EFV

Hmm.  Well, the results provided by this macro could be reproduced in significantly fewer lines.

Here:


version "4.0"
# Macro to remove n layers of the outside of scans

DECLARE nb_layers 1
DECLARE nb_images 0
DECLARE i 1
DECLARE ans 1


TREEVIEW IMAGE GET_NB(nb_images)

INPUT DOUBLE(nb_layers,"Please input the number of layers to remove",\
    "Please input the number of layers to remove",\
    $nb_layers)

INPUT QUESTION(ans, "Do you want to continue?")
SELECT NONE

if $ans == 1
    select all
    config modify NB_LAYERS($nb_layers)
    select shrink_all
    select invert
    edit delete
endif

#what follows is obsolete code


#while $i <=$nb_images
#    window refresh("Off")
#    if $ans == 0
#        break
#    endif
#    TREEVIEW SELECT NONE
#    TREEVIEW IMAGE SELECT ( $i, "On" )
#    EDIT OBJECT USE ()
#    SELECT OBJECT INVERT
#    EDIT OBJECT IGNORE ( )
#    TREEVIEW SELECT NONE
#    TREEVIEW IMAGE SELECT ( $i, "On" )
#    SELECT ALL
#    CONFIG MODIFY NB_LAYERS ( $nb_layers )
#    SELECT SHRINK_ALL
#    SELECT INVERT
#    EDIT DELETE
#    ++ i
#    Window refresh("On")
#endwhile
#
#TREEVIEW SELECT IGNORED
#EDIT OBJECT USE ()
#TREEVIEW SELECT NONE


If you want to expand the macro, you could ignore the images that weren't selected when the macro was pressed and only "shrink" those that were selected - SELECT OBJECT INVERT, EDIT OBJECT IGNORE.  You could, of course, force all selected images into the shrink by adding EDIT OBJECT USE and VIEW VISIBILITY RESTORE to the top, assuming the user wanted to shrink all selected images.

I took my version a few steps further, to the point of being cumbersome, but I find it useful.  The code is fairly old, so it might have a few extra steps in it.  Anyway, here it is:

version "4.0"
declare eSelected 0
declare eIndex 1
declare eI 1
declare eFillList
declare eListSize 1
declare eLayers 0
declare eStatus
declare eTemp 0
declare eName
declare eTotal
declare eGetContinue
declare eGetList
MACRO SHARED_VARIABLE create("eSharedContinue", 0)
MACRO SHARED_VARIABLE create("eSharedList", {0})
MACRO SHARED_VARIABLE GET_VALUE("eSharedContinue", eGetContinue)

if $eGetContinue == 0
    TREEVIEW IMAGE GET_NB(eTotal)
    while $eIndex <= $eTotal
        TREEVIEW IMAGE GET_SELECTION_STATUS($eIndex, eStatus)
        if $eStatus == "On"
            set eFillList[$eListSize] $eIndex
            ++ eListSize
        endif
        ++ eIndex
    ENDWHILE
    MACRO SHARED_VARIABLE SET_VALUE("eSharedList", $eFillList)
    while $eI <= $eTotal
        if $eI == $eFillList[1]
            TREEVIEW IMAGE GET_NAME($eI, eName)
            VIEW VISIBILITY OBJECTS KEEP($eName)
            ##########
            while $eTemp == 0
                INPUT INTEGER(eLayers,"Layer size.", "How many layers to shrink?", 0)
                if $eLayers > 10
                    set eLayers 10
                else
                    if $eLayers < 0
                        set eLayers 0
                    endif
                endif
                if $eLayers > 0
                    SELECT ALL
                    CONFIG MODIFY NB_LAYERS ( $eLayers )
                    SELECT SHRINK_ALL
                    SELECT INVERT
                endif
                #Macro pause ("Pause", "Examine the selected elements.")
                INPUT QUESTION(eTemp, "Keep this shrink?")
               
               
            endwhile
            ########
            ++ eI
            MACRO SHARED_VARIABLE SET_VALUE("eSharedContinue", 2)
            Macro end
        endif
        ++ eI
    endwhile
else
#    edit delete
    EDIT IGNORE_FOR_MERGING
    MACRO SHARED_VARIABLE GET_VALUE("eSharedList", eGetList)
    TREEVIEW IMAGE GET_NB(eTotal)
    while $eI <= $eTotal
        if $eI == $eGetList[$eGetContinue]
            TREEVIEW IMAGE GET_NAME($eI, eName)
            VIEW VISIBILITY OBJECTS KEEP($eName)
            #######
            while $eTemp == 0
            INPUT INTEGER(eLayers,"Layer size.", "How many layers to shrink?", 0)
            if $eLayers > 10
                set eLayers 10
            else
                if $eLayers < 0
                    set eLayers 0
                endif
            endif
           
            if $eLayers > 0
                SELECT ALL
                CONFIG MODIFY NB_LAYERS ( $eLayers )
                SELECT SHRINK_ALL
                SELECT INVERT
            endif
            #Macro Pause("Pause", "Examine the selected elements.")
            INPUT QUESTION(eTemp, "Keep this shrink?")
           
            endwhile
            ########
            ++ eGetContinue
            MACRO SHARED_VARIABLE SET_VALUE("eSharedContinue", $eGetContinue)
            if $eGetContinue > size(eGetList)
                macro pause("WARNING", "Hopefully this is a warning for the second to last time this macro runs.")
            endif
            Macro end
           
           
        endif
        ++ eI
    endwhile
   
    macro SHARED_VARIABLE DELETE("eSharedContinue")
    macro SHARED_VARIABLE DELETE("eSharedList")

    TREEVIEW SELECT NONE
    TREEVIEW select ALL
    VIEW VISIBILITY OBJECTS KEEP
    TREEVIEW SELECT NONE

    SELECT IMAGE_POINTS IGNORED_FOR_MERGING
    EDIT DELETE


    macro pause("SUCCESS", "Muliple image shrink process finished successfully.")
   
endif   


In order for this macro to work, you must have at least 1 scan selected, and must run the macro once for each scan you had selected when you first ran it.  See?  Cumbersome.

Basically, the macro builds a list of any scans you had selected when you ran it.  It then isolates the first scan and asks for a number of layers to shrink that scan.  The user can confirm or deny the number he entered (denial just asks for a new # of layers).  Then the macro ends.

Now the user can select any additional areas of the image or deselect any edges that he might not have wanted reduced.  This step, for me, make the macro most useful, as I can use it cot only to shrink images, but to remove targets and noise.  It is important to remember NOT to delete the selected areas during this step.

The next time you hit the macro button, any selected elements are flagged as "ignored for merging."  This saves time, as deleting the elements outright is somewhat slow.  It then isolates the next scan in the list for you, and the process continues.

There are two progress checks implemented - a second to last run warning, and a final run success message.  The second to last message is on line 95 and may as well be commented out.

This extra macro serves specifically to reset the first:

version "4.0"
MACRO SHARED_VARIABLE DELETE("eSharedContinue")
MACRO SHARED_VARIABLE DELETE("eSharedList")


There are better ways to do the things I did with this macro, I know.  I'm just posting it because it's the kind of extreme that you can take a layer reduction macro.

*EDIT* for forgetting part of the description of my own macro.