Image Conversion and Lab Colourspace range.
显示 更早的评论
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 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Color 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!