matrix manipulation for color spaces.

6 views (last 30 days)
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 Comments
darova
darova on 19 May 2020
Can you explain more? What size of your image? And what kind of conversion you want?
Malini Bakthavatchalam
Malini Bakthavatchalam on 19 May 2020
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.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 19 May 2020
Edited: Walter Roberson on 19 May 2020
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 Comments
Malini Bakthavatchalam
Malini Bakthavatchalam on 25 May 2020
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
Malini Bakthavatchalam on 25 May 2020
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

Sign in to comment.

More Answers (1)

vecdi
vecdi on 11 Jun 2024
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);

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!