ArcGIS_MShift pythonPath and memory 128 MG in OTB

48 views
Skip to first unread message

Juan Guerra Hernandez

unread,
Jan 30, 2019, 6:11:19 AM1/30/19
to SegOptim user group
Dear Gruop

I,am trying to perform segmentation_ArcGIS_MShift but I can not find the python scripts used to perform image segmentation in ArcGIS 

I have the last version of Arcgis 10.6. but I don´t know the pyScriptName and the path to use in the function 

Could someone help me to find pythonPath in order to run the function?

On the other hand, I have a problem of memory when I am running Segmentation_OTB_LMS becouse the limit is 128 MG. Is it possible to change this parameter in the function?. My RGB image from segmentation in not a large image only have 52 MG 

Thank in advance


João Gonçalves

unread,
Jan 30, 2019, 11:00:15 AM1/30/19
to SegOptim user group
Hi Juan,

Thanks for your message. For running ArcGIS segmentation you will need to define the folder that contains the Python distribution that is installed together with ArcGIS (usually in "C:/Python27/ArcGIS10.x" or similar). No need to define the pyScriptName.

Then you can use the following code to run the segmentation (modify it to your system):


# Folder containing the python.exe file used by ArcGIS 10.x
# Replace this with your own folder
arcgisPython
<- "C:/Python27/ArcGIS10.x"

# A multiband raster with features used for segmentation
inputSegmFeat
<- "C:/Users/MyUserName/MyFiles/myRaster.tif"

segmentation_ArcGIS_MShift
(inputSegmFeat,
                           outputSegmRst
= "C:/Users/MyUserName/MyFiles/outSegm.tif", # Output segmented raster - change this
                           
SpectralDetail = 12.3, # Change this
                           
SpatialDetail = 15,    # Change this
                           
MinSegmentSize = 25,   # Change this
                           pythonPath
= arcgisPython,
                           verbose
= TRUE)



Regarding the OTB segmentation function, for now the package uses the default RAM value (which is not a very good option in cases where images are large...). We will address this issue in a new version of SegOptim that will be released very soon. We will contact you directly once released.

Cheers,
João
- - -

João Gonçalves

unread,
Jan 30, 2019, 1:09:07 PM1/30/19
to SegOptim user group
Hi again,

Regarding the OTB option to change the amount of usable RAM memory, this is now available in SegOptim version 0.2.2. Tests using OTB 5.10 and 6.6 were both successful and do override the default 128Mb value.

Please re-install the package using the following line of code:
devtools::install_bitbucket("joao_goncalves/segoptim")

After installation, reload the package and now you can define the available memory with the "RAM" parameter. You can also modify the "tilesizex" and "tilesizey" parameters to adjust to your machine memory restrictions.
Here's an example:
library(SegOptim)

# See the help page for the function

?segmentation_OTB_LSMS

# Run OTB segmentation
outSegmRst <- segmentation_OTB_LSMS(
                      inputRstPath = "C:/Users/User/MyFiles/inputSegFeat.tif"
                     
SpectralRange = 3.1,
                     SpatialRange = 4.5,
                     
MinSize = 20,
                     
outputSegmRst =
"C:/Users/User/MyFiles/segmentedRaster.tif",
                     
verbose = TRUE,
                     
otbBinPath = "C:/OTB/bin",
                     
lsms_maxiter = 20,
                      tilesizex
= 3500,
                      tilesizey
= 3500,
                      RAM = 4096) # <- The available memory option here


Let us know if this works for you.

Juan Guerra Hernandez

unread,
Jan 31, 2019, 11:22:17 AM1/31/19
to SegOptim user group
Hi Joao

I re-install the package . I am working with the new version of SegOptim version 0.2.2 but the argument RAM give me a bug with OTB

## Run the segmentation OTB
outSegmRst <- segmentation_OTB_LSMS(
  # Input raster with features/bands to segment
  inputRstPath = inputSegFeat.path,
  # Algorithm params
  SpectralRange = 3.1,
  SpatialRange = 4.5,
  MinSize = 20,
  # Output
  tilesizex = 500,
  tilesizey = 500,
  RAM = 4096,
  outputSegmRst = outSegmRst.path,
  verbose = TRUE,
  otbBinPath = otbPath,
  lsms_maxiter = 50)

Error in segmentation_OTB_LSMS(inputRstPath = inputSegFeat.path, SpectralRange = 3.1,  : 
  unused argument (RAM = 4096)

I did download with devtools::install_bitbucket("joao_goncalves/segoptim") and then I used the library( SegOptim)

Thank 

Best regards

Juan





João Gonçalves

unread,
Jan 31, 2019, 7:11:16 PM1/31/19
to SegOptim user group
Hi Juan,

Seems that the package was not successfully (re-)instaled. Try first to remove the previous version and then do the install:
remove.packages("SegOptim")

devtools
::install_bitbucket("joao_goncalves/segoptim")

If successful you should be able to see the following messages at the end:

(...)
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* DONE (SegOptim)
In R CMD INSTALL

To check if the OTB segmentation function is updated go the help pages and you should be able to see the "RAM" option description:
library(SegOptim)

?segmentation_OTB_LSMS

# Arguments
# (...)
#RAM Available memory for processing the image data (in MB).

Let me know if this is working.
Reply all
Reply to author
Forward
0 new messages