Blue Channel Not Separating from Image

5 visualizzazioni (ultimi 30 giorni)
Kenji il 8 Set 2023
Commentato: Image Analyst il 9 Set 2023
I wrote this code to display only the blue channel of an image and both red and green channels work but the blue channel is unable to produce a result.
image_variable3 = imread('CH0.tif');
blue_channel = image_variable3;
I would get this error message and I don't know what any of it means.
Error using images.internal.imageDisplayValidateParams>validateCData
Multi-plane image inputs must be RGB images of size MxNx3.
Error in images.internal.imageDisplayValidateParams (line 30)
common_args.CData = validateCData(common_args.CData,image_type);
Error in images.internal.imageDisplayParseInputs (line 79)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 253)
Error in Merge (line 46)
I would greatly appreciate any help. Thank!
  6 Commenti
Image Analyst
Image Analyst il 9 Set 2023
@Kenji did you even see any of the answers below? Scroll down.

Accedi per commentare.

Risposte (2)

DGM il 9 Set 2023
Modificato: DGM il 9 Set 2023
If the image contains color content, but is returned as a MxN array when using imread() as shown, then chances are the image is indexed color.
% if it's an indexed color image
% you'll need to read the map with it
[inpict map] = imread('canoe.tif');
% if you want to treat it as RGB, you'll have to convert it
inpict = ind2rgb(inpict,map);
% you can then do whatever manipulations you want in RGB
Bonly = inpict;
Bonly(:,:,1:2) = 0;
If it's something else, then you can attach an example image. Since it's a TIF, you'll have to zip it in order to upload it.

Image Analyst
Image Analyst il 9 Set 2023
Your image is a gray scale image; it is NOT a RGB true color image. There is no blue channel.
You can make your code more robust by doing this:
storedImage = imread('CH0.tif');
size(storedImage) % Echo dimensions to command window.
if ndims(storedImage) == 3
% It's an RGB image. Get the blue channel and store in grayImage.
grayImage = storedImage(:, :, 3);
fprintf('Extracting blue channel of RGB image into variable "grayImage".\n');
elseif ndims(storedImage) == 2
% It's a gray scale image.
fprintf('Stored image is already monochrome (gray scale).\n');
grayImage = storedImage(:, :, 3);
elseif ndims(storedImage) >= 4
% It's a multipage gray scale image.
fprintf('This is a multi-page TIFF image. Decide what to do.\n');
imshow(grayImage, []);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by