从Skimage高程图(2D numpy.ndarray)生成3D表面图

时间:2019-04-11 22:52:45

标签: python python-3.x numpy matplotlib scikit-image

the skimage Segmentation tutorial中,绘制了从sobel函数生成的高程图的3D表面图。

>>> from skimage.filters import sobel
>>> elevation_map = sobel(coins)

enter image description here

问题:elevation_map似乎是二维的numpy.ndarray。我们如何生成以此显示的3D地图?

1 个答案:

答案 0 :(得分:0)

这很可能是使用Paraview / VTK产生的;

尝试以下方法:

vec <- c(1, 3, 4, 5, 8, 9, 10, 54) #Input vector

countvalswithin <- vector() #Empty vector that will store counts of values within bounds

#For loop to cycle through values stored in input vector
for(i in 1:length(vec)){
  currval <- vec[i] #Take current value
  lbound <- (currval - 3) #Calculate lower bound w.r.t. this value
  ubound <- (currval + 3) #Calculate upper bound w.r.t. this value

  #Create vector containing all values from source vector except current value
  #This will be used for comparison against current value to find values within bounds.
  othervals <- subset(vec, vec != currval)

  currcount <- 1 #Set to 0 to exclude self; count(er) of values within bounds of current value

  #For loop to cycle through all other values (excluding current value) to find values within bounds of current value
  for(j in 1:length(othervals)){

    #If statement to evaluate whether compared value is within bounds of current value; if it is, counter updates by 1
    if(othervals[j] > lbound & othervals[j] <= ubound){
      currcount <- currcount + 1 
    }

  }

  countvalswithin[i] <- currcount #Append count for current value to a vector

}

df <- data.frame(vec, countvalswithin) #Input vector and respective counts as a dataframe

df

 #    vec countvalswithin
 #  1   1               3
 #  2   3               4
 #  3   4               3
 #  4   5               4
 #  5   8               3
 #  6   9               3
 #  7  10               3
 #  8  54               1

enter image description here