Azzera filtri
Azzera filtri

why am I getting an error for this tutorial when adapted to my image? how can I fix this error:

2 visualizzazioni (ultimi 30 giorni)
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
% imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
lab_fabric = rgb2lab('image.tif');
a = lab_fabric(:,:,2);
b = lab_fabric(:,:,3);
color_markers = zeros([nColors, 2]);
for count = 1:nColors
color_markers(count,1) = mean2(a(sample_regions(:,:,count)));
color_markers(count,2) = mean2(b(sample_regions(:,:,count)));
end
color_labels = 0:nColors-1;
a = double(a);
b = double(b);
distance = zeros([size(a), nColors]);
for count = 1:nColors
distance(:,:,count) = ( (a - color_markers(count,1)).^2 + ...
(b - color_markers(count,2)).^2 ).^0.5;
end
[~,label] = min(distance,[],3);
label = color_labels(label);
clear distance;
rgb_label = repmat(label,[1 1 3]);
segmented_images = zeros([size(fabric), nColors],'uint8');
for count = 1:nColors
color = fabric;
color(rgb_label ~= color_labels(count)) = 0;
segmented_images(:,:,:,count) = color;
end
montage({segmented_images(:,:,:,2),segmented_images(:,:,:,3) ...
segmented_images(:,:,:,4),segmented_images(:,:,:,5) ...
segmented_images(:,:,:,6),segmented_images(:,:,:,1)});
title("Montage of Red, Green, Purple, Magenta, and Yellow Objects, and Background")
error:
Error using rgb2lab
Expected input number 1, RGB, to be one of these types:
single, double, uint8, uint16
Error in rgb2lab (line 56)
validateattributes(rgb, ...
Error in test (line 7)
lab_fabric = rgb2lab('image.tif');

Risposta accettata

Karim
Karim il 26 Dic 2022
Then you forgot to import the image, start with the imread function to read the image and then call rgb2lab
fabric = imread('fabric.png');
lab_fabric = rgb2lab(fabric);
  1 Commento
Walter Roberson
Walter Roberson il 26 Dic 2022
Very few image related functions accept file names. imread() does if course, and imshow() does as well. I seem to recall that one of the image montage functions accepts file names. Some of the image information functions as well. But for anything other than imread you should always check the documentation to be sure that it accepts file names. It is safer to assume that most functions require that you pass in image data rather than file names.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by