StevenVB12 / patternize

An R package for quantifying color pattern variation
30 stars 8 forks source link

Issue with RGB range #22

Open stevenyuser opened 3 years ago

stevenyuser commented 3 years ago

Hello Steven,

I have been trying to use Patternize to see color pattern variation on test models with paint on them. Basically, I want to see how many pixels of red paint each model has on each image and how they differ.

However, it seems like Patternize cannot detect the color difference between the skin and the paint pixels on the model.

When I run patLanRGB, it returns "The RGB range does not seem to overlap with any of the RGB values in the image (image)" no matter what I do.

I have downloaded the newest version of Patternize through GitHub and seems like everything else is working, any idea what is wrong? Perhaps the image colors are too similar? Anyways, any help would be very much appreciated.

Here is the link to my project, with the script and specified images.

I am a high school student who is intermediate with R, so if you see any flaws, it would be appreciated.

Best Regards, Steven

StevenVB12 commented 3 years ago

Hi Steven!

Thanks for reaching out with your problem. I’m curious what those models are used for..

First thing I notice is that colOffset should be a proportion (which will be multiplied by 255 (the color space)) and can’t be larger than 1. The difference between red and background seems quite narrow (not as easy as butterfly wings). I would suggest you to try a range of values (maybe something like 0.05, 0.1 and 0.15) to see if the extraction matches your expectation. With sampleRGB() you can also try picking a few different red pixels.

Another little trick is to set your target to a fixed sample. Now you have target = ‘LabA3’, which is fine, but it has to be included in the imageList to work and that might not be the case when you want to run the analysis for another set of models.

Finally, when everything runs fine, you can choose to set resampleFactor = 1. This will take longer but keep the highest resolution.

target <- imageList[‘LabA3’]

rasterList_lanRGB <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 3,
                               colOffset = 0.1, crop = TRUE, res = 300, adjustCoords = TRUE, plot = 'stack')

Hope this helps and I look forward to more questions.

Best,

Steven

From: @.> Sent: Thursday, June 17, 2021 11:50 PM To: @.> Cc: @.***> Subject: [StevenVB12/patternize] Issue with RGB range (#22)

Hello Steven,

I have been trying to use Patternize to see color pattern variation on test models with paint on them. Basically, I want to see how many pixels of red paint each model has on each image and how they differ.

However, it seems like Patternize cannot detect the color difference between the skin and the paint pixels on the model.

When I run patLanRGB, it returns "The RGB range does not seem to overlap with any of the RGB values in the image (image)" no matter what I do.

I have downloaded the newest version of Patternize through GitHub and seems like everything else is working, any idea what is wrong? Perhaps the image colors are too similar? Anyways, any help would be very much appreciated.

Here is the link to my project, with the script and specified images. https://github.com/stevenyuser/eyewearparticles

I am a high school student who is intermediate with R, so if you see any flaws, it would be appreciated.

Best Regards, Steven

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC4YRBFGOF7CJRHHUWUTTTK7AXANCNFSM4643WGSA.

stevenyuser commented 3 years ago

Hi Steven,

Thanks for the quick response!

Currently, I'm doing a research project to see which types of eyewear provide the best protection to the wearer. We used paint aerosols and different types of eyewear. We used red paint, so probably not the best decision there. I can keep you updated on the project if you want :)

I have tried changing colOffset as you suggested, but it still doesn't work. I have tried the range of values (0.05, 0.1, 0.15, etc.) and all of them give me the same result, a blank plot and this message:

"The RGB range does not seem to overlap with any of the RGB values in the image LabA3"

I think there's some issue because I specifically chose the RGB value from the image LabA3 and it didn't work either. (Used color picker in Photoshop)

I have also tried using the sampleRGB() function for my image. However, it returns this error message:

Error in rgb(t(x[, , 1L]), t(x[, , 2L]), t(x[, , 3L]), maxColorValue = max) : color intensity 23008, not in 0:255

Here's the code I used: image <- raster::stack("C:/Users/steve/Documents/eyewearanalysis/images/Edit1_Enhanced/LabA3.png") RGB <- sampleRGB(image, resampleFactor = 1)

I also tried setting my target to the fixed sample, but when I tried running it, it give me an error message again.

Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'raster': error in evaluating the argument 'x' in selecting a method for function 'extent': object 'refShape' not found

Code I used: target <- imageList['LabA3']

rasterList_lanRGB <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 1, 
                               colOffset = 0.01, crop = TRUE, res = 300, adjustCoords = TRUE, plot = 'stack')

