Blue Channel Not Separating from Image
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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;
blue_channel(:,:,1)=0;
blue_channel(:,:,2)=0;
imshow(blue_channel);
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)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in Merge (line 46)
imshow(blue_channel);
I would greatly appreciate any help. Thank!
6 Kommentare
Stephen23
am 9 Sep. 2023
Bearbeitet: Stephen23
am 9 Sep. 2023
" So by my understandings, in an MxNx3, the 3 indicates a length of 3 layers of red, green, and blue respectively."
Simply knowing the size of the array is not sufficient information to determine the colorspace. Although sRGB might be the most common colorspace, it could be other kinds of RGB (e.g. Adobe RGB), or CIELAB (i.e. Lab), or any of various other 3-channel colorspaces. See for example:
"So since the image is not MxNx3, the image does not contain any blue altogether?"
If it is an indexed image then you need to check its colormap to know if it contains any blue.
"Is there a way to convert a MxN to a MxNx3?"
Of course there are ways to convert to sRGB Truecolor, but you have to know the image format and colorspace first:
Antworten (2)
DGM
am 9 Sep. 2023
Bearbeitet: DGM
am 9 Sep. 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;
imshow(Bonly,'border','tight')
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.
1 Kommentar
Stephen23
am 9 Sep. 2023
You can find a description of indexed images here:
Image Analyst
am 9 Sep. 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');
end
imshow(grayImage, []);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
