# Undefined function or variable 'map' Error. How to fix?

3 views (last 30 days)

Show older comments

After working on this for a few days. This is the code I've written thus far:

if true

% code

end

% Clear the workspace

clc

clear all;

% Read the image 'Proj2.tif'

Proj2Image = 'Proj2.tif';

img = imread(Proj2Image);

% Stores the image as an array

img = img(:,:,1);

% I then take the Fast Fourier Transform (FFT) of the Image

imgfft = fft2(img);

% Next, I create a Butterworth Filter. A Low Pass Filter

% could probably also be performed, and work just as well.

% Note: C is a constant

% X is the size of the dimension of array X

% Y is the size of the dimension of array Y

c = 2;

X = size(imgfft, 1);

Y = size(imgfft, 2);

% A returns an array of ones in the X and Y direction

A = ones(X,Y);

XX = [204 182 191 196 214 219 228];

YY = [273 275 267 282 264 279 271];

% L is the max number of pixels in the image (i.e. 255)

L = 255;

for i=1:length(L)

for x = 1:X

for y = 1:Y

%Compute the distance between the points.

Lxy = sqrt((x-XX(i))^2 + (y-YY(i))^2);

A(x,y) = A(x,y) + 1/(1+(Lxy/L(i)^2))^(2*c);

end

end;

end;

% Subtract the array of ones

A = 1 - A;

% Next, I apply the filter by shifting the FFT of the image

% and multiplying it by the array of ones.

FilterImage = fftshift(imgfft).*A;

% Here, I shift back and perform the Inverse FFT

FilterImage2 = ifft2(fftshift(FilterImage));

% Next, I display FilterImage2 with the colormap defined as 'map'

imshow(abs(FilterImage2),map);

% Then I resize and display the 'periodicpattern.tif' image

% And compare it to the 'Proj2.tif' image that I filtered,

% shifted, and performed the FFT and Inverse FFT on.

[img,map] = imread('periodicpattern.tif');

figure('Name','Patterns/comparison');

subplot(1,2,1), imshow(abs(FilterImage2),map);

title('Patterns');

subplot(1,2,2), imshow(img,map);

title('Periodic Pattern of Image');

The problem I have with this code though is that when I run it, I get the following error message on Line 63: Undefined function or variable 'map'.

Do you have any other method I could use to fix this error, other than:

imshow(abs(FilterImage2),map);

I'm not quite too sure why it is doing this since Matlab ought to accept:

imshow(X,map)

which I don't think is all that much different. I tried replacing the abs(FilterImage2) by assigning it to a variable called I:

I = abs(FilterImage2);

But Matlab doesn't like this either.

Again, my input image is attached and all I am trying to do with it is get the mesh periodic cross-pattern out of it.

##### 1 Comment

Jan
on 17 Oct 2013

### Accepted Answer

Vivek Selvam
on 17 Oct 2013

Michael, you need to change line 9 from

img = imread(Proj2Image);

to

[img,map] = imread(Proj2Image);

##### 3 Comments

### More Answers (2)

Yatin
on 17 Oct 2013

Hi,

I notice that while reading the image with the " imread " function you have not read the map. The syntax for the imread function that you need to use in this case is

[img, map] = imread(Proj2Image);

The map obtained above can then possibly be used in the imshow function for displaying FilterImage2. Since the variable map is not available before, MATLAB is returning an error. Hope this solves your problem.

##### 0 Comments

Jan
on 17 Oct 2013

Edited: Jan
on 17 Oct 2013

This is a strange question. You did not define a variable called "map" but want to use it. The explanation, that "Matlab ought to accept imshow(X,map)" is very weak, because this argument is simply wrong. Try it:

clear all

imshow(X, map)

Now beside "map" even "X" is undefined.

It is impossible to recommend a workaround, because the definition of "map" is missing. But we cannot guess, what this should be, because the definition is missing...

Notice, that you define "map" in the following command:

[img,map] = imread('periodicpattern.tif');

So perhaps you simply forgot to catch the second output in the imread command before?

[img, map] = imread(Proj2Image);

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!