Here's the new link to the updated GitHub project with all my code and comments. (Old one had some issues with my computer) I have added comments detailing the error messages, so you can look at it or run the code yourself.

Many thanks, Steven

StevenVB12 commented 3 years ago

Hi Steven,

Can you try converting your .png images to .jpg (and make sure to check whether your landmarks still match)? I didn’t notice it before, but patternize uses .jpg format.

Sounds like a cool project. I hope it works out with patternize tool!

Best,

Steven

From: @.> Sent: Friday, June 18, 2021 6:26 PM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Hi Steven,

Thanks for the quick response!

Currently, I'm doing a research project to see which types of eyewear provide the best protection to the wearer. We used paint aerosols and different types of eyewear. We used red paint, so probably not the best decision there. I can keep you updated on the project if you want :)

I have tried changing colOffset as you suggested, but it still doesn't work. I have tried the range of values (0.05, 0.1, 0.15, etc.) and all of them give me the same result, a blank plot and this message:

"The RGB range does not seem to overlap with any of the RGB values in the image LabA3"

I think there's some issue because I specifically chose the RGB value from the image LabA3 and it didn't work either. (Used color picker in Photoshop)

I have also tried using the sampleRGB() function for my image. However, it returns this error message:

Error in rgb(t(x[, , 1L]), t(x[, , 2L]), t(x[, , 3L]), maxColorValue = max) : color intensity 23008, not in 0:255

Here's the code I used: image <- raster::stack("C:/Users/steve/Documents/eyewearanalysis/images/Edit1_Enhanced/LabA3.png") RGB <- sampleRGB(image, resampleFactor = 1)

I also tried setting my target to the fixed sample, but when I tried running it, it give me an error message again.

Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'raster': error in evaluating the argument 'x' in selecting a method for function 'extent': object 'refShape' not found

Code I used: target <- imageList['LabA3']

rasterList_lanRGB <- patLanRGB(imageList, landmarkList, RGB, transformRef = target, resampleFactor = 1,

                           colOffset = 0.01, crop = TRUE, res = 300, adjustCoords = TRUE, plot = 'stack')

Here's the new link to the updated GitHub project with all my code and comments. (Old one had some issues with my computer)https://github.com/stevenyuser/eyewearanalysis I have added comments detailing the error messages, so you can look at it or run the code yourself.

Many thanks, Steven

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-864302106, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC47IZI4IQHRPNLBTQXTTTPBZJANCNFSM4643WGSA.

stevenyuser commented 3 years ago

Hi Steven,

Thanks, the main issue is solved after I converted the images to .jpg! image

However, I have another question. Since I need to publish a paper on this, I need to have numbers. I would like to see the percentage of color (which represents droplets) variation between different images (which represents different eyewear protection), to determine which eyewear gives the best protection (least red color droplets). I am a bit confused about which functions I should use for this task, should I use patArea()? Is there any way I can get the specific numbers/percentages? I know I can graph it with patArea(), it would be helpful if I could also get the exact numbers.

StevenVB12 commented 3 years ago

Hey Steven,

patArea() will give you the percentage of pixels with color droplets relative to an outline you would have to draw. If you know the size of that outline, you could convert the percentage to an absolute area (note that these numbers will be scaled to the target image you aligned your images to).

Does this answer your question?

Steven

From: @.> Sent: Friday, June 25, 2021 12:12 AM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Hi Steven,

Thanks, the main issue is solved after I converted the images to .jpg! [image]https://user-images.githubusercontent.com/77898813/123367074-562b3a80-d547-11eb-94b1-ea1c536e0cef.png

However, I have another question. Since I need to publish a paper on this, I need to have numbers. I would like to see the percentage of color (which represents droplets) variation between different images (which represents different eyewear protection), to determine which eyewear gives the best protection (least red color droplets). I am a bit confused about which functions I should use for this task, should I use patArea()? Is there any way I can get the specific numbers/percentages? I know I can graph it with patArea(), it would be helpful if I could also get the exact numbers.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-868188983, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC44U3QBQBCVG7L6R743TUP6ZHANCNFSM4643WGSA.

stevenyuser commented 3 years ago

Hi Steven,

How would I be able to convert patArea() to an absolute area?

Thanks, Steven

StevenVB12 commented 3 years ago

Hi Steven,

