patternize
patternize copied to clipboard
Problems with .TPS files in colorChecker and alignLan functions
Hello Steven, First, I would like to thank you this useful package.
I am writing because I have some issues when using landmarks in .TPS format in patternize with functions ‘colorChecher’ and ‘alignLan’. I generated TPS files using tpsUtil and tpsDig software for a trial sample of 10 images.
With ‘colorChecker’ function, I used the code below:
colorcheckerXY <- makeList (IDlist, type = 'landmark', prepath = prepath, extension = ".TPS", format = 'tps', tpsFile = "corrected_images/lm-colorchecker.TPS") extension <- ".jpg" colorChecker(IDlist, prepath = NULL, extension = extension, colorCheckerType = "X-Rite", fixedCorners = TRUE, patchSize = 0.6, colorCheckerXY = colorcheckerXY)
This perfectly worked, but when I check the calibrated images, I found that only the first one is calibrated properly, and the remaining ones present some weird calibration patterns. They looked as if the colorchecker corners are not well-positioned within those images.
Similarly, when I used ‘aligLan’ function to align images and mask background and no-interest structures using the following code:
landmarkList <- makeList(IDlist, type = "landmark", prepath = dir("corrected_images/", ".TPS"), extension = ".TPS", format="tps", tpsFile = "corrected_images/alignment_landmarks.TPS") imageList_aligned <- alignLan (imageList, landmarkList, transformRef = target, adjustCoords = TRUE, plotTransformed = T, resampleFactor = 5, cartoonID = 'BRA20_resized_calibrated', maskOutline = mask1, inverse =FALSE)
The resulting images are not aligned correctly. The reference image is "BRA20_resizes_calibrated":
As you can see, only the reference image is well aligned. I guess that, as occurred in calibration, only one configuration of landmarks is being considered.
Conversely, when I use landmarks .txt files generated using ImageJ everything looks fine, both calibration and alignment of images. Obviously, I can use ImageJ for further analysis, but I found tpsDig easier when working with large amounts of images and I was wondering if I was doing something wrong or if I have missed something.
I would really appreciate any comment or suggestion, Thank you!
Lucía
Dear Lucia,
I don’t often work with tps format, so it might well be an error on my part. Would you mind sharing in a google drive or dorpbox (with @.@.>) with some of the images, and all files needed to generate your problem? I will have a look.
Best wishes,
Steven
From: AlarconRios @.> Sent: Friday, 13 January 2023 18:34 To: StevenVB12/patternize @.> Cc: Subscribed @.***> Subject: [StevenVB12/patternize] Problems with .TPS files in colorChecker and alignLan functions (Issue #36)
Hello Steven, First, I would like to thank you this useful package.
I am writing because I have some issues when using landmarks in .TPS format in patternize with functions ‘colorChecher’ and ‘alignLan’. I generated TPS files using tpsUtil and tpsDig software for a trial sample of 10 images.
With ‘colorChecker’ function, I used the code below:
colorcheckerXY <- makeList (IDlist, type = 'landmark', prepath = prepath, extension = ".TPS", format = 'tps', tpsFile = "corrected_images/lm-colorchecker.TPS") extension <- ".jpg" colorChecker(IDlist, prepath = NULL, extension = extension, colorCheckerType = "X-Rite", fixedCorners = TRUE, patchSize = 0.6, colorCheckerXY = colorcheckerXY)
This perfectly worked, but when I check the calibrated images, I found that only the first one is calibrated properly, and the remaining ones present some weird calibration patterns. They looked as if the colorchecker corners are not well-positioned within those images.
Similarly, when I used ‘aligLan’ function to align images and mask background and no-interest structures using the following code:
landmarkList <- makeList(IDlist, type = "landmark", prepath = dir("corrected_images/", ".TPS"), extension = ".TPS", format="tps", tpsFile = "corrected_images/alignment_landmarks.TPS") imageList_aligned <- alignLan (imageList, landmarkList, transformRef = target, adjustCoords = TRUE, plotTransformed = T, resampleFactor = 5, cartoonID = 'BRA20_resized_calibrated', maskOutline = mask1, inverse =FALSE)
The resulting images are not aligned correctly. The reference image is "BRA20_resizes_calibrated":
[polygon-mask-TPS-alingment-output]https://user-images.githubusercontent.com/12897158/212382490-0fa55bf9-4115-49a4-99cf-ffebae696044.png
As you can see, only the reference image is well aligned. I guess that, as occurred in calibration, only one configuration of landmarks is being considered.
Conversely, when I use landmarks .txt files generated using ImageJ everything looks fine, both calibration and alignment of images. Obviously, I can use ImageJ for further analysis, but I found tpsDig easier when working with large amounts of images and I was wondering if I was doing something wrong or if I have missed something.
I would really appreciate any comment or suggestion, Thank you!
Lucía
— Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/36, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC42QUPF2TUCOZMUPVQTWSGGZLANCNFSM6AAAAAAT2UXVAA. You are receiving this because you are subscribed to this thread.Message ID: @.@.>>
Hello Steven, thank you for your response. I attach a file with all the documents needed. This folder have two subfolders, one for the colorChecker function and one for the alignLan function, in case you want to have a look to both of them:
- ‘colorChecker function’ folder includes: o No calibrated images (with _resized suffix) o Landmarks in TPS format o Landmarks from ImageJ (_cclm.txt suffix)
- ‘alignLan function’ folder includes: o Calibrated images (with _resized_calibrated suffix) o Landmarks (16 landmarks) for each individual from ImageJ (_landmarks.txt suffix) o Landmarks in TPS format o Outline file (BRA20_polygon_mask.txt)
Please, let me know whether I forgot something that you may need. Thank you for your help
Best, Lucía
Hi Lucia,
This was a confusing error. It seems like the orientation and order of your TPS landmarks was different (flipped along the y axis and starting at the white corner). These lines of code should fix it:
colorcheckerXY <- makeList (IDlist, type = 'landmark', prepath = prepath, extension = "_resized_cdm.txt", format = 'tps', tpsFile = "lm-colorchecker.TPS")
colorcheckerXY <- makeList (IDlist, type = 'landmark', prepath = NULL, extension = "_resized_cclm.txt")
imageList <- makeList(IDlist, type = 'image', prepath = prepath, extension = '_resized.jpg')
fixTPS <- function(IDlist, imageList, landList){
for(n in 1:length(IDlist)){
ID <- IDlist[n]
im <- imageList[[ID]]
extPicture <- raster::extent(im)
landList[[ID]][,2] <- extPicture[4] - landList[[ID]][,2]
landList[[ID]] <- landList[[ID]][c(4,1,2,3),]
} return(landList) }
colorcheckerXY <- fixTPS(IDlist, imageList, colorcheckerXY)
Let me know how it goes!
Best wishes,
Steven
From: AlarconRios @.> Sent: Friday, 13 January 2023 18:34 To: StevenVB12/patternize @.> Cc: Subscribed @.***> Subject: [StevenVB12/patternize] Problems with .TPS files in colorChecker and alignLan functions (Issue #36)
Hello Steven, First, I would like to thank you this useful package.
I am writing because I have some issues when using landmarks in .TPS format in patternize with functions ‘colorChecher’ and ‘alignLan’. I generated TPS files using tpsUtil and tpsDig software for a trial sample of 10 images.
With ‘colorChecker’ function, I used the code below:
colorcheckerXY <- makeList (IDlist, type = 'landmark', prepath = prepath, extension = ".TPS", format = 'tps', tpsFile = "corrected_images/lm-colorchecker.TPS") extension <- ".jpg" colorChecker(IDlist, prepath = NULL, extension = extension, colorCheckerType = "X-Rite", fixedCorners = TRUE, patchSize = 0.6, colorCheckerXY = colorcheckerXY)
This perfectly worked, but when I check the calibrated images, I found that only the first one is calibrated properly, and the remaining ones present some weird calibration patterns. They looked as if the colorchecker corners are not well-positioned within those images.
Similarly, when I used ‘aligLan’ function to align images and mask background and no-interest structures using the following code:
landmarkList <- makeList(IDlist, type = "landmark", prepath = dir("corrected_images/", ".TPS"), extension = ".TPS", format="tps", tpsFile = "corrected_images/alignment_landmarks.TPS") imageList_aligned <- alignLan (imageList, landmarkList, transformRef = target, adjustCoords = TRUE, plotTransformed = T, resampleFactor = 5, cartoonID = 'BRA20_resized_calibrated', maskOutline = mask1, inverse =FALSE)
The resulting images are not aligned correctly. The reference image is "BRA20_resizes_calibrated":
[polygon-mask-TPS-alingment-output]https://user-images.githubusercontent.com/12897158/212382490-0fa55bf9-4115-49a4-99cf-ffebae696044.png
As you can see, only the reference image is well aligned. I guess that, as occurred in calibration, only one configuration of landmarks is being considered.
Conversely, when I use landmarks .txt files generated using ImageJ everything looks fine, both calibration and alignment of images. Obviously, I can use ImageJ for further analysis, but I found tpsDig easier when working with large amounts of images and I was wondering if I was doing something wrong or if I have missed something.
I would really appreciate any comment or suggestion, Thank you!
Lucía
— Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/36, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC42QUPF2TUCOZMUPVQTWSGGZLANCNFSM6AAAAAAT2UXVAA. You are receiving this because you are subscribed to this thread.Message ID: @.@.>>
Hello Steven, thank you very much for your response and your help.
First, I should apologize because you were right… the TPS that I sent you had landmarks in a different configuration that the one required by the function (1: brown, 2:cyan, 3:black, 4:white). It was because I made several trials changing landmarks order before posting my question here, and I sent the incorrect TPS file for colour calibration. Sorry for the difficulties that it probably caused.
Again on the issue with ‘colorChecker’ function, when I applied the code you sent, colour calibration perfectly worked. Just highlight that I avoided running lines 3-4 from the code you sent:
colorcheckerXY <- makeList (IDlist, type = 'landmark', prepath = NULL, extension = "resized_cclm.txt")
because, if I run them, landmarks in ImageJ format (one .txt file per image) were imported and replaced those imported from the TPS file.
Also, when I use the TPS with the landmarks well-positioned (and change the order of landmarks within the code of ‘fixTPS’ function to landList[[ID]][c(1,2,3,4),] ) it perfectly worked!. As well as when applying fixTPS before function ‘alignLan’, the problem is solved.
Again, thank you for your help. Best, Lucía