Skip to content

Instantly share code, notes, and snippets.

@mrifkikurniawan
Created September 1, 2019 04:27
Show Gist options
  • Save mrifkikurniawan/89ae73c5447b03e64a7e507162cf08a3 to your computer and use it in GitHub Desktop.
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.
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)
@mrifkikurniawan
Copy link
Author

This source code crop the channel of the image below.
The topmost is blue channel, the middle is green, and the last is red.
image

concatenated into a stacked colored image like this.
image2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment