Created
September 1, 2019 04:27
-
-
Save mrifkikurniawan/89ae73c5447b03e64a7e507162cf08a3 to your computer and use it in GitHub Desktop.
Get 3 color channels, RGB, of image, and stack it together to get color image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This source code crop the channel of the image below.

The topmost is blue channel, the middle is green, and the last is red.
concatenated into a stacked colored image like this.