Here’s a workaround..

  1. Do you have a scale in your target image? If not, you could measure something in the original object to know it’s size. For example, the eye.

  2. In imageJ there’s a measure tool that gives you the amount of pixels that are spanned by a line that you draw.

  3. Now you know how many pixels there are in a cm or a cm2.

  4. From patArea you get the pixels. If you didn’t drop the resolution, you should be able to calculate the area from the pixels you have. If you used resamplefactor, you will have to take that into account as well.

Hope this helps!

Steven

From: @.> Sent: Thursday, July 1, 2021 11:42 PM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Hi Steven,

How would I be able to convert patArea() to an absolute area?

Thanks, Steven

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-872689415, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC44VZOPZTFMVVDEVAJLTVUYRFANCNFSM4643WGSA.

stevenyuser commented 3 years ago

Hi Steven,

Great idea! I will contact the person with the mask to find the length of the eye. For patArea(), it only gives me the percentage of the photo that is covered with color, not the raw amount of pixels. Do I just multiply to find it, or is there a way to get the raw number of pixels?

I'm currently working on another thing that I'll ask you about soon.

Thanks so much, Steven

StevenVB12 commented 3 years ago

Oh I forgot. It’s the percentage relative to the area of the outline.

I think you can load the outline into imageJ as well, and get the amount of pixels that are in it. Sorry, it’s been a while since I’ve done this.

Steven

From: @.> Sent: Friday, July 2, 2021 10:11 AM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Hi Steven,

Great idea! I will contact the person with the mask to find the length of the eye. For patArea(), it only gives me the percentage of the photo that is covered with color, not the raw amount of pixels. Do I just multiply to find it, or is there a way to get the raw number of pixels?

I'm currently working on another thing that I'll ask you about soon.

Thanks so much, Steven

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-873029543, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC4447BODH33XDRGRFCLTVXCKDANCNFSM4643WGSA.

stevenyuser commented 3 years ago

Hi Steven,

I have a few more questions.

First, when I aligned my images using patLanRGB() plot looks like this: image I'm not sure why it is like that and if it affects the accuracy of the area. For context, this is what my landmarks look like: image Will this affect the accuracy of the area?

Secondly, does the outline shape matter since I am just getting the absolute area anyways? There isn't really a good way to set an outline for a picture of the eyes of a head.

