Steve on Image Processing with MATLAB

Image processing concepts, algorithms, and MATLAB

Note

Steve on Image Processing with MATLAB has been archived and will not be updated.

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

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")
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^* $) 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^*) $ 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);
tiledlayout("flow")
nexttile
imshow(candy)
 
nexttile
imshow(L,[0 100])
title("L")
 
nexttile
imshow(a,[-90 90])
title("a")
 
nexttile
imshow(b,[-90 90])
title("b")
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")
|
  • print

评论

要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。