이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
matrix manipulation for color spaces.
조회 수: 2 (최근 30일)
이전 댓글 표시
Malini Bakthavatchalam
2020년 5월 19일
Hi , I have an image . I want to convert that to [3 3] matrix value to play with color space. I understand imead will convert image to matrix form but if I want 3 3 matrix, How should I proceed?
댓글 수: 2
darova
2020년 5월 19일
Can you explain more? What size of your image? And what kind of conversion you want?
Malini Bakthavatchalam
2020년 5월 19일
tVersion: ''
Width: 480
Height: 502
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
This is my image size. The image is just a face of a girl. So I want to convert this image in DKL space and work on illusion project.
채택된 답변
Walter Roberson
2020년 5월 19일
편집: Walter Roberson
2020년 5월 19일
You probably do not want a 3 x 3 images. What you probably want is to let T be a 3 x 3 transformation matrix, and RGB be your RGB image, then
M = reshape(RGB, [], 3);
transformed = M * T;
nonRGB = reshape(transformed, size(RGB));
댓글 수: 26
Malini Bakthavatchalam
2020년 5월 19일
Thank you for the answer. Could I use this matrix for working my image on DKL color space?
Malini Bakthavatchalam
2020년 5월 19일
This code shows me error of
Undefined function or variable 'T'.
Error in DKLtry (line 20)
transformed = M * T;
Walter Roberson
2020년 5월 19일
Could I use this matrix for working my image on DKL color space?
Looking at https://github.com/nblauch/dkl_conversion the answer would appear to be NO, that the conversion to DKL is non-linear.
Malini Bakthavatchalam
2020년 5월 19일
Is there a way to work on LMS space ... Because i heard from my colleague DKL is a variant of LMS space? Do You have any opinion about it ?
Malini Bakthavatchalam
2020년 5월 19일
[L; M; S] = [0.3897 0.6890 -0.0787; 0.3897 0.6890 -0.0787; 0.0000 0.0000 1.0000] [x; Y; Z], this is the matrix how can i apply to the image ... https://www.cs.tau.ac.il/~turkel/imagepapers/ColorTransfer.pdf. I read color transfers from this paper but I am confused how do i use it to tranform to images ?
Walter Roberson
2020년 5월 19일
Search for
LMS2DKL<-function(bg,diffcone.coords,DKL2LMS=FALSE){
which is currently line 229 at https://github.com/cran/colorscience/blob/master/R/colorscience.R for R code.
If I read it correctly, this was a conversion from MATLAB source. It looks to me as if that might be related to https://github.com/Psychtoolbox-3/Psychtoolbox-3/blob/master/Psychtoolbox/PsychDemos/DKLDemo.m (authors seem to match)
Walter Roberson
2020년 5월 19일
xYZ2LMS_transform = [0.3897 0.6890 -0.0787; 0.3897 0.6890 -0.0787; 0.0000 0.0000 1.0000];
M = reshape(xYZ, [], 3);
transformed = M * xYZ_LMS_transform;
LMS = reshape(transformed, size(xYZ));
L = LMS(:,:,1);
M = LMS(:,:,2);
S = LMS(:,:,3);
Malini Bakthavatchalam
2020년 5월 20일
It still shows error Undefined function or variable 'xYZ_LMS_transform'.
Error in DKLtry (line 29)
transformed = M * xYZ_LMS_transform;
My code was
RGB = imread('file.jpg');
XYZ = rgb2xyz(RGB);
rgb2xyz([1 1 1])
XYZ_D50 = rgb2xyz(RGB,'WhitePoint','d50');
%Display the first output XYZ image alongside the XYZ image with D50 as reference white.
figure
imshowpair(XYZ,XYZ_D50,'montage');
title('XYZ Image, Without (Left) and With (Right) Reference White');
% xyz = rgb2xyz(RGB);
xYZ2LMS_transform = [0.3897 0.6890 -0.0787;
0.3897 0.6890 -0.0787;
0.0000 0.0000 1.0000];
M = reshape(XYZ, [], 3);
transformed = M * xYZ_LMS_transform;
LMS = reshape(transformed, size(XYZ));
L = LMS(:,:,1);
M = LMS(:,:,2);
S = LMS(:,:,3);
imshowpair(XYZ,M,LMS,L,M,S,'montage')
Walter Roberson
2020년 5월 20일
RGB = imread('file.jpg');
XYZ = rgb2xyz(RGB);
rgb2xyz([1 1 1])
XYZ_D50 = rgb2xyz(RGB,'WhitePoint','d50');
%Display the first output XYZ image alongside the XYZ image with D50 as reference white.
figure
imshowpair(XYZ,XYZ_D50,'montage');
title('XYZ Image, Without (Left) and With (Right) Reference White');
% xyz = rgb2xyz(RGB);
xYZ2LMS_transform = [0.3897 0.6890 -0.0787;
0.3897 0.6890 -0.0787;
0.0000 0.0000 1.0000];
M = reshape(XYZ, [], 3);
transformed = M * xYZ2LMS_transform;
LMS = reshape(transformed, size(XYZ));
L = LMS(:,:,1);
M = LMS(:,:,2);
S = LMS(:,:,3);
imshowpair(XYZ,M,LMS,L,M,S,'montage')
Malini Bakthavatchalam
2020년 5월 20일
It is still showing me error
Error using imfuse>parse_inputs (line 442)
The value of 'method' is invalid. Expected METHOD to match one of these values:
'falsecolor', 'diff', 'blend', 'montage', 'checkerboard'
The input did not match any of the valid values.
Error in imfuse (line 118)
[A,B,RA,RB,method,options] = parse_inputs(varargin{:});
Error in imshowpair (line 107)
[result, R_ref] = imfuse(varargin{:});
Error in DKLtry (line 35)
imshowpair(XYZ,M,LMS,L,M,S,'montage')
Caused by:
Error using validatestring>checkString (line 89)
Expected input to be one of these types:
char, string
Instead its type was double.
Walter Roberson
2020년 5월 20일
RGB = imread('file.jpg');
XYZ = rgb2xyz(RGB);
rgb2xyz([1 1 1])
XYZ_D50 = rgb2xyz(RGB,'WhitePoint','d50');
%Display the first output XYZ image alongside the XYZ image with D50 as reference white.
figure
montage({XYZ, XYZ_D50});
title('XYZ Image, Without (Left) and With (Right) Reference White');
% xyz = rgb2xyz(RGB);
xYZ2LMS_transform = [0.3897 0.6890 -0.0787;
0.3897 0.6890 -0.0787;
0.0000 0.0000 1.0000];
M = reshape(XYZ, [], 3);
transformed = M * xYZ2LMS_transform;
LMS = reshape(transformed, size(XYZ));
L = LMS(:,:,1);
M = LMS(:,:,2);
S = LMS(:,:,3);
montage( {XYZ, LMS, L, M, S} )
But remember that XYZ, LMS, L, M, S are not RGB images, so displaying them might not give an accurate idea of what they represent.
Malini Bakthavatchalam
2020년 5월 20일
편집: Walter Roberson
2020년 5월 20일
Thanks for the help. If I change the image to char and divide the imread by 255 would that be better ...
for ii = 1 : length(picName)
MyImrgb = double(imread([pathName picName{ii}]))/255;
MyImrgb = MyImrgb.^2.2;
[x, y, z] = size(MyImrgb);
% Define a DKL2RGB mat based on the classic calibration technic
% this P matrix defines DKL in RGB color space
% ld % rg %yv
ldrgyv2rgbMat = [1,1,0.236748566577269;
1,-0.299338211934457,-0.235643322285071;
1,0.0137437185685517,1]; % B
MyImrgbCol = reshape(MyImrgb, [x*y, z]);
% define each RGB pixel in DKL (inverse matrix Q or P with \)
MyImldrgyvCol = ldrgyv2rgbMat\(MyImrgbCol'*2 - 1);
Malini Bakthavatchalam
2020년 5월 24일
Thanks for the suggestion. I have a basic doubt, is it ok to use the color conversion available in matlab for some function and matrix trasnformation for rest of the code. for example. In my code, I have used rgb2xyz matlab function, but when i transformed from the paper i used the matrix. is the logic correct?
Malini Bakthavatchalam
2020년 5월 24일
I hve one more basic question as well. How do i convert an image to 3 3 matrix ?
so when I tried this
RGB = imread('file.jpg');
M = reshape(RGB, [],3);
RGB2XYZtranscol = [0.5141 0.3239 0.1604;
0.2651 0.6702 0.0641;
0.0241 0.1228 0.8444]
XYZ_space = RGB.* RGB2XYZtranscol;
Imshowpairwise(RGB,XYZ_space,'montage')
I got this error message.
Error using .*
Integers can only be combined with integers of the same class, or scalar doubles.
Error in dkltry2 (line 21)
XYZ_space = RGB.* RGB2XYZtranscol;
Walter Roberson
2020년 5월 24일
How do i convert an image to 3 3 matrix ?
You do not convert an image to a 3 x 3 matrix.
M = reshape(im2double(RGB), [],3);
XYZ_space = reshape(M * RGB2XYZtranscol, size(RGB));
Malini Bakthavatchalam
2020년 5월 25일
편집: Image Analyst
2020년 5월 25일
What if I use a code im2double(RGBimage)/255? Some of my colleagues suggested this to me, but I did not understand why to divide by 255. What is the explanation for this?
Image Analyst
2020년 5월 25일
You may or may not have to. Check the function. Some, but not all, image processing functions expect floating point images to be in the range of 0-1.
Malini Bakthavatchalam
2020년 5월 25일
Now i changed the color space to XYZ, but to work on the program i have to convert to RGB to project the image in the screen ... so I used reshape(inv(XYZ_space), [], 3), if I apply it, it shows me error inv works only for 2D.. what is the error in my code .. ?
Walter Roberson
2020년 5월 25일
No, im2double() automatically rescales to the range 0 to 1. You would not want to further divide by 255.
double()/255 could be used for something known to be uint8 and definitely never going to be anything other than uint8, but it is safer in the long run to use im2double() as that will automatically do whatever scaling is needed according to the datatype of the image. So if you happened to read in a uint16 image where you thought you were reading in a uint8 image, then im2double() would automatically adjust.
Walter Roberson
2020년 5월 25일
You would not inv() the image. You might want to
reshape(reshape(XYZ_space, [], 3) * inv(RGB2XYZtranscol), size(XYZ_space))
Malini Bakthavatchalam
2020년 5월 25일
Yes, thank you I got your point, so I wrote my final code for converting into DKL color space back into RGB..
clear all
close all
clc
RGB = imread('file.jpg')
MyImrgb = reshape(im2double(RGB), [],3);
Imrgb = MyImrgb.^2.2; %gamma correction
[x, y, z] = size(Imrgb);
ldrgyv2rgbMat = [1,1,0.236748566577269;
1,-0.299338211934457,-0.235643322285071;
1,0.0137437185685517,1]; % B (mat based on the classic calibration technic)
MyImrgbCol = reshape(Imrgb, [x*y, z]);
MyImldrgyvCol = ldrgyv2rgbMat\(MyImrgbCol'*2 - 1);
figure(1), imshow(RGB)
figure(2), imshow(MyImldrgyvCol)
But i get error
Error using \
Matrix dimensions must agree.
Error in dkltry2 (line 12)
MyImldrgyvCol = ldrgyv2rgbMat\(MyImrgbCol'*2 - 1);
Malini Bakthavatchalam
2020년 5월 25일
Also, I have one more doubt, I used an color thresholder to remove my background. and I used that image in the color space transformation. but now when I use my complete code for the project, it is still calculating my histogram with background so how can i solve the issue.. I am attaching my complete code here
추가 답변 (1개)
vecdi
2024년 6월 11일
RGB = imread('file.jpg')
MyImrgb = reshape(im2double(RGB), [],3);
Imrgb = MyImrgb.^2.2; %gamma correction
[x, y, z] = size(Imrgb);
ldrgyv2rgbMat = [1,1,0.236748566577269;
1,-0.299338211934457,-0.235643322285071;
1,0.0137437185685517,1]; % B (mat based on the classic calibration technic)
MyImrgbCol = reshape(Imrgb, [x*y, z]);
MyImldrgyvCol = ldrgyv2rgbMat\(MyImrgbCol'*2 - 1);
figure(1), imshow(RGB)
figure(2), imshow(MyImldrgyvCol)
But i get error
Error using \
Matrix dimensions must agree.
Error in dkltry2 (line 12)
MyImldrgyvCol = ldrgyv2rgbMat\(MyImrgbCol'*2 - 1);
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)