Third, it seems like the code is a bit janky in my example: code is in repo here Is this normal? Do I need anything else (or am missing anything) to get my results for the number of pixels in area? (I haven't calculated it yet because I run into the above mentioned errors).

StevenVB12 commented 3 years ago

Hey Steven,

  1. I think you can reduce the ‘res’ option a bit, that should remove the white lines a bit. It does look like not all of your images are perfectly aligning. Are you sure all lanmarks are in the same order?

  2. You could indeed just use tha area of your aligned rasters as your reference. Note that patternize crops the images within the space of the landmarks as default. Play with the ‘cropOffset’ to get a bigger area.

  3. What’s the errors you are getting exactly?

Hope this helps!

Steven

From: @.> Sent: Tuesday, September 7, 2021 12:02 AM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Hi Steven,

I have a few more questions.

First, when I aligned my images using patLanRGB() plot looks like this: [image]https://user-images.githubusercontent.com/77898813/132281454-5c57d851-bf85-4dd0-9f36-03c22f084a74.png I'm not sure why it is like that and if it affects the accuracy of the area. For context, this is what my landmarks look like: [image]https://user-images.githubusercontent.com/77898813/132281768-8db48a21-7ac8-4071-8a6d-7f4a0d1793ed.png Will this affect the accuracy of the area?

Secondly, does the outline shape matter since I am just getting the absolute area anyways? There isn't really a good way to set an outline for a picture of the eyes of a head.

Third, it seems like the code is a bit janky in my example: code is in repo herehttps://github.com/stevenyuser/eyewearprotectionanalysis Is this normal? Do I need anything else (or am missing anything) to get my results for the number of pixels in area? (I haven't calculated it yet because I run into the above mentioned errors).

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-913972289, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC4ZYH4HB4PEADMEB63TUAWFEBANCNFSM4643WGSA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

stevenyuser commented 3 years ago

Hi Steven,

  1. I redid my landmarks and it aligns now, thanks!
  2. I didn't really edit the crop/cropOffset and it seems to work fine.
  3. I think I basically solved all of the errors since it seems to work fine now. I get results now, possibly inaccurate, but seems fine. The stable build was pushed to the repo.

I have a few more questions.

I ran my code in eyewearpixelanalysis.R and the plot that is made when patLanRGB is run looks like this: image I suspect this is because I increased the res to 500 and colOffset to 0.05. To produce the most accurate results, what should colOffset be set to? Is there a way I can calculate it or should I just eyeball it? My PatLanRGB looks like that, while my images are these images, does it look like the red color is being extracted properly?

After taking the area of the samples, I get this:

   SampleId        Area
1     LabA3 0.009568471
2     LabB3 0.010089527
3 ReadingA2 0.027331723
4 ReadingB3 0.014447444

After some simple napkin math I got these total pixel areas:

2,378.922828491
2,508.468292267
6,795.240303983
3,591.937974724

In patLanRGB() [transformRef] and patArea() [outline and cartoonID], since I am targeting LabA3 in these instances, will this make my other samples inaccurate. Do I need to make a new script for each of the other samples or is this okay?

Basically, I am unsure if my results are accurate enough. I need to finish this today, so I'm glad that all of the code works at least.

Thank you so much for all of the help! Steven

StevenVB12 commented 3 years ago

Hey Steven,

I think for your case, eyeballing whether the color is extracted well compared to the background is the best option.

Reduce the res to maybe 150, that should make it look better.

See if you can just extract the amount of pixels that have a value of 1 and divide that by the number of pixels the total raster. You wouldn’t need to use the outline or patArea function in this case. Maybe that makes more sense in your case.

Good luck!

Steven

From: @.> Sent: Tuesday, September 7, 2021 4:27 PM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Hi Steven,

  1. I redid my landmarks and it aligns now, thanks!
  2. I didn't really edit the crop/cropOffset and it seems to work fine.
  3. I think I basically solved all of the errors since it seems to work fine now. I get results now, possibly inaccurate, but seems fine. The stable build was pushed to the repo.

I have a few more questions.

I ran my code in eyewearpixelanalysis.R and the plot that is made when patLanRGB is run looks like this: [image]https://user-images.githubusercontent.com/77898813/132404620-ac2e5df7-ece9-4678-bb06-521b2103940e.png I suspect this is because I increased the res to 500 and colOffset to 0.05. To produce the most accurate results, what should colOffset be set to? Is there a way I can calculate it or should I just eyeball it? My PatLanRGB looks like that, while my images are these imageshttps://github.com/stevenyuser/eyewearprotectionanalysis/tree/main/images/edited, does it look like the red color is being extracted properly?

After taking the area of the samples, I get this:

SampleId Area

1 LabA3 0.009568471

2 LabB3 0.010089527

3 ReadingA2 0.027331723

4 ReadingB3 0.014447444

After some simple napkin math I got these total pixel areas:

2,378.922828491

2,508.468292267

6,795.240303983

3,591.937974724

In patLanRGB() [transformRef] and patArea() [outline and cartoonID], since I am targeting LabA3 in these instances, will this make my other samples inaccurate. Do I need to make a new script for each of the other samples or is this okay?

Basically, I am unsure if my results are accurate enough. I need to finish this today, so I'm glad that all of the code works at least.

Thank you so much for all of the help! Steven

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-914608556, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC45CPYRFUIYYP6BQPCDUAZYTTANCNFSM4643WGSA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

stevenyuser commented 3 years ago

Hi,

What do you mean by a pixel with the value of 1?

Thanks

StevenVB12 commented 3 years ago

Pixels that have the color get assigned the value of 1 in the rasterList.

Steven

-------- Original message -------- From: stevenyuser @.> Date: 9/7/21 6:43 PM (GMT-04:00) To: StevenVB12/patternize @.> Cc: "Steven M. Van Belleghem" @.>, Comment @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Hi,

What do you mean by a pixel with the value of 1?

Thanks

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-914673938, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC46GHADZZGVVZHI7Y5DUA2IR5ANCNFSM4643WGSA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

stevenyuser commented 3 years ago

Okay thanks

stevenyuser commented 2 years ago

Hi, everything was working pretty well (I got the results), and was working on trying to implement the method you talked about extracting the values of 1 from the rasterList, but unfortunately, once I updated to R 4.1.1, my code has suddenly stopped working. When I make a raster list with patLanRGB, it adds the samples to the array, but it only works and adds for LabA3 and LabB3, not the rest.

rasterList <- patLanRGB(imageList, landmarkList, RGB, transformRef = 'LabA3', resampleFactor = 1,
                        colOffset = 0.05, crop = TRUE, res = 500, plot = 'stack')

# output:
# ...
[1] "sample LabA3 done and added to rasterList"
[1] "sample LabB3 done and added to rasterList"
Error in if (all(map == FALSE)) { : missing value where TRUE/FALSE needed # doesn't work after this.

Did something possibly break patternize in 4.1.1 or possibly another package installed (I installed tidyverse, but it doesn't work even when I unenable it)?

I think it's because LabC3 (the third sample) has no colored pixels, meaning there's no TRUE value in the raster? This breaks the function, but doesn't explain why it worked before, and changes now. Hopefully, this bug/issue can be fixed in the next update of patternize.

Thank you, Steven Yu

StevenVB12 commented 2 years ago

Hi Steven,

Are you using the GitHub version of patternize. That one should have this issue resolved… If not, I’ll have another look at the code.

Best,

Steven

From: @.> Sent: Wednesday, September 29, 2021 9:48 PM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Hi, everything was working pretty well (I got the results), and was working on trying to implement the method you talked about extracting the values of 1 from the rasterList, but unfortunately, once I updated to R 4.1.1, my code has suddenly stopped working. When I make a raster list with patLanRGB, it adds the samples to the array, but it only works and adds for LabA3 and LabB3, not the rest.

rasterList <- patLanRGB(imageList, landmarkList, RGB, transformRef = 'LabA3', resampleFactor = 1,

                    colOffset = 0.05, crop = TRUE, res = 500, plot = 'stack')

output:

...

[1] "sample LabA3 done and added to rasterList"

[1] "sample LabB3 done and added to rasterList"

Error in if (all(map == FALSE)) { : missing value where TRUE/FALSE needed # doesn't work after this.

Did something possibly break patternize in 4.1.1 or possibly another package installed (I installed tidyverse, but it doesn't work even when I unenable it)?

I think it's because LabC3 (the third sample) has no colored pixels, meaning there's no TRUE value in the raster? This breaks the function, but doesn't explain why it worked before, and changes now. Hopefully, this bug/issue can be fixed in the next update of patternize.

Thank you, Steven Yu

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-930682636, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC442KUQ7WD4NFBJFI6DUEO6VVANCNFSM4643WGSA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

stevenyuser commented 2 years ago

Thank you so much, it works now, forgot to update, sorry!

StevenVB12 commented 2 years ago

Awesome!

Steven

From: @.> Sent: Thursday, September 30, 2021 11:37 AM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Thank you so much, it works now, forgot to update, sorry!

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-931435644, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC453CD7GEX6NDYD3GEDUER7ZZANCNFSM4643WGSA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

stevenyuser commented 2 years ago

Hi StevenVB12,

I've run into another issue.

I am trying to get the area for my 18 samples for 3 sections (left, right, and total). The method I have chosen is to get the outline for each of the 3 sections and then use patArea for each of the three sections of a sample (by subsetting the rasterList) and then add those 3 area sections to a CSV file for each of the 18 samples.

This code works for LabA2 and LabB3 (first and second samples), but fails for LabC3 (and others if I remove LabC3), where it outputs an error of: Error in .intersectExtent(x, y, validate = TRUE) : Objects do not intersect

# First align all the 18 samples
rasterList <- patLanRGB(imageList, landmarkList, RGB, transformRef = 'LabA3', resampleFactor = 1,
                        colOffset = 0.05, crop = TRUE, res = 500, plot = 'stack')

# Then, find the area for the 18 samples for the 3 sections
num <- 1
for(id in IDList) {
  print(id)

  outlineTotal <- read.table(paste('cartoons/outline/', id, '', '.txt', sep = ""), h = F)
  outlineLeft <- read.table(paste('cartoons/outline/', id, '_left', '.txt', sep = ""), h = F)
  outlineRight <- read.table(paste('cartoons/outline/', id, '_right', '.txt', sep = ""), h = F)

  print(outlineTotal)
  print(outlineLeft)
  print(outlineRight)

  areaTotal <- patArea(rasterList[num], id, type = 'RGB', refShape = 'target', outline = outlineTotal, 
                  imageList = imageList, cartoonID = id)
  areaLeft <- patArea(rasterList[num], id, type = 'RGB', refShape = 'target', outline = outlineLeft, 
                       imageList = imageList, cartoonID = id)
  areaRight <- patArea(rasterList[num], id, type = 'RGB', refShape = 'target', outline = outlineRight, 
                       imageList = imageList, cartoonID = id)

  print(areaTotal)
  print(areaLeft)
  print(areaRight)

  num <- num + 1

  print(' ')
}

The full code is here: https://github.com/stevenyuser/eyewearprotectionanalysis

Best regards, Steven Yu

StevenVB12 commented 2 years ago

Hey Steven,

If I get this right, you only need to use the 3 sections from sample LabA3. That is your reference sample and will thus define the coordinate space or extent for all the aligned samples (and thus it is enough to only define the sections for LabA3). The extent of LabC3, for example, might not match with LabA3, resulting in nothing that can be intersected.

Does that make sense?

Steven

From: @.> Sent: Monday, October 11, 2021 5:53 PM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Hi StevenVB12,

I've run into another issue.

I am trying to get the area for my 18 samples for 3 sections (left, right, and total). The method I have chosen is to get the outline for each of the 3 sections and then use patArea for each of the three sections of a sample (by subsetting the rasterList) and then add those 3 area sections to a CSV file for each of the 18 samples.

This code works for LabA2 and LabB3 (first and second samples), but fails for LabC3 (and others if I remove LabC3), where it outputs an error of: Error in .intersectExtent(x, y, validate = TRUE) : Objects do not intersect

First align all the 18 samples

rasterList <- patLanRGB(imageList, landmarkList, RGB, transformRef = 'LabA3', resampleFactor = 1,

                    colOffset = 0.05, crop = TRUE, res = 500, plot = 'stack')

Then, find the area for the 18 samples for the 3 sections

num <- 1

for(id in IDList) {

print(id)

outlineTotal <- read.table(paste('cartoons/outline/', id, '', '.txt', sep = ""), h = F)

outlineLeft <- read.table(paste('cartoons/outline/', id, '_left', '.txt', sep = ""), h = F)

outlineRight <- read.table(paste('cartoons/outline/', id, '_right', '.txt', sep = ""), h = F)

print(outlineTotal)

print(outlineLeft)

print(outlineRight)

areaTotal <- patArea(rasterList[num], id, type = 'RGB', refShape = 'target', outline = outlineTotal,

              imageList = imageList, cartoonID = id)

areaLeft <- patArea(rasterList[num], id, type = 'RGB', refShape = 'target', outline = outlineLeft,

                   imageList = imageList, cartoonID = id)

areaRight <- patArea(rasterList[num], id, type = 'RGB', refShape = 'target', outline = outlineRight,

                   imageList = imageList, cartoonID = id)

print(areaTotal)

print(areaLeft)

print(areaRight)

num <- num + 1

print(' ')

}

The full code is here: https://github.com/stevenyuser/eyewearprotectionanalysis

Best regards, Steven Yu

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-940468672, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC42GG2AJWVSAUGI34ZTUGNMGJANCNFSM4643WGSA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

stevenyuser commented 2 years ago

Hi Steven,

If I am understanding this correctly, I should do patLanRGB() for each sample and then apply the area for each of the three sections of each sample?

Thank you, Steven Yu

StevenVB12 commented 2 years ago

Run patLanRGB() on all samples, so they are transformed/aligned to the target sample. When you have your sections defined for the target sample, you only have to run patArea() once..

Steven

From: @.> Sent: Tuesday, October 12, 2021 12:08 PM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Hi Steven,

If I am understanding this correctly, I should do patLanRGB() for each sample and then apply the area for each of the three sections of each sample?

Thank you, Steven Yu

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-941156189, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC44YJX2RY3M4I6D6CQ3UGRMODANCNFSM4643WGSA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

stevenyuser commented 2 years ago

Hi,

I tried your method of running patLanRGB once on all samples. Then, I got the outlines for sample LabA3 for Total, Left, and Right. Then, I ran areaTotal, areaLeft, and areaRight with the respective outlines. Unfortunately, it seems that only the areaTotal works as intended, as areaLeft is completely 0 (even though ReadingC3 clearly has colored pixels on the left eye) and it's not sensitive enough.

Is it possible for me to get the three sections of the outline for each sample and then run the area for each of the three sections of the samples with the respective outlines to get more accurate numbers? Would I need to run patLanRGB on each individual sample and then run the patArea?

Thank you, Steven Yu

P.S. My code has been pushed to the repo.

StevenVB12 commented 2 years ago

A final check… it could be that your coordinates of the outline are flipped along the y-axis compared to the extracted raster. Can you check that?

Steven

From: @.> Sent: Tuesday, October 12, 2021 9:55 PM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Hi,

I tried your method of running patLanRGB once on all samples. Then, I got the outlines for sample LabA3 for Total, Left, and Right. Then, I ran areaTotal, areaLeft, and areaRight with the respective outlines. Unfortunately, it seems that only the areaTotal works as intended, as areaLeft is completely 0 (even though ReadingC3 clearly has colored pixels on the left eye) and it's not sensitive enough.

Is it possible for me to get the three sections of the outline for each sample and then run the area for each of the three sections of the samples with the respective outlines to get more accurate numbers? Would I need to run patLanRGB on each individual sample and then run the patArea?

Thank you, Steven Yu

P.S. My code has been pushed to the repo.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-941837991, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC45YMJTCVZCFVBJ6G7TUGTRJ5ANCNFSM4643WGSA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

stevenyuser commented 2 years ago

Hi Steven,

I'm sorry, how do I check for that? I checked through the coordinates of the outlines and they all seem similar (left has a smaller x value than right). However, each image has a different scale (different relative xy values). How do I check the raster coordinates?

Thank you, Steven Yu

StevenVB12 commented 2 years ago

Hey Steven,

I had a look at the code. What seemed to have happened is that the outlines get oriented differently in comparison to the rastersStacks. This is fixed with using “flipOutline = ‘y”.

I also noticed your res was set higher than the actual resolution of the images, which results in empty cells in the color extraction.

Maybe you can also further play with the RGB values, as I think in sunC3 you should get more pixels. What you can do is run separate RGB values for different images and combine the extracted rasters into one list afterwards..

Hope this helps!

Steven

From: @.> Sent: Thursday, October 14, 2021 1:44 PM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Hi Steven,

I'm sorry, how do I check for that? I checked through the coordinates of the outlines and they all seem similar (left has a smaller x value than right). However, each image has a different scale (different relative xy values). How do I check the raster coordinates?

Thank you, Steven Yu

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-943580115, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC43WAS6SX3BGJLYYNFTUG4JIVANCNFSM4643WGSA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

stevenyuser commented 2 years ago

Thank you, it seems to work when I did that!

When I wanted to follow your suggestion of playing with the RGB values more, I tried the following code and it kept giving me the error: Error in if (facCol[jj]) { : missing value where TRUE/FALSE needed I've been trying to deal with this for a couple of weeks now, but to no avail... I also used the manual sampleRGB, but it doesn't seem accurate. Basically, my code below just creates an imageList and landmarkList like I do before, but I subset them for each sample. I found the RGB values of each photo and I try to run patLanRGB on each image (with the subsetted imageList and landmarkList), but it keeps on giving me the above error.


# image list
prepath <- 'images/edited'
extension <- '.jpg'
imageList <- makeList(IDList, 'image', prepath, extension)

# landmark list
prepath <- 'landmarks'
extension <- '_landmarks.txt'
landmarkList <- makeList(IDList, 'landmark', prepath, extension)

# RGB values for color segmentation (red)
# Each RGB value is picked from each image in the sample list
rgbList <- list()
rgbList[[1]] <- c(193, 74, 39) # default
rgbList[[2]] <- c(188, 68, 38)
rgbList[[3]] <- c(182, 46, 38)
rgbList[[4]] <- c(167, 76, 50)
rgbList[[5]] <- c(193, 74, 39) # cannot find, will use default
rgbList[[6]] <- c(168, 60, 42)
rgbList[[7]] <- c(190, 74, 39)
rgbList[[8]] <- c(178, 51, 44)
rgbList[[9]] <- c(195, 47, 35)
rgbList[[10]] <- c(193, 74, 39) # cannot find, will use default
rgbList[[11]] <- c(193, 74, 39) # cannot find, will use default
rgbList[[12]] <- c(193, 74, 39) # cannot find, will use default
rgbList[[13]] <- c(189, 58, 39)
rgbList[[14]] <- c(148, 52, 49)
rgbList[[15]] <- c(194, 50, 36)
rgbList[[16]] <- c(172, 60, 51)
rgbList[[17]] <- c(182, 59, 37)
rgbList[[18]] <- c(189, 45, 40)

# align RGB values for each image

num <- 1
rasterList <- list()
for(id in IDList) {
  rasterList[num] <- patLanRGB(sampleList = imageList[num], landList = landmarkList[num], rgbList[[num]],
                                 transformRef = id, resampleFactor = 1, colOffset = 0.05,
                                 crop = TRUE, res = 400, plot = 'stack')
  num <- num + 1
}

Output:

[1] "sample 1 LabA3 added to array"
Error in if (facCol[jj]) { : missing value where TRUE/FALSE needed
StevenVB12 commented 2 years ago

Hmm, does the error tell you the line of code it occurs? (if not, try “traceback()”)

Why are you using a different reference in each loop? I would try using the same reference, e.g. landmarkList[[1]]

Steven

From: @.> Sent: Saturday, October 30, 2021 12:37 PM To: @.> Cc: Steven M. Van @.>; @.> Subject: Re: [StevenVB12/patternize] Issue with RGB range (#22)

Thank you, it seems to work when I did that!

When I wanted to follow your suggestion of playing with the RGB values more, I tried the following code and it kept giving me the error: Error in if (facCol[jj]) { : missing value where TRUE/FALSE needed I've been trying to deal with this for a couple of weeks now, but to no avail... I also used the manual sampleRGB, but it doesn't seem accurate. Basically, my code below just creates an imageList and landmarkList like I do before, but I subset them for each sample. I found the RGB values of each photo and I try to run patLanRGB on each image (with the subsetted imageList and landmarkList), but it keeps on giving me the above error.

image list

prepath <- 'images/edited'

extension <- '.jpg'

imageList <- makeList(IDList, 'image', prepath, extension)

landmark list

prepath <- 'landmarks'

extension <- '_landmarks.txt'

landmarkList <- makeList(IDList, 'landmark', prepath, extension)

RGB values for color segmentation (red)

Each RGB value is picked from each image in the sample list

rgbList <- list()

rgbList[[1]] <- c(193, 74, 39) # default

rgbList[[2]] <- c(188, 68, 38)

rgbList[[3]] <- c(182, 46, 38)

rgbList[[4]] <- c(167, 76, 50)

rgbList[[5]] <- c(193, 74, 39) # cannot find, will use default

rgbList[[6]] <- c(168, 60, 42)

rgbList[[7]] <- c(190, 74, 39)

rgbList[[8]] <- c(178, 51, 44)

rgbList[[9]] <- c(195, 47, 35)

rgbList[[10]] <- c(193, 74, 39) # cannot find, will use default

rgbList[[11]] <- c(193, 74, 39) # cannot find, will use default

rgbList[[12]] <- c(193, 74, 39) # cannot find, will use default

rgbList[[13]] <- c(189, 58, 39)

rgbList[[14]] <- c(148, 52, 49)

rgbList[[15]] <- c(194, 50, 36)

rgbList[[16]] <- c(172, 60, 51)

rgbList[[17]] <- c(182, 59, 37)

rgbList[[18]] <- c(189, 45, 40)

align RGB values for each image

num <- 1

rasterList <- list()

for(id in IDList) {

rasterList[num] <- patLanRGB(sampleList = imageList[num], landList = landmarkList[num], rgbList[[num]],

                             transformRef = id, resampleFactor = 1, colOffset = 0.05,

                             crop = TRUE, res = 400, plot = 'stack')

num <- num + 1

}

Output:

[1] "sample 1 LabA3 added to array"

Error in if (facCol[jj]) { : missing value where TRUE/FALSE needed

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/StevenVB12/patternize/issues/22#issuecomment-955445166, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQOC44SHSNKM3TPV4BFEADUJQNMTANCNFSM4643WGSA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

stevenyuser commented 2 years ago

The error says that the error is in if falCol[jj] {, where there is not a TRUE/FALSE, instead there is a missing value. Here is what traceback() prints:

6: rbind(deparse.level, ...)
5: rbind(x, matrix(0, m + 1, m))
4: Morpho::computeTransform(refShape, as.matrix(lanArray[, , n]), 
       type = transformType)
3: withVisible(...elt(i))
2: capture.output(transMatrix <- Morpho::computeTransform(refShape, 
       as.matrix(lanArray[, , n]), type = transformType))
1: patLanRGB(sampleList = imageList[num], landList = landmarkList[num], 
       rgbList[[num]], transformRef = id, resampleFactor = 1, colOffset = 0.05, 
       crop = TRUE, res = 400, plot = "stack")

As for why I use different references, it's because I want to use the landmarks that match each sample.

Thank you, Steven Yu

stevenyuser commented 2 years ago

I did some testing and it seems even if I don't subset the imageList and landmarkList (make a new one instead in the for loop), it still doesn't work. It seems like if I only do LabA3 it doesn't work, but two samples do work. Is this a possible bug?

Thanks, Steven Yu