Info

This question is closed. Reopen it to edit or answer.

Errors when editing an image

1 view (last 30 days)
Tom
Tom on 10 Jan 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
I'm trying to create an image filter subclass that will shift an input image sinusoidally on the x-axis, but when I call the function I get a few errors.
Errors I get are:
Error using LabImage (line 20)
Not enough input arguments.
Error in SinusoidalLabImageFilter/Apply (line 29)
img_o(y,local_x,:) = img(y,:,:);
Error in LabImage/ApplyFilter (line 128)
filter.Apply(obj);'
I'm not quite sure how to resolve the errors, as I'm not entirely sure where the errors stem from. The 2 relevant bits of the classes are below
classdef SinusoidalLabImageFilter < LabImageFilter
%LabImageFilter for Sinusoidally shifting an image
properties(SetAccess = protected)
ImageData; %MxNx3 RGB image data
end
methods
function obj = SinusoidalLabImageFilter()
obj = obj@LabImageFilter();
end
end
methods(Access = {?LabImage,?LabImageFilter})
function [ img_o ] = Apply(filter, img)
%UNTITLED Shifts an image sinusoidally
%
Y = size(img, 1);
X = size(img, 2);
theta = input('Input a period of the wave: ');
max_shift = 2*input('Input an amplitude of the wave: ');
img_o = LabImage([X+max_shift, Y];
for y=1:Y
local_shift = ceil((max_shift/2)*sin(y/theta));
local_x= 1:X;
local_x = local_x + ceil((max_shift/2)) + local_shift;
img_o(y,local_x,:) = img(y,:,:);
end
img.ImageData = img_o
end
end
end
This is the filter I'm trying to call by
filter = SinusoidalLabImageFilter();
x.ApplyFilter(filter);
The original LabImage class up to where it is relevant is below
classdef LabImage < handle
% LabImage: an image-handling and manipulation class
properties (SetAccess=?LabImageFilter)
ImageData; %MxNx3 RGB image data
end
properties
Alpha; % separate transparency channel
end
methods
function obj = LabImage(input)
% LabImage contructor
%
%The constructor takes 3 possible input types:
% filename: load imagedata from the specified file
% [x,y]: create an empty image of width x and height y
% LabImage: construct a copy of the original LabImage
if isa(input, 'LabImage')
obj.ImageData = input.ImageData;
obj.Alpha = 0.0;
obj.Alpha = input.Alpha;
else
if ischar(input)
data = imread(input);
data = double(data)./255;
else
data = zeros(input(2),input(1),3);
end
s = size(data);
obj.ImageData = data;
obj.Alpha = 1.0;
end
function obj = ApplyFilter(obj, filter)
filter.Apply(obj);
end
end
end
Thanks in advance to anyone who can help resolve my issues

Answers (1)

Sean de Wolski
Sean de Wolski on 10 Jan 2014
You need to pass the image in too:
filter.Apply(obj);
But filter.Apply expects (obj,img)
function [ img_o ] = Apply(filter, img)
This is a good example of where:
dbstop if error
Will help you dramatically. It'll stop when the error occurs so you can see exactly what's going on.

Community Treasure Hunt

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

Start Hunting!