patternize
patternize copied to clipboard
plotHeat: Error in cartoon/raster stack Alignment
Hello Steven, Thanks for this beautiful and smart package!
I was trying to perfom the pattern analysis with Patternize but I bumped in some alignment issues.
Using the first method to align images and extract pattern (landmarks+RGB treshold), I couldn't get the heatmap aligned to the cartoon under it: I always get a shift along the y axis.
These two were generated with 2 different reference images, alongside with their respective outline.
I have to say I am quite green to R, hence it is porbably a matter of some wrong setting, but I tried various thing without consistent results, the only result was obtained by manually change the raster max coordinates or adding an asymmetrical cropOffset.
It is puzzling me the fact that the landmarks of the reference images don't match the outline cartoon that has been designed on the same exact image (no mismatch when I sequentially open these two landmark sets in ImageJ on top of the reference image): even when I set adjustCoords = FALSE in the stack generation, afterwards I can clearly see that the cartoon (outline mask) does not match any of the 4 raster image I used (It should be expected to match the raster from the original image, right?) (PS: Yes, the ref image is in the imageList)
That is the extent of my reasoning, I reallly don't want to bother you more than necessary, so do you have some suggestions? (The package version should be the final one, installed with devtools....) I can't exclude a problem of dataset, so tell me if my dataset is needed to figure out the issue.
These are the lines of your script I put my hands one, I suppose there is no need for the others: `rasterList_lanRGB <- patLanRGB(imageList, landmarkList, RGB, transformRef= 'SAM_4014', resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
plotHeat(summedRaster_lanRGB, IDlist, plotCartoon = TRUE, outline = cartoon, refShape = 'target', landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = "outline_4014", cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, flipOutline = 'y')`
Thanks in advance
Best, Paolo
Hi Paolo,
I am travelling right now, so it will take me a few days before I'll get to this. In the mean time, could you share me a folder with all the materials needed to run your analysis or a small part of it with a script? That will be easiest for me to troubleshoot.
Best,
Steven
-------- Original message -------- From: Pmajo @.> Date: 5/27/22 10:29 AM (GMT-05:00) To: StevenVB12/patternize @.> Cc: Subscribed @.***> Subject: [StevenVB12/patternize] plotHeat: Error in cartoon/raster stack Alignment (Issue #31)
Hello Steven, Thanks for this beautiful and smart package!
I was trying to perfom the pattern analysis with Patternize but I bumped in some alignment issues. Using the first method to align images and extract pattern (landmarks+RGB treshold), I couldn't get the heatmap aligned to the cartoon under it: I always get a shift along the y axis. [HeatMap1 0]https://user-images.githubusercontent.com/104376150/170706611-c4a0ddcf-c008-4d43-ad16-93cbbf38353c.jpeg [HeatMap2]https://user-images.githubusercontent.com/104376150/170715550-341f103e-94ca-4a6e-a3f2-a9055db07e77.jpeg
These two were generated with 2 different reference images, alongside with their respective outline.
I have to say I am quite green to R, hence it is porbably a matter of some wrong setting, but I tried various thing without consistent results, the only result was obtained by manually change the raster max coordinates or adding an asymmetrical cropOffset.
It is puzzling me the fact that the landmarks of the reference images don't match the outline cartoon that has been designed on the same exact image (no mismatch when I sequentially open these two landmark sets in ImageJ on top of the reference image): even when I set adjustCoords = FALSE in the stack generation, afterwards I can clearly see that the cartoon (outline mask) does not match any of the 4 raster image I used (It should be expected to match the raster from the original image, right?) (PS: Yes, the ref image is in the imageList)
That is the extent of my reasoning, I reallly don't want to bother you more than necessary, so do you have some suggestions? (The package version should be the final one, installed with devtools....) I can't exclude a problem of dataset, so tell me if my dataset is needed to figure out the issue.
These are the lines of your script I put my hands one, I suppose there is no need for the others: `rasterList_lanRGB <- patLanRGB(imageList, landmarkList, RGB, transformRef= 'SAM_4014', resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
plotHeat(summedRaster_lanRGB, IDlist, plotCartoon = TRUE, outline = cartoon, refShape = 'target', landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = "outline_4014", cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, flipOutline = 'y')`
Thanks in advance
Best, Paolo
— Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/31, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC4ZF4KPBZYSOZ7CTMOLVMDL43ANCNFSM5XEMRTSA. You are receiving this because you are subscribed to this thread.Message ID: @.***>
Hi Steven,
Hope you are well,
First of all, thank you very much for creating Patternize! I've been using it to measure colour variation in Atlantic salmon parr for my Masters project and I have really enjoyed working with this package.
However, I'm facing a similar issue with the alignment of heatmaps on template outlines. I even encounter this issue when I run the examples in the patternize-examples repository. So when I run the following...
# Load required packages
library(viridis)
library(patternize)
# Lists with samples
IDListHyb <- c('BC0213','BC0360','BC0391','BC2407','BC2321','BC2207','BC2208','BC0637','BC2359','BC2550')
# make list with images
prepath <- 'images/Heliconius'
extension <- '-D.jpg'
imageListEra <- makeList(IDListEra, 'image', prepath, extension)
imageListHyb <- makeList(IDListHyb, 'image', prepath, extension)
# choose target image
target <- imageListEra[['BC0057']]
RGB <- c(114,17,0) # red
rasterList_regRGBHyb <- patRegRGB(imageListHyb, target, RGB, resampleFactor = 5, colOffset= 0.12,
crop = c(1000,3800,500,2800), removebgR = 100, plot = 'stack', focal = TRUE,
sigma = 5, iterations = 3)
# sum the colorpatterns
summedRaster_regRGBHyb <- sumRaster(rasterList_regRGBHyb, IDListHyb, type = 'RGB')
# plot heatmap
outline_BC0057 <- read.table('cartoon/BC0057_outline.txt', h= F)
lines_BC0057 <- list.files(path='cartoon', pattern='BC0057_vein', full.names = T)
plotHeat(summedRaster_regRGBHyb, IDListHyb, plotCartoon = TRUE, refShape = 'target', outline = outline_BC0057,
lines = lines_BC0057, landList = landmarkList, crop = c(1000,3800,500,2800), flipRaster = 'xy',
imageList = imageListHyb, cartoonID = 'BC0057', cartoonFill = 'black', cartoonOrder = 'under',
colpalette = colfunc)
... R outputs this figure:
As you can see, the pattern is incorrectly aligned along the y-axis.
Any help you can provide would be very much appreciated.
Thanks for your time,
Dylan
Hi Steven, I am working with Heliconius and using patternize to measure their variation. Like the post above, I am having a hard time getting the raster to align with the cartoon. This is also a problem in the PCA as well. I have uploaded the images to a google drive and can share the link. I dont know what the problem is. Even the cartoon is flipped, compared to the orientation of the original images and the representative cartoons. What do you recommend? I can share the link and code, if you provide an email.
Code is here; I've been following along line by line from your Heliconius forewingband project, its not an immediate need, just for making the lovely figures that I know patternize can do. Take your time in response. Thank you again! Christopher
library(patternize) library(Morpho) library(viridis)
setwd("~/Desktop/smpl_images/forewings/")
#load sample list
smpls<- read.csv("~/Desktop/DRB_lab/Chapter_2/data/annotated_samples_metadata.csv")
#subset for plesseni
mpls<- subset(smpls, smpls$Taxonomic.Name == "Heliconius melpomene ssp. plesseni")
List with samples
IDlistMples <- mpls$Unit.ID
make list with landmarks
prepath <- 'landmarks' extension <- '_d.txt' landmarkList <- makeList(IDlistMples, 'landmark', prepath, extension)
make list with images
prepath <- 'images/' extension <- '_d.jpg' imageList <- makeList(IDlistMples, 'image', prepath, extension)
tranformref
target <- landmarkList[['CAM016347']]
RGB <- c(231,62,30) # bright orange-red rasterList_lanRGB_plesseni <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
If you don't want to run the function, you can load the saved output rasterList
save(rasterList_lanRGB_plesseni, file = '../rasterlist_mplesseni.rda') #load('output/Fig1_rasterList_lanRGB.rda')
sum the colorpatterns
summedRaster_org <- sumRaster(rasterList_lanRGB_plesseni, IDlistMples, type = 'RGB')
plot heatmap
outline_pless <- read.table('../fwcartoons/plesseni_outline.txt.txt', h= F) lines_pless <- list.files(path='../fwcartoons/', pattern='plesseni_vein', full.names = T)
colfunc <- inferno(100) plotHeat(summedRaster_org, IDlistMples, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, lines = lines_pless, landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = 'BC0004', cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, legend.side = 2, main = "Heliconius melpomene plesseni HEATMAP")
#subset for plesseni x malleti#######################################
mpHYB<- subset(smpls, smpls$Taxonomic.Name == "Heliconius melpomene ssp. plesseni x malleti")
List with samples
IDlistmpHYB <- mpHYB$Unit.ID
make list with landmarks
prepath <- 'landmarks' extension <- '_d.txt' landmarkList <- makeList(IDlistmpHYB, 'landmark', prepath, extension)
make list with images
prepath <- 'images/' extension <- '_d.jpg' imageList <- makeList(IDlistmpHYB, 'image', prepath, extension)
tranformref
target <- landmarkList[['CAM016084']]
RGB <- c(231,62,30) # bright orange-red rasterList_lanRGB_mphyb <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
If you don't want to run the function, you can load the saved output rasterList
save(rasterList_lanRGB_mphyb, file = '../plessxmallet_rasterList.rda') #load('output/Fig1_rasterList_lanRGB.rda')
sum the colorpatterns
summedRaster_org <- sumRaster(rasterList_lanRGB_mphyb, IDlistmpHYB, type = 'RGB')
plot heatmap
outline_pless <- read.table('../fwcartoons/plessxmalleti_outline.txt', h= F) lines_pless <- list.files(path='../fwcartoons/', pattern='plessxmalleti_vein', full.names = T)
colfunc <- inferno(100) plotHeat(summedRaster_org, IDlistmpHYB, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, lines = lines_pless, landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = 'BC0004', cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, main = "Heliconius melpomene plesseni x malleti HEATMAP")
#subset for malleti#######################################
malleti<- subset(smpls, smpls$Taxonomic.Name == "Heliconius melpomene ssp. malleti")
List with samples
IDlistmlt <- malleti$Unit.ID
make list with landmarks
prepath <- 'landmarks' extension <- '_d.txt' landmarkList <- makeList(IDlistmlt, 'landmark', prepath, extension)
make list with images
prepath <- 'images/' extension <- '_d.jpg' imageList <- makeList(IDlistmlt, 'image', prepath, extension)
tranformref
target <- landmarkList[['CAM017064']]
RGB <- c(231,62,30) # bright orange-red rasterList_lanRGB_malleti <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
If you don't want to run the function, you can load the saved output rasterList
save(rasterList_lanRGB_malleti, file = '../rasterList_malleti.rda') #load('output/Fig1_rasterList_lanRGB.rda')
sum the colorpatterns
summedRaster_org <- sumRaster(rasterList_lanRGB_malleti, IDlistmlt, type = 'RGB')
plot heatmap
outline_pless <- read.table('../fwcartoons/mmalleti_outline.txt', h= F) lines_pless <- list.files(path='../fwcartoons/', pattern='mmalleti_vein', full.names = T)
colfunc <- inferno(100) plotHeat(summedRaster_org, IDlistmpHYB, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, lines = lines_pless, landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = 'BC0004', cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, main = "Heliconius melpomene malleti HEATMAP")
#subset for erato lativitta#######################################
el<- subset(smpls, smpls$Taxonomic.Name == "Heliconius erato ssp. lativitta")
List with samples
IDlistelativ <- el$Unit.ID
make list with landmarks
prepath <- 'landmarks' extension <- '_d.txt' landmarkList <- makeList(IDlistelativ, 'landmark', prepath, extension)
make list with images
prepath <- 'images/' extension <- '_d.jpg' imageList <- makeList(IDlistelativ, 'image', prepath, extension)
tranformref
target <- landmarkList[['CAM041591']]
RGB <- c(231,62,30) # bright orange-red rasterList_lanRGB_elativ <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
If you don't want to run the function, you can load the saved output rasterList
save(rasterList_lanRGB_elativ, file = '../rasterList_eratolativ.rda') #load('output/Fig1_rasterList_lanRGB.rda')
sum the colorpatterns
summedRaster_org <- sumRaster(rasterList_lanRGB_elativ, IDlistelativ, type = 'RGB')
plot heatmap
outline_pless <- read.table('../fwcartoons/eratolativ_outline.txt', h= F) lines_pless <- list.files(path='../fwcartoons/', pattern='eratolativ_vein', full.names = T)
colfunc <- inferno(100) plotHeat(summedRaster_org, IDlistelativ, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, lines = lines_pless, landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = 'BC0004', cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, main = "Heliconius erato lativitta HEATMAP")
#subset for notabilis#######################################
en<- subset(smpls, smpls$Taxonomic.Name == "Heliconius erato ssp. notabilis")
List with samples
IDlistenotab <- en$Unit.ID
make list with landmarks
prepath <- 'landmarks' extension <- '_d.txt' landmarkList <- makeList(IDlistenotab, 'landmark', prepath, extension)
make list with images
prepath <- 'images/' extension <- '_d.jpg' imageList <- makeList(IDlistenotab, 'image', prepath, extension)
tranformref
target <- landmarkList[['CAM016879']]
RGB <- c(231,62,30) # bright orange-red rasterList_lanRGB_enotab<- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
If you don't want to run the function, you can load the saved output rasterList
save(rasterList_lanRGB_enotab, file = '../rasterList_eratonotab.rda') #load('output/Fig1_rasterList_lanRGB.rda')
sum the colorpatterns
summedRaster_org <- sumRaster(rasterList_lanRGB, IDlistenotab, type = 'RGB')
plot heatmap
outline_pless <- read.table('../fwcartoons/eratonotab_outline.txt', h= F) lines_pless <- list.files(path='../fwcartoons/', pattern='eratonotab_vein', full.names = T)
colfunc <- inferno(100) plotHeat(summedRaster_org, IDlistenotab, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, lines = lines_pless, landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = 'CAM016879', cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, main = "Heliconius erato notabilis HEATMAP")
#subset for notab lativ hybrid#######################################
nxlHYB<- subset(smpls, smpls$Taxonomic.Name == "Heliconius erato ssp. notabilis x lativitta")
List with samples
IDlistnlHYB <- nxlHYB$Unit.ID
make list with landmarks
prepath <- 'landmarks' extension <- '_d.txt' landmarkList <- makeList(IDlistnlHYB, 'landmark', prepath, extension)
make list with images
prepath <- 'images/' extension <- '_d.jpg' imageList <- makeList(IDlistnlHYB, 'image', prepath, extension)
tranformref
target <- landmarkList[['CAM017425']]
RGB <- c(231,62,30) # bright orange-red rasterList_lanRGB_nlhyb <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
If you don't want to run the function, you can load the saved output rasterList
save(rasterList_lanRGB_nlhyb, file = '../rasterList_notabxlativ.rda') #load('output/Fig1_rasterList_lanRGB.rda')
sum the colorpatterns
summedRaster_org <- sumRaster(rasterList_lanRGB_nlhyb, IDlistnlHYB, type = 'RGB')
plot heatmap
outline_pless <- read.table('../fwcartoons/notxlativ_outline.txt', h= F) lines_pless <- list.files(path='../fwcartoons/', pattern='notxlativ_vein', full.names = T)
colfunc <- inferno(100) plotHeat(summedRaster_org, IDlistnlHYB, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, lines = lines_pless, landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = 'BC0004', cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, main = "Heliconius notabilis x lativitta HEATMAP")
######## ####load the sumrasters load('../plessxmallet_rasterList.rda') load('../rasterList_malleti.rda') load('../rasterlist_mplesseni.rda') load('../rasterList_eratonotab.rda') load('../rasterList_eratolativ.rda') load('../rasterList_notabxlativ.rda')
Plot PCA
Make population and color list
popList <- list(IDlistMples, IDlistmpHYB, IDlistmlt) colList <- c("gold", "red", "green") symbolList <- c(16,17,18)
TotalList <- c(rasterList_lanRGB_plesseni,rasterList_lanRGB_mphyb,rasterList_lanRGB_malleti)
pcaOut <- patPCA(TotalList, popList, colList, symbolList = symbolList, plot = TRUE, plotType = 'points', plotChanges = TRUE, PCx = 1, PCy = 2, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, adjustCoords = TRUE, flipOutline = TRUE, imageList = imageList, cartoonID = 'pless', normalized = TRUE, cartoonFill = 'black', cartoonOrder = 'under', legendTitle = 'Predicted')
Hi,
Please do share me the google drive link.
Thanks,
Steven
From: C-G-L @.> Sent: Saturday, October 1, 2022 2:01 AM To: StevenVB12/patternize @.> Cc: Steven M. Van Belleghem @.>; Comment @.> Subject: Re: [StevenVB12/patternize] plotHeat: Error in cartoon/raster stack Alignment (Issue #31)
Code is here; I've been following along line by line from your Heliconius forewingband project, its not an immediate need, just for making the lovely figures that I know patternize can do. Take your time in response. Thank you again! Christopher
library(patternize) library(Morpho) library(viridis)
setwd("~/Desktop/smpl_images/forewings/")
#load sample list
smpls<- read.csv("~/Desktop/DRB_lab/Chapter_2/data/annotated_samples_metadata.csv")
#subset for plesseni
mpls<- subset(smpls, smpls$Taxonomic.Name == "Heliconius melpomene ssp. plesseni")
List with samples
IDlistMples <- mpls$Unit.ID
make list with landmarks
prepath <- 'landmarks' extension <- '_d.txt' landmarkList <- makeList(IDlistMples, 'landmark', prepath, extension)
make list with images
prepath <- 'images/' extension <- '_d.jpg' imageList <- makeList(IDlistMples, 'image', prepath, extension)
tranformref
target <- landmarkList[['CAM016347']]
RGB <- c(231,62,30) # bright orange-red rasterList_lanRGB_plesseni <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
If you don't want to run the function, you can load the saved output rasterList
save(rasterList_lanRGB_plesseni, file = '../rasterlist_mplesseni.rda') #load('output/Fig1_rasterList_lanRGB.rda')
sum the colorpatterns
summedRaster_org <- sumRaster(rasterList_lanRGB_plesseni, IDlistMples, type = 'RGB')
plot heatmap
outline_pless <- read.table('../fwcartoons/plesseni_outline.txt.txt', h= F) lines_pless <- list.files(path='../fwcartoons/', pattern='plesseni_vein', full.names = T)
colfunc <- inferno(100) plotHeat(summedRaster_org, IDlistMples, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, lines = lines_pless, landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = 'BC0004', cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, legend.side = 2, main = "Heliconius melpomene plesseni HEATMAP")
#subset for plesseni x malleti#######################################
mpHYB<- subset(smpls, smpls$Taxonomic.Name == "Heliconius melpomene ssp. plesseni x malleti")
List with samples
IDlistmpHYB <- mpHYB$Unit.ID
make list with landmarks
prepath <- 'landmarks' extension <- '_d.txt' landmarkList <- makeList(IDlistmpHYB, 'landmark', prepath, extension)
make list with images
prepath <- 'images/' extension <- '_d.jpg' imageList <- makeList(IDlistmpHYB, 'image', prepath, extension)
tranformref
target <- landmarkList[['CAM016084']]
RGB <- c(231,62,30) # bright orange-red rasterList_lanRGB_mphyb <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
If you don't want to run the function, you can load the saved output rasterList
save(rasterList_lanRGB_mphyb, file = '../plessxmallet_rasterList.rda') #load('output/Fig1_rasterList_lanRGB.rda')
sum the colorpatterns
summedRaster_org <- sumRaster(rasterList_lanRGB_mphyb, IDlistmpHYB, type = 'RGB')
plot heatmap
outline_pless <- read.table('../fwcartoons/plessxmalleti_outline.txt', h= F) lines_pless <- list.files(path='../fwcartoons/', pattern='plessxmalleti_vein', full.names = T)
colfunc <- inferno(100) plotHeat(summedRaster_org, IDlistmpHYB, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, lines = lines_pless, landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = 'BC0004', cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, main = "Heliconius melpomene plesseni x malleti HEATMAP")
#subset for malleti#######################################
malleti<- subset(smpls, smpls$Taxonomic.Name == "Heliconius melpomene ssp. malleti")
List with samples
IDlistmlt <- malleti$Unit.ID
make list with landmarks
prepath <- 'landmarks' extension <- '_d.txt' landmarkList <- makeList(IDlistmlt, 'landmark', prepath, extension)
make list with images
prepath <- 'images/' extension <- '_d.jpg' imageList <- makeList(IDlistmlt, 'image', prepath, extension)
tranformref
target <- landmarkList[['CAM017064']]
RGB <- c(231,62,30) # bright orange-red rasterList_lanRGB_malleti <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
If you don't want to run the function, you can load the saved output rasterList
save(rasterList_lanRGB_malleti, file = '../rasterList_malleti.rda') #load('output/Fig1_rasterList_lanRGB.rda')
sum the colorpatterns
summedRaster_org <- sumRaster(rasterList_lanRGB_malleti, IDlistmlt, type = 'RGB')
plot heatmap
outline_pless <- read.table('../fwcartoons/mmalleti_outline.txt', h= F) lines_pless <- list.files(path='../fwcartoons/', pattern='mmalleti_vein', full.names = T)
colfunc <- inferno(100) plotHeat(summedRaster_org, IDlistmpHYB, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, lines = lines_pless, landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = 'BC0004', cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, main = "Heliconius melpomene malleti HEATMAP")
#subset for erato lativitta#######################################
el<- subset(smpls, smpls$Taxonomic.Name == "Heliconius erato ssp. lativitta")
List with samples
IDlistelativ <- el$Unit.ID
make list with landmarks
prepath <- 'landmarks' extension <- '_d.txt' landmarkList <- makeList(IDlistelativ, 'landmark', prepath, extension)
make list with images
prepath <- 'images/' extension <- '_d.jpg' imageList <- makeList(IDlistelativ, 'image', prepath, extension)
tranformref
target <- landmarkList[['CAM041591']]
RGB <- c(231,62,30) # bright orange-red rasterList_lanRGB_elativ <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
If you don't want to run the function, you can load the saved output rasterList
save(rasterList_lanRGB_elativ, file = '../rasterList_eratolativ.rda') #load('output/Fig1_rasterList_lanRGB.rda')
sum the colorpatterns
summedRaster_org <- sumRaster(rasterList_lanRGB_elativ, IDlistelativ, type = 'RGB')
plot heatmap
outline_pless <- read.table('../fwcartoons/eratolativ_outline.txt', h= F) lines_pless <- list.files(path='../fwcartoons/', pattern='eratolativ_vein', full.names = T)
colfunc <- inferno(100) plotHeat(summedRaster_org, IDlistelativ, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, lines = lines_pless, landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = 'BC0004', cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, main = "Heliconius erato lativitta HEATMAP")
#subset for notabilis#######################################
en<- subset(smpls, smpls$Taxonomic.Name == "Heliconius erato ssp. notabilis")
List with samples
IDlistenotab <- en$Unit.ID
make list with landmarks
prepath <- 'landmarks' extension <- '_d.txt' landmarkList <- makeList(IDlistenotab, 'landmark', prepath, extension)
make list with images
prepath <- 'images/' extension <- '_d.jpg' imageList <- makeList(IDlistenotab, 'image', prepath, extension)
tranformref
target <- landmarkList[['CAM016879']]
RGB <- c(231,62,30) # bright orange-red rasterList_lanRGB_enotab<- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
If you don't want to run the function, you can load the saved output rasterList
save(rasterList_lanRGB_enotab, file = '../rasterList_eratonotab.rda') #load('output/Fig1_rasterList_lanRGB.rda')
sum the colorpatterns
summedRaster_org <- sumRaster(rasterList_lanRGB, IDlistenotab, type = 'RGB')
plot heatmap
outline_pless <- read.table('../fwcartoons/eratonotab_outline.txt', h= F) lines_pless <- list.files(path='../fwcartoons/', pattern='eratonotab_vein', full.names = T)
colfunc <- inferno(100) plotHeat(summedRaster_org, IDlistenotab, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, lines = lines_pless, landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = 'CAM016879', cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, main = "Heliconius erato notabilis HEATMAP")
#subset for notab lativ hybrid#######################################
nxlHYB<- subset(smpls, smpls$Taxonomic.Name == "Heliconius erato ssp. notabilis x lativitta")
List with samples
IDlistnlHYB <- nxlHYB$Unit.ID
make list with landmarks
prepath <- 'landmarks' extension <- '_d.txt' landmarkList <- makeList(IDlistnlHYB, 'landmark', prepath, extension)
make list with images
prepath <- 'images/' extension <- '_d.jpg' imageList <- makeList(IDlistnlHYB, 'image', prepath, extension)
tranformref
target <- landmarkList[['CAM017425']]
RGB <- c(231,62,30) # bright orange-red rasterList_lanRGB_nlhyb <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3, colOffset = 0.15, crop = TRUE, res = 200, adjustCoords = TRUE, plot = 'stack')
If you don't want to run the function, you can load the saved output rasterList
save(rasterList_lanRGB_nlhyb, file = '../rasterList_notabxlativ.rda') #load('output/Fig1_rasterList_lanRGB.rda')
sum the colorpatterns
summedRaster_org <- sumRaster(rasterList_lanRGB_nlhyb, IDlistnlHYB, type = 'RGB')
plot heatmap
outline_pless <- read.table('../fwcartoons/notxlativ_outline.txt', h= F) lines_pless <- list.files(path='../fwcartoons/', pattern='notxlativ_vein', full.names = T)
colfunc <- inferno(100) plotHeat(summedRaster_org, IDlistnlHYB, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, lines = lines_pless, landList = landmarkList, adjustCoords = TRUE, imageList = imageList, cartoonID = 'BC0004', cartoonFill = 'black', cartoonOrder = 'under', colpalette = colfunc, main = "Heliconius notabilis x lativitta HEATMAP")
######## ####load the sumrasters load('../plessxmallet_rasterList.rda') load('../rasterList_malleti.rda') load('../rasterlist_mplesseni.rda') load('../rasterList_eratonotab.rda') load('../rasterList_eratolativ.rda') load('../rasterList_notabxlativ.rda')
Plot PCA Make population and color list
popList <- list(IDlistMples, IDlistmpHYB, IDlistmlt) colList <- c("gold", "red", "green") symbolList <- c(16,17,18)
TotalList <- c(rasterList_lanRGB_plesseni,rasterList_lanRGB_mphyb,rasterList_lanRGB_malleti)
pcaOut <- patPCA(TotalList, popList, colList, symbolList = symbolList, plot = TRUE, plotType = 'points', plotChanges = TRUE, PCx = 1, PCy = 2, plotCartoon = TRUE, refShape = 'target', outline = outline_pless, adjustCoords = TRUE, flipOutline = TRUE, imageList = imageList, cartoonID = 'pless', normalized = TRUE, cartoonFill = 'black', cartoonOrder = 'under', legendTitle = 'Predicted')
— Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/31#issuecomment-1264138707, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC4ZH4VGTLYTCGF66V23WA55MPANCNFSM5XEMRTSA. You are receiving this because you commented.Message ID: @.@.>>
Hi Dylan,
I pushed a fix of plotHeat and the example code to github. There was something off in the code (keeping track of the extent of the raster and matching outline gets difficult to me when there’s a crop involved and need for reorientation). Hope this fixes it (and doesn’t break any other code).
Is the registration otherwise working well for you? I find landmarking always a more detailed option in my analysis.. Therefore the registration code has not been updated as frequently.
Please keep me informed if you come across any other issues.
Best,
Steven
From: DylanCarbone @.> Sent: Monday, June 20, 2022 11:58 AM To: StevenVB12/patternize @.> Cc: Steven M. Van Belleghem @.>; Comment @.> Subject: Re: [StevenVB12/patternize] plotHeat: Error in cartoon/raster stack Alignment (Issue #31)
Hi Steven,
Hope you are well,
First of all, thank you very much for creating Patternize! I've been using it to measure colour variation in Atlantic salmon parr for my Masters project and I have really enjoyed the working with this package.
However, I'm facing a similar issue with the alignment of heatmaps on template outlines. I even encounter this issue when I run the examples in the patternize-examples repository. So when I run the following...
Load required packages
library(viridis)
library(patternize)
Lists with samples
IDListHyb <- c('BC0213','BC0360','BC0391','BC2407','BC2321','BC2207','BC2208','BC0637','BC2359','BC2550')
make list with images
prepath <- 'images/Heliconius'
extension <- '-D.jpg'
imageListEra <- makeList(IDListEra, 'image', prepath, extension)
imageListHyb <- makeList(IDListHyb, 'image', prepath, extension)
choose target image
target <- imageListEra[['BC0057']]
RGB <- c(114,17,0) # red
rasterList_regRGBHyb <- patRegRGB(imageListHyb, target, RGB, resampleFactor = 5, colOffset= 0.12,
crop = c(1000,3800,500,2800), removebgR = 100, plot = 'stack', focal = TRUE,
sigma = 5, iterations = 3)
sum the colorpatterns
summedRaster_regRGBHyb <- sumRaster(rasterList_regRGBHyb, IDListHyb, type = 'RGB')
plot heatmap
outline_BC0057 <- read.table('cartoon/BC0057_outline.txt', h= F)
lines_BC0057 <- list.files(path='cartoon', pattern='BC0057_vein', full.names = T)
plotHeat(summedRaster_regRGBHyb, IDListHyb, plotCartoon = TRUE, refShape = 'target', outline = outline_BC0057,
lines = lines_BC0057, landList = landmarkList, crop = c(1000,3800,500,2800), flipRaster = 'xy',
imageList = imageListHyb, cartoonID = 'BC0057', cartoonFill = 'black', cartoonOrder = 'under',
colpalette = colfunc)
... R outputs this figure on my console:
[example_img]https://user-images.githubusercontent.com/94693787/174638003-b041add6-f506-4c44-a9ee-f0dfa23d4e48.jpg
As you can see, the pattern is incorrectly aligned along the y-axis.
Any help help you can provide would be very much appreciated.
Thanks for your time,
Dylan
— Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/31#issuecomment-1160614669, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC4YVDNL3DUFI3IUA4XLVQCIILANCNFSM5XEMRTSA. You are receiving this because you commented.Message ID: @.@.>>
Hi Steven,
Hope you are well,
We had an email exchange in July, and you fixed all the issues I had with with raster alignment then! :)
Thanks again for your help,
Dylan
Hi Steven,
You were correct! Aligning them all to the same reference and adding to refImage, fixed the heatmap. However, I am still fighting the pcaplot. Below I have plotted hindwings, and the outline and raster dont match up. I aligned them all to the same reference. Any recommendations here?
On Tue, Oct 11, 2022 at 2:27 PM DylanCarbone @.***> wrote:
Hi Steven,
Hope you are well,
We had an email exchange in July, and you fixed all the issues I had with with raster alignment then! :)
Thanks again for your help,
Dylan
— Reply to this email directly, view it on GitHub https://github.com/StevenVB12/patternize/issues/31#issuecomment-1275104606, or unsubscribe https://github.com/notifications/unsubscribe-auth/AROB2RON25VYHRB3BZWDH5DWCWWPZANCNFSM5XEMRTSA . You are receiving this because you commented.Message ID: @.***>
And if I use the example data, it looks like so.
On Thu, Oct 13, 2022 at 10:54 PM Christopher Lawrence @.***> wrote:
Hi Steven,
You were correct! Aligning them all to the same reference and adding to refImage, fixed the heatmap. However, I am still fighting the pcaplot. Below I have plotted hindwings, and the outline and raster dont match up. I aligned them all to the same reference. Any recommendations here?
On Tue, Oct 11, 2022 at 2:27 PM DylanCarbone @.***> wrote:
Hi Steven,
Hope you are well,
We had an email exchange in July, and you fixed all the issues I had with with raster alignment then! :)
Thanks again for your help,
Dylan
— Reply to this email directly, view it on GitHub https://github.com/StevenVB12/patternize/issues/31#issuecomment-1275104606, or unsubscribe https://github.com/notifications/unsubscribe-auth/AROB2RON25VYHRB3BZWDH5DWCWWPZANCNFSM5XEMRTSA . You are receiving this because you commented.Message ID: @.***>
Hi Christopher,
Could you try adding the refimage also to the pca plot command like for the plotHeat?
Steven
-------- Original message -------- From: C-G-L @.> Date: 10/14/22 4:58 AM (GMT+01:00) To: StevenVB12/patternize @.> Cc: "Steven M. Van Belleghem" @.>, Comment @.> Subject: Re: [StevenVB12/patternize] plotHeat: Error in cartoon/raster stack Alignment (Issue #31)
And if I use the example data, it looks like so.
On Thu, Oct 13, 2022 at 10:54 PM Christopher Lawrence @.***> wrote:
Hi Steven,
You were correct! Aligning them all to the same reference and adding to refImage, fixed the heatmap. However, I am still fighting the pcaplot. Below I have plotted hindwings, and the outline and raster dont match up. I aligned them all to the same reference. Any recommendations here?
On Tue, Oct 11, 2022 at 2:27 PM DylanCarbone @.***> wrote:
Hi Steven,
Hope you are well,
We had an email exchange in July, and you fixed all the issues I had with with raster alignment then! :)
Thanks again for your help,
Dylan
— Reply to this email directly, view it on GitHub https://github.com/StevenVB12/patternize/issues/31#issuecomment-1275104606, or unsubscribe https://github.com/notifications/unsubscribe-auth/AROB2RON25VYHRB3BZWDH5DWCWWPZANCNFSM5XEMRTSA . You are receiving this because you commented.Message ID: @.***>
— Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/31#issuecomment-1278406404, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC42L2NZSLGICARHWWBDWDDD5XANCNFSM5XEMRTSA. You are receiving this because you commented.Message ID: @.***>
Hi!
Tried it out this morning, like so, and still no joy.
pcaOut <- patPCA(TotalList, popList, colList, symbolList = symbolList, plot = TRUE, plotType = 'points', plotChanges = TRUE, PCx = 1, PCy = 2, plotCartoon = TRUE, refShape = 'target', refImage = imageList[["CAM016347"]], outline = outline_pless, imageList = imageList, cartoonID = 'pless', normalized = TRUE, cartoonFill = 'black', cartoonOrder = 'under', legendTitle = 'Predicted')
On Fri, Oct 14, 2022 at 5:25 AM Steven M. Van Belleghem < @.***> wrote:
Hi Christopher,
Could you try adding the refimage also to the pca plot command like for the plotHeat?
Steven
-------- Original message -------- From: C-G-L @.> Date: 10/14/22 4:58 AM (GMT+01:00) To: StevenVB12/patternize @.> Cc: "Steven M. Van Belleghem" @.>, Comment @.> Subject: Re: [StevenVB12/patternize] plotHeat: Error in cartoon/raster stack Alignment (Issue #31)
And if I use the example data, it looks like so.
On Thu, Oct 13, 2022 at 10:54 PM Christopher Lawrence @.***> wrote:
Hi Steven,
You were correct! Aligning them all to the same reference and adding to refImage, fixed the heatmap. However, I am still fighting the pcaplot. Below I have plotted hindwings, and the outline and raster dont match up. I aligned them all to the same reference. Any recommendations here?
On Tue, Oct 11, 2022 at 2:27 PM DylanCarbone @.***> wrote:
Hi Steven,
Hope you are well,
We had an email exchange in July, and you fixed all the issues I had with with raster alignment then! :)
Thanks again for your help,
Dylan
— Reply to this email directly, view it on GitHub < https://github.com/StevenVB12/patternize/issues/31#issuecomment-1275104606 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AROB2RON25VYHRB3BZWDH5DWCWWPZANCNFSM5XEMRTSA
. You are receiving this because you commented.Message ID: @.***>
— Reply to this email directly, view it on GitHub< https://github.com/StevenVB12/patternize/issues/31#issuecomment-1278406404>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/ABQOC42L2NZSLGICARHWWBDWDDD5XANCNFSM5XEMRTSA
. You are receiving this because you commented.Message ID: @.***>
— Reply to this email directly, view it on GitHub https://github.com/StevenVB12/patternize/issues/31#issuecomment-1278735992, or unsubscribe https://github.com/notifications/unsubscribe-auth/AROB2RLUZSSXP4XLNV36P4TWDERHNANCNFSM5XEMRTSA . You are receiving this because you commented.Message ID: @.***>
Does the totallist include all the samples aligned to the same target? Also make sure anything else matches the plotHeat command if it’s possible.
Steven
From: C-G-L @.> Sent: Friday, October 14, 2022 6:22 PM To: StevenVB12/patternize @.> Cc: Steven M. Van Belleghem @.>; Comment @.> Subject: Re: [StevenVB12/patternize] plotHeat: Error in cartoon/raster stack Alignment (Issue #31)
Hi!
Tried it out this morning, like so, and still no joy.
pcaOut <- patPCA(TotalList, popList, colList, symbolList = symbolList, plot = TRUE, plotType = 'points', plotChanges = TRUE, PCx = 1, PCy = 2, plotCartoon = TRUE, refShape = 'target', refImage = imageList[["CAM016347"]], outline = outline_pless, imageList = imageList, cartoonID = 'pless', normalized = TRUE, cartoonFill = 'black', cartoonOrder = 'under', legendTitle = 'Predicted')
On Fri, Oct 14, 2022 at 5:25 AM Steven M. Van Belleghem < @.***mailto:***@***.***> wrote:
Hi Christopher,
Could you try adding the refimage also to the pca plot command like for the plotHeat?
Steven
-------- Original message -------- From: C-G-L @.mailto:***@***.***> Date: 10/14/22 4:58 AM (GMT+01:00) To: StevenVB12/patternize @.mailto:***@***.***> Cc: "Steven M. Van Belleghem" @.mailto:***@***.***>, Comment @.mailto:***@***.***> Subject: Re: [StevenVB12/patternize] plotHeat: Error in cartoon/raster stack Alignment (Issue #31)
And if I use the example data, it looks like so.
On Thu, Oct 13, 2022 at 10:54 PM Christopher Lawrence @.***mailto:***@***.***> wrote:
Hi Steven,
You were correct! Aligning them all to the same reference and adding to refImage, fixed the heatmap. However, I am still fighting the pcaplot. Below I have plotted hindwings, and the outline and raster dont match up. I aligned them all to the same reference. Any recommendations here?
On Tue, Oct 11, 2022 at 2:27 PM DylanCarbone @.***mailto:***@***.***> wrote:
Hi Steven,
Hope you are well,
We had an email exchange in July, and you fixed all the issues I had with with raster alignment then! :)
Thanks again for your help,
Dylan
— Reply to this email directly, view it on GitHub < https://github.com/StevenVB12/patternize/issues/31#issuecomment-1275104606 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AROB2RON25VYHRB3BZWDH5DWCWWPZANCNFSM5XEMRTSA
. You are receiving this because you commented.Message ID: @.***mailto:***@***.***>
— Reply to this email directly, view it on GitHub< https://github.com/StevenVB12/patternize/issues/31#issuecomment-1278406404>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/ABQOC42L2NZSLGICARHWWBDWDDD5XANCNFSM5XEMRTSA
. You are receiving this because you commented.Message ID: @.***mailto:***@***.***>
— Reply to this email directly, view it on GitHub https://github.com/StevenVB12/patternize/issues/31#issuecomment-1278735992, or unsubscribe https://github.com/notifications/unsubscribe-auth/AROB2RLUZSSXP4XLNV36P4TWDERHNANCNFSM5XEMRTSA . You are receiving this because you commented.Message ID: @.***mailto:***@***.***>
— Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/31#issuecomment-1279212464, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC473RMZTAV4TUFLXJJLWDGCA3ANCNFSM5XEMRTSA. You are receiving this because you commented.Message ID: @.@.>>