# Why do I get such different values for R, G and B for very similar photos?

4 views (last 30 days)
Vicente on 29 Jun 2024
Commented: Vicente on 2 Jul 2024
I previously asked this question here. .Since then I have been finding answers little by little to the doubts that have arisen.
In short, I am applying a mask to a series of photos of a sample which is changing color over time. From each of these photos I am measuring the mean R, G and B values within the mask and then transforming them to L, a and b, and finally obtaining the Delta E values between each photo and the first one.
At first, with small samples, everything worked well, and I was able to obtain graphs like the following:
these from samples such as the following:
However, then, using larger samples, I am getting values like the following:
As I said, the only thing I did was to increase the sample size (plus change the time between each photo from about three per second to one per second, and increase the total number of photos by almost 2000).
The origin of the problem seems to be in the measurement of the values of R, G and B, because from these I did the rest of the calculations. For the large sample, where the error occurs, the values of R, G and B go up and down drastically in a strange way from photo 100 to 1800, more or less.
I checked photo 98, 99, 100 and 101 and at first sight they are identical, so the error is not born (apparently) from the analyzed photos.
These are the photos when all start to fail.
I use two codes, the first one (made by Data Analyst, shared by himself in one of the links I put in my first question) to make the mask and verify that it has a correct shape and size. And the second one to apply this mask to each of the photos of the sample and obtain from this process the values of R, G, B, L, a, b and Delta E. Finally, I also use another one to make the graphs. I share them in case you need to see them.
So, what could be going on, why from two very similar photos do you get values for R, G and B that do not make sense, why with the other sample does this error not occur?
It is worth to say that analyzing the photos 100 and 101 (where the delivered data go crazy) in the first code (the one that creates the mask) i get similar values for R, G and B, nothing like the ones delivered by the second code. So it is likely that the error has to do with the precision used for the numbers (and not with the code itself, as it was used for the small sample correctly) in addition to the fact that as the color change is more gradual in this large sample, the values from photo to photo are more similar. If the error arises from here, could you help me to correct it? I tried to make some changes but the error persisted, and I'm not very good at programming without the help of AI (my bad).
Vicente on 1 Jul 2024
Well, I noticed that after running the second code (the one that calculates the values) the variable "baseFileName" ends up in "pruebatiempo_999.png" instead of the 2700 picture.
Then I took a look at the variable "imageFiles" and look:
You were right. You can also see the photos in between that make the graph oscillate.
I add some code to make the function sort the files in imagefiles and then,
I should have stopped to review all the variables. My bad. Bad habits for using AI for program I think, I don't know.
Thank you for pointing out this detail.
DGM on 2 Jul 2024
Oof yeah. I normally try to write numbered files using zero padding to avoid that. At least it's sorted now.

Image Analyst on 30 Jun 2024
It looks like your data for the latter plots is oscillating on an alternating element basis between two curves, hence the "solid" looking plot. Something is happening starting around image #100. It's like every other image is changing brightness.
Presumably the delta E is with respect to the very first image (not between adjacent frames), so upload that first image, plus some images between 1 and 100, and some right around the transition at the end, like around image #1900.
I don't think you're doing calibrated color measurement so the LAB values are just arbitrary (would not agree with spectrophotometer) and if there is a sudden change in illumination, then that would cause a sudden change in the LAB values, even though your sample did not change. I think you should also monitor the mean intensity of the left 30% of the image. Also plot that to make sure there is no change in it.
##### 3 CommentsShow 1 older commentHide 1 older comment
Image Analyst on 2 Jul 2024
@Vicente if you don't see an abrupt change in brightness in the image then there should be no substantial change in the average intensity. It's probably due to incorrect (alphanumeric) sorting of your list of filenames. For example alphanumerically sorted names would go like 1.txt, 10.txt, 11.txt...2.txt, 20.txt, 21.txt and so on. You might like to read this:
or else just use dir() to get the time stamps and sort your filename list by the time stamp.
Vicente on 2 Jul 2024
Yes, there was the error, dir() read the files in an unexpected way.
Thanks for the link, very useful. And for the help too.

### Categories

Find more on Image Arithmetic in Help Center and File Exchange

R2023b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!