Color Imaging - RGB Channels

2 ビュー (過去 30 日間)
Utkarsh Srivastava
Utkarsh Srivastava 2020 年 10 月 28 日
コメント済み: DGM 2024 年 1 月 1 日
%Read the image
img = imread('image.jpg');
%Get the size (rows and columns) of the image
[r,c] = size(img);
rr=r/3;
%Wrire code to split the image into three equal parts and store them in B, G, R channels
B=imcrop(img,[1,1,c,rr]);
G=imcrop(img,[1,1*rr,c,rr]);
R=imcrop(img,[1,2*rr,c,rr]);
%concatenate R,G,B channels and assign the RGB image to ColorImg variable
ColorImg(:,:,1) = R;
ColorImg(:,:,2) = G;
ColorImg(:,:,3) = B;
imshow(ColorImg)
  2 件のコメント
Image Analyst
Image Analyst 2021 年 4 月 1 日
編集済み: Image Analyst 2021 年 4 月 1 日
DGM
DGM 2024 年 1 月 1 日

サインインしてコメントする。

回答 (2 件)

ANTO OVID G S
ANTO OVID G S 2021 年 4 月 1 日
%Read the image
img = imread('image.jpg');
%Get the size (rows and columns) of the image
[r,c] = size(img);
rr=r/3;
%Wrire code to split the image into three equal parts and store them in B, G, R channels
B = img(1 : r / 3, :, :);
G = img(r / 3 + 1 : 2 * r / 3, :, :);
R = img(2 * r / 3 + 1 : r, :, :);
% Concatenate R,G,B channels and assign the RGB image to ColorImg variable
ColorImg(:,:,1) = R;
ColorImg(:,:,2) = G;
ColorImg(:,:,3) = B;
imshow(ColorImg)
  2 件のコメント
Zakariye Mohamud
Zakariye Mohamud 2022 年 11 月 12 日
thanks it worked me...
Much Thankful for your Work .. Anto Ovid
DGM
DGM 2022 年 11 月 12 日
編集済み: DGM 2022 年 11 月 12 日
Note that this will only work if the copy of the source image is 2D. Some copies of this image are not. Just because an image looks gray does not mean it's not an RGB image.
  • misuse of scalar output syntax for size() will break if array is not 2D
  • presumptive output assignment will break if array is not 2D
  • rr is calculated but never used
  • array indexing blindly uses fractional subscripts
  • output image is constructed by array growing

サインインしてコメントする。


DGM
DGM 2022 年 11 月 12 日
I know this is homework and that actually trying to make the result not look like garbage is well beyond the scope of the assignment. That said, it's not my homework, so I'm not limited by those expectations.
I'm going to just blindly throw this to the Image Registration App and see what it can do. I don't have CVT, so I'm stuck trying to do this in-browser here. I'm sure it can be registered better, but the results are fair for a remarkably lazy attempt.
% read the image
inpict = imread('image.jpeg'); % a gray or RGB image
inpict = im2gray(inpict); % force the image to be gray
inpict = imcrop(inpict,[21 22 365 991]); % crop off excess
% detile the image
[h,w,~] = size(inpict);
h = 3*floor(h/3);
inpict = reshape(inpict(1:h,:).',w,[],3);
inpict = permute(inpict,[2 1 3]);
[B G R] = imsplit(inpict);
% show naive concatenation of R G B channels
imshow(cat(3,R,G,B))
% apply estimated registration for R and B channels
% these come from the Image Registration Estimator app that comes with IPT
% but maddeningly enough, it actually requires CVT to use the files it creates
Sbg = registerImages_BG(B,G);
Srg = registerImages_RG(R,G);
% show attempted automated registration
outpict = cat(3,Srg.RegisteredImage,G,Sbg.RegisteredImage);
imshow(outpict)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by