[rast] extent unknown in alignLan and masking problem
Dear Steven,
Thank you very much for working on this package. I'm trying to use patternize and recolorize to analyze some butterfly wing patterns (classic) following the protocol described here https://hiweller.rbind.io/post/recolorize-patternize-workflow/. I've been encountering an issue similar to this one https://github.com/StevenVB12/patternize/issues/42 but nonetheless quite different, so that I couldn't follow the resolution of that thread.
I have 6 sets of 12 landmarks as XY coordinates for 6 images of butterfly forewings, and the coordinates of one outline to serve as a mask, to be applied to all of them as in Hannah Weller's workflow. The images are .tif files all cropped to the same dimensions so that they only include one forewing and the grey background around it, and the colours are the native ones from the scans I took, I applied no other colour alterations as I was hoping to do it with patternize/recolorize.
The issue arises when I try to align the images using alignLan:
IDlist<-c("1695","1699","1712","1730","1746","1776")
# make list with images
imageList <- makeList(IDlist, type = "image",
prepath = "./",
extension = "_cropped_D.tif")
# make list with landmarks
landmarkList <- makeList(IDlist,
type = "landmark",
prepath = "./",
extension = "_coord_D.txt")
#rename individuals so names are not numeric
names(imageList)<-c("m1695","m1699","m1712","m1730","m1746","m1776")
names(landmarkList)<-c("m1695","m1699","m1712","m1730","m1746","m1776")
# Set target as first individual (also has outline coordinates)
target <- landmarkList[["m1695"]]
# Set up mask using first individual's outline
mask <- read.table("1695_outline.txt", header = FALSE)
### Alignment ###
imageList_aligned <- alignLan(imageList, landmarkList, transformRef = target,
adjustCoords = TRUE,
plotTransformed = T,
resampleFactor = 3,
inverse = F)
Images and landmarks are imported correctly as far as I can tell, but when I run alignLan, I get
There were 18 warnings (use warnings() to see them)
1: [rast] unknown extent
2: [rast] unknown extent
3: [rast] unknown extent
4: [rast] unknown extent
(etc x 18)
The workflow cannot continue after this as the array generated this way contains several NA's for each sample. Additionally, when I alter the command to
imageList_aligned <- alignLan(imageList, landmarkList, transformRef = target,
adjustCoords = TRUE,
plotTransformed = T,
resampleFactor = 3,
cartoonID = 'm1695',
maskOutline = mask,
inverse = F)
In addition to the same "extent unknown" problem, it doesn't seem to even be able to import the images correctly, as it only plots black rectangles. The masking is quite essential as I need to get rid of the images' grey background, but there is a slight chance I may be misinterpreting how to use it, so I'm open to suggestions on how to best communicate to patternize that I want it to ignore the area outside the wing.
While searching around StackOverflow I noticed you may have heard of the "extent unknown" issue and dealt with it in the past, but I wonder if maybe in the meantime new updates to R caused it to show up again. I'm using the devtools installation of patternize from your github and I've attempted to do this on a few different versions of R (4.3.2, 4.3.3, 4.4.0) with no difference in the results.
I hope you can help me and I'm happy to provide more details if needed. Thank you very much in any case!
Hi,
Could you quickly check if converting your images to jpg format solves the problem. If not, could you send me some of your images, landmarks and outline for me to troubleshoot?
Thanks,
Steven
Van Belleghem Steven From: brunacama93 @.> Sent: Tuesday, 7 May 2024 11:07 To: StevenVB12/patternize @.> Cc: Subscribed @.***> Subject: [StevenVB12/patternize] [rast] extent unknown in alignLan and masking problem (Issue #43)
Dear Steven,
Thank you very much for working on this package. I'm trying to use patternize and recolorize to analyze some butterfly wing patterns (classic) following the protocol described here https://hiweller.rbind.io/post/recolorize-patternize-workflow/. I've been encountering an issue similar to this one #42https://github.com/StevenVB12/patternize/issues/42 but nonetheless quite different, so that I couldn't follow the resolution of that thread.
I have 6 sets of 12 landmarks as XY coordinates for 6 images of butterfly forewings, and the coordinates of one outline to serve as a mask, to be applied to all of them as in Hannah Weller's workflow. The images are .tif files all cropped to the same dimensions so that they only include one forewing and the grey background around it, and the colours are the native ones from the scans I took, I applied no other colour alterations as I was hoping to do it with patternize/recolorize.
The issue arises when I try to align the images using alignLan:
IDlist<-c("1695","1699","1712","1730","1746","1776")
make list with images
imageList <- makeList(IDlist, type = "image",
prepath = "./",
extension = "_cropped_D.tif")
make list with landmarks
landmarkList <- makeList(IDlist,
type = "landmark",
prepath = "./",
extension = "_coord_D.txt")
#rename individuals so names are not numeric
names(imageList)<-c("m1695","m1699","m1712","m1730","m1746","m1776")
names(landmarkList)<-c("m1695","m1699","m1712","m1730","m1746","m1776")
Set target as first individual (also has outline coordinates)
target <- landmarkList[["m1695"]]
Set up mask using first individual's outline
mask <- read.table("1695_outline.txt", header = FALSE)
Alignment
imageList_aligned <- alignLan(imageList, landmarkList, transformRef = target,
adjustCoords = TRUE,
plotTransformed = T,
resampleFactor = 3,
inverse = F)
Images and landmarks are imported correctly as far as I can tell, but when I run alignLan, I get
There were 18 warnings (use warnings() to see them)
1: [rast] unknown extent
2: [rast] unknown extent
3: [rast] unknown extent
4: [rast] unknown extent
(etc x 18)
The workflow cannot continue after this as the array generated this way contains several NA's for each sample. Additionally, when I alter the command to
imageList_aligned <- alignLan(imageList, landmarkList, transformRef = target,
adjustCoords = TRUE,
plotTransformed = T,
resampleFactor = 3,
cartoonID = 'm1695',
maskOutline = mask,
inverse = F)
In addition to the same "extent unknown" problem, it doesn't seem to even be able to import the images correctly, as it only plots black rectangles. The masking is quite essential as I need to get rid of the images' grey background, but there is a slight chance I may be misinterpreting how to use it, so I'm open to suggestions on how to best communicate to patternize that I want it to ignore the area outside the wing.
While searching around StackOverflow I noticed you may have heard of the "extent unknown" issue and dealt with it in the past, but I wonder if maybe in the meantime new updates to R caused it to show up again. I'm using the devtools installation of patternize from your github and I've attempted to do this on a few different versions of R (4.3.2, 4.3.3, 4.4.0) with no difference in the results.
I hope you can help me and I'm happy to provide more details if needed. Thank you very much in any case!
— Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/43, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC45TX3L2PHZG4JHRM7DZBCKRPAVCNFSM6AAAAABHKSDDIGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI4DENRZG4ZDKMI. You are receiving this because you are subscribed to this thread.Message ID: @.@.>>
Hi Steven,
I tried using jpegs before, it doesn't change anything. Here's a few of my files- outline is also found in the coordinates folder https://github.com/brunacama93/melanargiatest
I had to remove a couple of them so the above code needs to be changed to omit 1730 and 1776. I added a modified version to the same repo for convenience.
Thank you for answering so promptly!
Hi,
This does seem to be working for me:
library(patternize) library(recolorize)
#I have all files within the same working directory for this small test
IDlist<-c("1695","1699","1712","1746")
make list with images
imageList <- makeList(IDlist, type = "image", prepath = "wing_scans", extension = "_cropped_D.jpg")
make list with landmarks
landmarkList <- makeList(IDlist, type = "landmark", prepath = "coordinates", extension = "_coord_D.txt")
#rename individuals so names are not numeric names(imageList)<-c("m1695","m1699","m1712","m1746") names(landmarkList)<-c("m1695","m1699","m1712","m1746")
Set target as first individual (also has outline coordinates)
target <- landmarkList[["m1695"]]
Set up mask using first individual's outline
mask <- read.table("coordinates/1695_outline.txt", header = FALSE)
Alignment
imageList_aligned <- alignLan(imageList, landmarkList, transformRef = target, cartoonID = 'm1695', adjustCoords = TRUE, plotTransformed = T, resampleFactor = 3, inverse = F)
Can you give this a try? The folder melanargiatest_main should be your working dir.
Steven
Van Belleghem Steven From: brunacama93 @.> Sent: Tuesday, 7 May 2024 11:59 To: StevenVB12/patternize @.> Cc: Steven M. Van Belleghem @.>; Comment @.> Subject: Re: [StevenVB12/patternize] [rast] extent unknown in alignLan and masking problem (Issue #43)
Hi Steven,
I tried using jpegs before, it doesn't change anything. Here's a few of my files- outline is also found in the coordinates folder https://github.com/brunacama93/melanargiatest
I had to remove a couple of them so the above code needs to be changed to omit 1730 and 1776. I added a modified version to the same repo for convenience.
Thank you for answering so promptly!
— Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/43#issuecomment-2097915884, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC4YSLSGGULDMBQEZC3LZBCQUVAVCNFSM6AAAAABHKSDDIGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJXHEYTKOBYGQ. You are receiving this because you commented.Message ID: @.@.>>
Thank you for getting back to me. I'm still getting the same warnings. While alignLan is creating the image list, if I try to go forward with the workflow, the next part calls for
imgs <- lapply(imageList_aligned, brick_to_array)
names(imgs) <- names(imageList_aligned)
# save raster extents for later conversion:
extent_list <- lapply(imageList_aligned, raster::extent)
for (i in 1:length(imgs)) {
rc <- recolorize(imgs[[i]], method = "k", n = 3, plotting = FALSE)
plotColorPalette(rc$centers)
}
in the imgs object, imgs[[1]] correctly returns the full matrix for 1695, the reference individual, and it is possible to recolorize it with k3 colours. The other 3 individuals' matrices however have several "NaN"s which stop the loop. Do you see this as well? I assume this may be because with the image being warped some of the coordinates become out of bounds relative to 1695?
This may be resolved if I managed to mask out the background, for which I add maskOutline=mask to alignLan
imageList_aligned <- alignLan(imageList, landmarkList, transformRef = target,
cartoonID = 'm1695',
adjustCoords = TRUE,
plotTransformed = T,
resampleFactor = 3,
maskOutline = mask,
inverse = F)
But doing so leads to the second part of the issue, which is that maskOutline returns only a black rectangle for each specimen, with the relative matrices being just 0s.
It's encouraging that recolorize at least works on the first one!
Aha, something is wrong with your landmarks and coordinates. They should not be decimals, but pixel coordinates. To get these, I personally use ImageJ > export XY coordinates.
Steven
Van Belleghem Steven From: brunacama93 @.> Sent: Tuesday, 7 May 2024 14:08 To: StevenVB12/patternize @.> Cc: Steven M. Van Belleghem @.>; Comment @.> Subject: Re: [StevenVB12/patternize] [rast] extent unknown in alignLan and masking problem (Issue #43)
Thank you for getting back to me. I'm still getting the same warnings. While alignLan is creating the image list, if I try to go forward with the workflow, the next part calls for
imgs <- lapply(imageList_aligned, brick_to_array)
names(imgs) <- names(imageList_aligned)
save raster extents for later conversion:
extent_list <- lapply(imageList_aligned, raster::extent)
for (i in 1:length(imgs)) {
rc <- recolorize(imgs[[i]], method = "k", n = 3, plotting = FALSE)
plotColorPalette(rc$centers)
}
in the imgs object, imgs[[1]] correctly returns the full matrix for 1695, the reference individual, and it is possible to recolorize it with k3 colours. The other 3 individuals' matrices however have several "NaN"s which stop the loop. Do you see this as well? I assume this may be because with the image being warped some of the coordinates become out of bounds relative to 1695?
This may be resolved if I managed to mask out the background, for which I add maskOutline=mask to alignLan
imageList_aligned <- alignLan(imageList, landmarkList, transformRef = target,
cartoonID = 'm1695',
adjustCoords = TRUE,
plotTransformed = T,
resampleFactor = 3,
maskOutline = mask,
inverse = F)
But doing so leads to the second part of the issue, which is that maskOutline returns only a black rectangle for each specimen, with the relative matrices being just 0s.
maskoutline.issue.example.png (view on web)https://github.com/StevenVB12/patternize/assets/101118577/583fdc71-222f-452e-8d01-bf0f0a200e38
It's encouraging that recolorize at least works on the first one!
— Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/43#issuecomment-2098255414, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC45SH3PIHSZP6NFXRG3ZBC73LAVCNFSM6AAAAABHKSDDIGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJYGI2TKNBRGQ. You are receiving this because you commented.Message ID: @.@.>>
Oh my god. That's how I had been saving my XY coordinates all along, but turns out that decimal format is what it defaults to when working with .tif files. So, I redid all my landmarks on the .jpgs and now the whole workflow works great. Thank you so much!
Awesome! Let me know if anything else pops up!
Steven
Van Belleghem Steven From: brunacama93 @.> Sent: Tuesday, 7 May 2024 15:51 To: StevenVB12/patternize @.> Cc: Steven M. Van Belleghem @.>; Comment @.> Subject: Re: [StevenVB12/patternize] [rast] extent unknown in alignLan and masking problem (Issue #43)
Oh my god. That's how I had been saving my XY coordinates all along, but turns out that decimal format is what it defaults to when working with .tif files. So, I redid all my landmarks on the .jpgs and now the whole workflow works great. Thank you so much!
— Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/43#issuecomment-2098460548, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC47Y2UKVPD6V6IR3N4LZBDL5ZAVCNFSM6AAAAABHKSDDIGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJYGQ3DANJUHA. You are receiving this because you commented.Message ID: @.@.>>