Color Imaging - RGB Channels
조회 수: 7(최근 30일)
표시 이전 댓글
%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)

댓글 수: 1
Image Analyst
2021년 4월 1일
편집: Image Analyst
2021년 4월 1일
Same homework problem as this other post
and this one where I put the solution:
답변(2개)
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
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
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)
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!