简体   繁体   中英

Unable to perform assignment because the size of the left side is 512-by-512 and the size of the right side is 512-by-512-by-3 MATLAB

I am a beginner in MATLAB and am following this code from GitHub related to the classification of lung cancer.

When I use the sample image in the GitHub link it works fine but when I try to use a different image from the database mentioned on GitHub I am getting the following error.

Unable to perform assignment because the size of the left side is 512-by-512 and the size of the right side is 512-by-512-by-3.

Error in lung (line 16)

img_out(:,:,n) = imfilter(img_in, gb, 'symmetric');

Here is the area of code where the error lies

%% Preprocessing using gabor filter for image enhancement

lambda  = 9;
theta   = 0;
bw      = 3;
psi     = [0 0];
gamma   = 2;
N       = 4;
img_in = imread('b.bmp');
%img_in = double(dicomread('b.dcm'));
%img_in(:,:,2:3) = [];
img_out = zeros(size(img_in,1), size(img_in,2), N);
for n=1:N
    gb = gabor_fn(bw,gamma,psi(1),lambda,theta)...
        + gabor_fn(bw,gamma,psi(2),lambda,theta);
    img_out(:,:,n) = imfilter(img_in, gb, 'symmetric');
    theta = theta + pi/4;
end
figure(1);
imshow(img_in);
title('input image');
figure(2);
img_out_disp = sum(abs(img_out).^2, 3).^0.5;
img_out_disp = img_out_disp./max(img_out_disp(:));
imshow(img_out_disp);
title('gabor output, L-2 super-imposed, normalized');

I also checked the import wizard and there is definitely something different about the sample image on GitHub and the.dcm image I download and then convert to.bmp.

The output of img_in = imread('b.bmp'); is a 512x512x3 RGB image. You filter this RGB by imfilter() and return an object of the same size. You are then trying to to assign this to a single 512x512 slice of your 512x512x4 img_out array.

If the.dcm image is grayscale you should use rgb2gray() to change the size of img_in to a single 512x512 slice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM