box detection/rectangle detection

Hi
Here is my sample image. How to automatically grab/crop/know the region of each colour square without using 'get rect' function?

 Respuesta aceptada

Image Analyst
Image Analyst el 24 de Nov. de 2021

0 votos

There is a function for this: colorChecker()
Attached is a full demo.

5 comentarios

Salad Box
Salad Box el 29 de Nov. de 2021
Thank you so much for sharing this file! Very much appreciated!!
Salad Box
Salad Box el 30 de Nov. de 2021
I just got an additional question.
After colour correction, blue, yellow and black, in particular, still have fairly large delta E (>10 units) compared to the rest of the colour patches. Why is that?
Image Analyst
Image Analyst el 30 de Nov. de 2021
Yes. Several reasons for this. I do calibrated color image analysis all the time, and have for almost 30 years. You might want to take a look at my attached tutorial.
Most of the simple built-in transforms use a 3 by 3 matrix to convert RGB into XYZ like
X = a1 * R + a2 * G + a3 * B
Y = b1 * R + b2 * G + b3 * B
Z = c1 * R + c2 * G + c3 * B
Note that there are no cross terms like R*G, no additive constant, no higher order terms like R^2. Missing those terms will give a worse fit. Plus having only 24 chips from which to train might reduce accuracy, though some papers (Henry Kang) say that having more does not necessarily increase accuracy for non-training colors.
So for a simple transform you might expect delta E's of up to 5 or 10 for traning colors. Using better transforms will get you better results -- if you need it. Sometimes you don't because you just need to get something to do color segmentation and the inaccuracy won't affect the segmentated region that much. However if you need calibrated values, like you need to be able to trace your camera's values back to a claibrated spectrophotometer (the gold standard for color measurement), then you can do better than these simplistic built-in transforms. For example for one of my tests I looked at, I got a min delta E of 0.22 and a max of 7 with the average delta E of 2.4.
Now another problem. MATLAB's formulas assume your image with your chart in it should have sRGB colors.
You can look on Calibrite's web site for the spec or see the attached PDF file.
Note that every chip has nominal sRGB values. If your chart's chips don't have those, you will have a delta E. That's because using the built-in formula is not really calibrated. OK, consider this. Let's say you had the exact exposure to make your chart have the nominal, perfect values to give you a delta E of zero for every chip. Now say that you just cut your exposure time in half so that all the chip colors are half as bright as before. Now the formulas will say that your delta E's are enormous even though your actual scene, chart, and illumination didn't change one bit. All that changed was your exposure time and now you have huge delta E's. How could that be? It's because the formula assume a delta E of zero will be attained only if your chips have the nominal sRGB values, which is not usually the case. Actually never the case unless you synthesize a chart like I did here:
So what can you do? Well if you want calibrated color values, work in LAB color space, not RGB color space. So for each image you develop a new transform to convert RGB into XYZ and then LAB. Since you have known LAB values that don't depend on the exposure (they're intrinsic to the material) the transform will adapt to give you the correct LAB values regardless of the exposure. In super simplistic terms, say you have a transform that worked, and then you cut the exposure by half. Well the new transform would just have coefficients twice as big to make sure you get the same LAB values. (Not exactly - just super simple to help you visualize what's going on.)
Now that you have an LAB image you can usually do all your image analysis in that space. If you really want to get a new RGB image (I never do though), you can transform the calibrated LAB image into sRGB color space (or pretty close) using the "book formulas". Usually this is not necessary but might be desired if, for example, you took images of the same thing with different systems or cameras or lighting and wanted to make all the images look like they were taken on a single, standardized sRGB system because you were going to put them all in a Powerpoint presentation or something.
Sorry, I know your head is spinning now. I teach a course in color science and it's hard to boil down an 8 hour course into a few paragraphs. And color science is hard. No one says it's easy because it's tied up with human physiology. Even the world's color experts that I talk to say it's hard and even they admit they don't know everything. It takes a run-of-the-mill scientist seeing this stuff many, many times over years before it starts to sink it. I mean it was confusing for me when I first started studying it and I have a Ph.D. in optics and have studied radiometry, spectroscopy, etc. before I started with color science. So I feel your pain. Good luck though.
Salad Box
Salad Box el 2 de Dic. de 2021
Thank you! I am taking a deep breath. Colour science seems so hard core and tutorial like this is exactly what I needed.
I am really keen to go for this 8-hour course in colour science taught by you if it can be accessed in any ways?
Please advise.:)
Roger Breton
Roger Breton el 30 de En. de 2024
I tried your "Test.m" code and still got the same error message: "Color patches were not detected."?
% Read in image that has a Color Checker chart in it but that has unknown image capture conditions.
% fileName = 'colorCheckerTestImage.jpg';
fileName = 'CC24 in Scene JPEG.jpg';
rgbImage = imread(fileName);

Iniciar sesión para comentar.

Más respuestas (1)

yanqi liu
yanqi liu el 25 de Nov. de 2021
yes,sir,use Image Analyst suggest method,can get
clc; clear all; close all;
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/812319/image.jpeg';
img = imread(filename);
% use colorChecker
chart = colorChecker(img);
displayChart(chart)
% use measureColor
[colorTable, ccm] = measureColor(chart);
figure;
displayColorPatch(colorTable); set(gcf, 'units','normalized','position',[0,0,1,1])
colorTable
colorTable = 24×9 table
ROI Color Measured_R Measured_G Measured_B Reference_L Reference_a Reference_b Delta_E ___ ________________ __________ __________ __________ ___________ ___________ ___________ _______ 1 {'DarkSkin' } 115 63 42 37.54 14.37 14.92 11.905 2 {'LightSkin' } 248 171 155 64.66 19.27 17.5 15.464 3 {'BlueSky' } 71 109 182 49.32 -3.82 -22.54 22.639 4 {'Foliage' } 54 90 44 43.46 -12.74 22.72 12.144 5 {'BlueFlower' } 133 119 181 54.94 9.61 -24.79 9.0919 6 {'BluishGreen' } 69 193 191 70.48 -32.26 -0.37 9.8937 7 {'Orange' } 247 141 31 62.73 35.83 56.5 14.512 8 {'PurplishBlue'} 68 76 160 39.43 10.75 -45.17 7.7894 9 {'ModerateRed' } 240 84 96 50.57 48.64 16.67 18.741 10 {'Purple' } 73 34 97 30.1 22.54 -20.87 13.951 11 {'YellowGreen' } 154 202 60 71.77 -24.13 58.19 9.0499 12 {'OrangeYellow'} 254 182 19 71.51 18.24 67.37 14.268 13 {'Blue' } 46 52 148 28.37 15.42 -49.8 9.7419 14 {'Green' } 17 166 74 54.38 -39.72 32.27 14.419 15 {'Red' } 221 54 37 42.43 51.05 28.62 26.85 16 {'Yellow' } 253 238 22 81.8 2.67 80.41 17.854

1 comentario

Salad Box
Salad Box el 29 de Nov. de 2021
Thank you so much for confirming and explaning this! Very very useful!!

Iniciar sesión para comentar.

Categorías

Más información sobre Modify Image Colors en Centro de ayuda y File Exchange.

Preguntada:

el 24 de Nov. de 2021

Comentada:

el 30 de En. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by