Skip to content

Instantly share code, notes, and snippets.

@Graciaira
Forked from mrifkikurniawan/color_imaging.m
Created May 14, 2020 14:50
Show Gist options
  • Save Graciaira/ed61b458660eac0deca7536d9cf98a70 to your computer and use it in GitHub Desktop.
Save Graciaira/ed61b458660eac0deca7536d9cf98a70 to your computer and use it in GitHub Desktop.
Get 3 color channels, RGB, of image, and stack it together to get color image.
clear all;
%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-1]);
G=imcrop(img,[1,1*rr+1,c,rr-1]);
R=imcrop(img,[1,2*rr+1,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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment