5

How to use IMSPLIT to split a color image into component images

 2 years ago
source link: https://blogs.mathworks.com/steve/2022/07/14/using-imsplit/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to use IMSPLIT to split a color image into component images » Steve on Image Processing with MATLAB

Today I want to show you a handy little function, imsplit, for splitting color images into their components.
Also, for no reason other than WOW, I want to show one of the images just released by the James Webb Space Telescope program (home page, flickr galleries).
url = "https://live.staticflickr.com/65535/52211883534_7fe30b9955_o_d.png";
rgb = imread(url);
imshow(rgb)
text(size(rgb,2),size(rgb,1),"Image credits: NASA, ESA, CSA, and STScl",...
VerticalAlignment = "top",...
HorizontalAlignment = "right")
imsplit_post_1.png
Anyway, back to imsplit. Long-time readers have seen me use code like this to split up color images (sometimes RGB, sometimes L∗a∗b∗L∗a∗b∗) into component images:
L = lab(:,:,1);
a = lab(:,:,2);
b = lab(:,:,3);
See, for example, the posts about two-dimensional histograms (23-Dec-2010) and segmenting images in (a∗,b∗)(a∗,b∗) space (04-Feb-2011).
That code is not hard to write, but now I've become fond of using imsplit instead, just because it is a bit more compact, without sacrificing understandability. The function imsplit, introduced in release R2018b, is used this way:
url = "https://blogs.mathworks.com/images/steve/2010/mms.jpg";
candy = imread(url);
lab = rgb2lab(candy);
[L,a,b] = imsplit(lab);
nexttile
imshow(candy)
nexttile
imshow(L,[0 100])
title("L")
nexttile
imshow(a,[-90 90])
title("a")
nexttile
imshow(b,[-90 90])
title("b")
tiledlayout("flow")
imsplit_post_2.png
That's it, really. There's nothing more to it. Give it a try the next time you need to do this; it'll save you 2.7183 seconds.
Before I go, let's look at that Webb telescope image one more time, just because.
[R,G,B] = imsplit(rgb);
tiledlayout("flow")
nexttile
imshow(rgb)
nexttile
imshow(R)
title("R")
nexttile
imshow(G)
title("G")
nexttile
imshow(B)
title("B")
imsplit_post_3.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK