Adding a Color Scale to the Procrustes Distances


To visualize the Procrustes distances you will need the R library plotrix so you can use the function color.scale(). Within RStudio you can install this by going to Tools -> install packages -> install from: Repository (CRAN) and type plotrix in the packages box.


Files you will need:
ProcDistLandmarks_all_mean - the average Procrustes distance for each landmark, fixed and sliding

ProcDistLandmarks_surfaceall_mean - the average Procrustes distance for just the surface landmarks.
     This file is created by selecting only the values that correspond to semi-landmarks:
          ProcDistLandmarks_surfaceall_mean <- ProcDistLandmarks_all_mean[110:969]

The fixed landmarks had much larger Procrustes distances than the sliding semi-landmarks, so it was useful to also visualize just the sliding semi-landmarks without the fixed.


To create a color scale for the Procrustes distances:

- First scale the distances to a 0 to 1 range:

library(plotrix)
maxmeandist <- max(ProcDistLandmarks_all_mean)
minmeandist <- min(ProcDistLandmarks_all_mean)
scaledmeandist <- (ProcDistLandmarks_all_mean-minmeandist)/(maxmeandist-minmeandist)

you can plot the scaled values just to see how it looks:
plot(scaledmeandist)

- Then add color to each Proc. distance based on its scaled value and plot to check the color:

white to black:
meanprocdistcolorscale <- color.scale(scaledmeandist)
plot(scaledmeandist, col = meanprocdistcolorscale)

Red to green:
meanprocdistcolorscale <- color.scale(scaledmeandist, c(0,1,1),c(1,1,0),0)
plot(scaledmeandist, col = meanprocdistcolorscale)

Green to blue:
meanprocdistcolorscale <- color.scale(scaledmeandist, 0,c(0,1,1),c(1,1,0))
plot(scaledmeandist, col = meanprocdistcolorscale)

- and more info on the package plotrix here: https://cran.r-project.org/web/packages/plotrix/plotrix.pdf
-you can change the colors by changing the values after scaledmeandist, I don't quite understand what numbers correspond to what colors, but if you mess around with them you can figure out colors that work for you:
     c(0,1,1),c(1,1,0),0 = red, yellow, green
     0,c(0,1,1),c(1,1,0) = green to blue
     0,c(1,0),c(1,1)       = dark blue to light blue
    c(0,1,0),c(0,0,1),c(0,1,0)  = green, purple, black

You can repeat the method with just the surface semi-landmarks, and with the male and female averages:

ProcDistLandmarks_surfaceall_mean <- ProcDistLandmarks_all_mean[110:969]

scaledmean_surfdist <- (ProcDistLandmarks_surfaceall_mean-min(ProcDistLandmarks_surfaceall_mean))/(max(ProcDistLandmarks_surfaceall_mean)-min(ProcDistLandmarks_surfaceall_mean))

plot(scaledmean_surfdist)

mean_surfdist_colorscale <- color.scale(scaledmean_surfdist,0,c(0,1,1),c(1,1,0))
plot(scaledmean_surfdist, col = mean_surfdist_colorscale)


Files you end up with:
All landmarks:
scaledmeandist
meanprocdistcolorscale

surface semi-landmarks:
scaledmean_surfdist
mean_surfdist_colorscale

Next you will export the colored Procrustes distances as a point cloud


No comments:

Post a Comment