WHEN I AM RUNNING THIS CODE I AM RECEIVING ERROR IS CASE OF CONVERSION FROM LAB TO RGB. HERE I HAVE WORKED WITH B COMPONENT.HOW CAN I COMBINE 3 CHANNEL AND GER RID OF FROM ERR

5 views (last 30 days)
C = imread('Lena.png');
lab = rgb2lab(C);
L=lab(:,:,3);
A=lab(:,:,1);
B=lab(:,:,2);
%imshow(L);
output_size = max(size(L));
D = 315.25;
dsensor3 = 0.1985;
[F3, sensor_pos3, fan_rot_angles3] = fanbeam(L,D,...
'FanSensorSpacing',dsensor3);
%imshow(F3);
Ifan3 = ifanbeam(F3,D,'FanSensorSpacing',dsensor3,'OutputSize',output_size);
% imshow(Ifan3);
%img_block=blockproc(F3,[4 4],@perdm_fun,'BorderSize',[1 1],'TrimBorder',true);
mat=4*ones(1,90);
newRow = zeros(1,size(F3,2));
newF3 = [F3(1:359, :); newRow; F3(360:end, :)];
H=mat2cell(newF3,mat,mat);
D = 2;
S = 360 ;
X = arrayfun(@(x) S, 1:D,'un',0);
M = zeros(X{:});
p1=mat2cell(M,mat,mat);
p=mat2cell(M,mat,mat);
s=mat2cell(M,mat,mat);
for i=1:90
for j=1:90
celmat=zeros(4);
b=(H{i,j});
[p1{i,j},p{i,j},s{i,j}] = perdm_fun(b);
end
end
finalkey=keygen();
ncell=encypt(p1,s);
modF3=cell2mat(ncell);
IfanmodF3 = ifanbeam(modF3,D,'FanSensorSpacing',dsensor3,'OutputSize',output_size);
%aid=lab([A(:),B(:),IfanmodF3(:)]);
%aid2=lab2rgb(aid);
encyptedLena = lab2rgb(IfanmodF3);%,'ColorSpace','adobe-rgb-1998');
figure,imshow(encyptedLena);
ERROR:
Error using images.color.ColorConverter/convert (line 218)
Mismatch between input size and the expected number of input color components.
Error in images.color.ColorConverter/evaluate (line 364)
out = convert(self, in, varargin{:});
Error in images.color.internal.Callable/parenReference (line 15)
[varargout{1:nargout}] = self.evaluate(varargin{:});
Error in lab2rgb (line 76)
rgb = converter(lab);
Error in perdm_Main (line 45)
encyptedLena = lab2rgb(IfanmodF3);%,'ColorSpace','adobe-rgb-1998');

Accepted Answer

Image Analyst
Image Analyst on 13 Aug 2022
I didn't go over the whole code (no time now) but I did notice something wrong immediately. L is channel 1, not 3. Corrected code:
rgbImage = imread('Lena.png');
labImage = rgb2lab(rgbImage);
[L, A, B] = imsplit(labImage);
  4 Comments
Walter Roberson
Walter Roberson on 13 Aug 2022
Suppose that this is the first time through the loop. You do not assign anything to s1 before
for i=90:-1:1
so the only way that anything gets assigned to s1 is in the else clause of the isnan test.
The isnan test is inside the for l=1:16 loop. Suppose isnan is false for the first 10 iterations of l, then with the else clause you assign to each of s1(1) to s1(10). Now suppose isnan is true when l is 11. You assign 0 to ree but you do not assign anything to s1(11) because the assignment is inside the else test. Now suppose isnan is false for l = 12, so you assign something to s1(12), which has the side effect of filling in 0 for the missing s1(11). Now keep going and assume for l=15 that isnan is false so you assign to s1(15), filling in any missing elements with 0. At this point s1 is a vector of length 15.
Now suppose that for 16 the value is nan, so you assign 0 to ree but you do not assign ree to s1(16). At this point s1 is still length 15.
Now you try to reshape the vector of length 15 to 4 by 4 and that fails.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!