Image Conversion and Lab Colourspace range.
    6 views (last 30 days)
  
       Show older comments
    
    Simon Kirkman
 on 21 Aug 2020
  
    
    
    
    
    Commented: Simon Kirkman
 on 28 Aug 2020
            I have two questions about converting images to different colourspaces and performing operations on them. If I have an RGB image and I want to convert it to Lab I can use the rgb2lab function in MATLAB. If I then want to perform operations on the converted image (I am doing colour correction using least squares regression) but when I do this I am getting max Values of 
- L = 149
- a = 214
- b = 255
These values fall outside of the range of the Lab colourspace (l = (0:100) a&b = (-128:127). 
First of all how could I get an empty Lab image without using rgb2lab on the original image which i could then perform operations on. The second question is would if be right to clip the values so they do not go outside the maximum range like when performing operations on rgb images they are clipped at 255 and 0?
My code is as follows.
% creating an Image in Lab to work on
LabCorrectedImage = rgb2lab(colour);
[rows,cols,channels] = size(LabCorrectedImage);
% Modifying L values with least squares regression using constants obtained against a colour chart
    for col = 1:cols
        for row = 1:rows
            redPixel = correctedImage(row, col,1);
            greenPixel = correctedImage(row,col,2);
            bluePixel = correctedImage(row,col,3);
            LabCorrectedImage(rows,col,1) = Alphas(1,1)+ (Alphas(2,1)*redPixel) + (Alphas(3,1)* greenPixel)+(Alphas(4,1)*bluePixel)+(Alphas(5,1)*redPixel^2)+(Alphas(6,1)* greenPixel^2)+ (Alphas(7,1)*bluePixel^2) + (Alphas(8,1)*redPixel*greenPixel) +(Alphas(9,1)*redPixel*bluePixel)+(Alphas(10,1)*greenPixel*bluePixel);        
        end
    end
% Modifying a values with least squares regression using constants obtained against a colour chart
     for col = 1:cols
        for row = 1:rows
            redPixel = correctedImage(row, col,1);
            greenPixel = correctedImage(row,col,2);
            bluePixel = correctedImage(row,col,3);
            LabCorrectedImage(rows,col,2) = Bethas(1,1)+ (Bethas(2,1)*redPixel) + (Bethas(3,1)* greenPixel)+(Bethas(4,1)*bluePixel)+(Bethas(5,1)*redPixel^2)+(Bethas(6,1)* greenPixel^2)+ (Bethas(7,1)*bluePixel^2)+ (Bethas(8,1)*redPixel*greenPixel) +(Bethas(9,1)*redPixel*bluePixel)+(Bethas(10,1)*greenPixel*bluePixel);
        end
     end
% Modifying b values with least squares regression using constants obtained against a colour chart
     for col = 1:cols
         for row = 1:rows
            redPixel = correctedImage(row, col,1);
            greenPixel = correctedImage(row,col,2);
            bluePixel = correctedImage(row,col,3);
            LabCorrectedImage(rows,col,3) = Gammas(1,1)+ (Gammas(2,1)*redPixel) + (Gammas(3,1)* greenPixel)+(Gammas(4,1)*bluePixel)+(Gammas(5,1)*redPixel^2)+(Gammas(6,1)* greenPixel^2)+ (Gammas(7,1)*bluePixel^2)+ (Gammas(8,1)*redPixel*greenPixel) +(Gammas(9,1)*redPixel*bluePixel)+(Gammas(10,1)*greenPixel*bluePixel);
          end
     end
0 Comments
Accepted Answer
  Prabhan Purwar
    
 on 28 Aug 2020
        Hi,
Lab Images are represented in a matrix format of m*n*3, kindly create an empty matrix of the same size to get an empty Image structure. I would suggest going with a color correction method that is suitable for Lab Image representation. Clipping of values may lead to Normalization or data loss.
Hope it helps!!
Thanks.
More Answers (0)
See Also
Categories
				Find more on Color in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
