MATLAB Answers

i am trying to do this code

1 view (last 30 days)
D.A.E
D.A.E on 9 Aug 2020
Commented: D.A.E on 9 Aug 2020
i am trying to do this code
but the last image doesn't apper and it gives me this error
??? Error: An array for multiple LHS assignment cannot contain numeric value.
so what should i do ?
i = imread('peppers.png');
red=i(:,:,1);
green=i(:,:,2);
blue=i(:,:,3);
subplot(4,2,1);imshow(i);title('original image');
subplot(4,2,2);imshow(red);title('red');
subplot(4,2,3);imshow(green);title('green');
subplot(4,2,4);imshow(blue);title('blue');
A=cat(3,red,green,blue);
subplot(4,2,5);imshow(A);title('Combined again');
Fi=fftshift(double(A));
[m,n,5]=size(A);
[x,y]=meshgrid(1:n,1:m);
x=x-(n+1)/2;
y=y-(m+1)/2;
d=sqrt(x.^2+y.^2);
d0=30;
ghpf=1-exp(-d.^2/(2*d0.^2));
j=ifft2(fftshift(Fi.*ghpf));
subplot(4,2,6);imshow(j);title('new');

  0 Comments

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 9 Aug 2020
You cannot do this:
[m,n,5]=size(A);
Like I said before in your prior/duplicate question, the third output must be a variable:
[m, n, numberOfColorChannels] = size(A);
It cannot be a constant. Plus, please consider my suggestions in that answer for improving your code.

  3 Comments

D.A.E
D.A.E on 9 Aug 2020
i have to define a variable first? then put it in [m,n,variable]?
Image Analyst
Image Analyst on 9 Aug 2020
Actually it looks like it was someone else with the same homework question:
No, you don't have to define the variable first/in advance. The call to size() will create it automatically.
D.A.E
D.A.E on 9 Aug 2020
yeah we are doing the same homework , but we don't know how
thank you by the way

Sign in to comment.


Image Analyst
Image Analyst on 9 Aug 2020
You need to do it on the gray scale image. Here's a little bit more:
clc; % Clear the command window.
fprintf('Beginning to run %s.m.\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
rgbImage = imread('peppers.png');
[rows, columns, numberOfColorChannels]=size(rgbImage);
subplot(4,3,1);imshow(rgbImage);title('Original Image');
g = gcf;
g.WindowState = 'maximized';
if numberOfColorChannels == 3
red=rgbImage(:,:,1);
green=rgbImage(:,:,2);
blue=rgbImage(:,:,3);
subplot(4,3,2);imshow(red);title('red');
subplot(4,3,3);imshow(green);title('green');
subplot(4,3,4);imshow(blue);title('blue');
rgbImage2=cat(3,red,green,blue); % Will be identical to rgbImage!
subplot(4,3,5);imshow(rgbImage2);title('Combined again');
grayImage = rgb2gray(rgbImage);
else
grayImage = rgbImage; % It's already gray scale.
end
subplot(4,3,6);
imshow(grayImage, []);
title('Gray Image');
fftImage = fft2(double(grayImage));
Fi=fftshift(fftImage);
subplot(4,3,7);
imshow(log(real(Fi)), []);
title('Spectrum of Gray Image');
[x,y]=meshgrid(1:columns,1:rows);
x=x-(columns+1)/2;
y=y-(rows+1)/2;
d=sqrt(x.^2+y.^2);
d0=30;
ghpf=1-exp(-d.^2/(2*d0.^2));
subplot(4,3,8);
imshow(ghpf, []);
title('Spectrum of Filter');
filteredSpectrum = Fi.*ghpf;
subplot(4,3,9);
imshow(log(real(filteredSpectrum)), []);
title('Filtered Spectrum');
filteredSpatialDomainImage=ifft2(fftshift(Fi.*ghpf));
subplot(4,3,10);imshow(filteredSpatialDomainImage);title('new');
fprintf('Beginning to run %s.m.\n', mfilename);
msgbox('Done!');
There is a lot of useless code in there so you should really try to understand what you're doing and only do what needs doing. Like no need to split up into color channels only to recombine them.

  1 Comment

D.A.E
D.A.E on 9 Aug 2020
thank you so much

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!