Image processing with difference equation

I am trying to send an take an image and blur it using a difference equation, My code takes each individual pixel of the image, runs it through the difference equation and then stores the new pixel value into a new array that is displayed upon completion. I am just having trouble with completing the difference equation. The difference equation I have is
(1-p)x[n] = y[n] - p*y[n-1]
I have this difference equation in my code for the most part, I am just running into a wall trying to set what x should be equal to. I was going along with the example from this webpage, second to last page. (https://www.csun.edu/~skatz/ece351/matlab_tutorial_2.pdf)
function [ ] = Blur_( lion, p )%Lion is the image, p is the variable used in the difference equation, set this between .1-.9
row = 2; %//Starting point for Second While Loop Currently skips all the first element of each row, should change once run through diff equation.
%//Setting row = 1 will grab each element of the array
column = 1; %//Starting point for first While Loop
A = 'End of Row'; %//Display at end of each row
[x_1,y_1,~] = size(lion);% find dimensions of image
figure %//Defines new figure to be displayed
colormap(gray(255));
image(lion) %// the image stored in gray is a columnXrow uint8 image
title('Original Image');%//Gives title to original image
tableA = zeros(y_1,x_1, 'uint8'); %create array of zeros for tableA to reduce overhead
while (p > 0 && p < 1)%//Test range of p from 0.1 to 1 incrementing by .1
while (column < (y_1 + 1)) %// First while loop, used for the rows
while (row < (x_1 + 1)) %//Second while loop, used to access each column of First while loops current row
element = double(lion(column,row))%//This stores the current Array cell value in the variable element
%--------THE PART THAT ISN'T WORKING-------%
a = [1 -p]; %//this is for y[n] - p*y[n-1]
b = [1-p 0]; %// for (1-p)x[n] (will return and replace 1 with p once code is functioning)
x = element*4;%This part I cant solve for. I am not sure how to calculate from difference equation I just used some arbitrary value with the current pixel as a place holder
new_pixel = filter(b,a,x); %difference equation is applied to the array
tableA(column,row)= new_pixel; %//This creates the new array for the new image, storing new_pixel into current row/column
%-------------------------------------------%
row = row + 1;
end
row = 1; %Reset row to the start at the first element in the array on the next row
disp(A); %//End of row in array
column = column + 1; %increment column
end %//end column while loop
column = 1; %//Reset column to 1, this will allow us to test the next value of p for a new image.
figure %//Defines a new figure to be displayed
colormap(gray(255));
image(tableA)%//displays the new image
title('New Image');%//Gives the new image a title
p = p + .2; %//Increment p until 1
end %//end p while loop
end

 採用された回答

Image Analyst
Image Analyst 2016 年 4 月 23 日

0 投票

I don't know what the code is doing. Why don't you simply blur with a single line of code in a call to conv2() or imfilter()? It would be so much easier.

5 件のコメント

Steven Laburtz
Steven Laburtz 2016 年 4 月 23 日
I am taking each individual Pixel and passing it through a difference equation, I am required to use this equation. I wish i could just pass it through a blurring function.
Image Analyst
Image Analyst 2016 年 4 月 23 日
but what is x and what is y in the equation? I'd guess y is the intensity of the input image, and n is the index of the pixel (like what column your pixel is on so it's like the "(x,y)" coordinate), but what is x in the equation? Is x the intensity of an output image? This is why I don't like it when people use single letter variable names - it's not very self-descriptive and we're left guessing what the variables represent.
Steven Laburtz
Steven Laburtz 2016 年 4 月 23 日
編集済み: Steven Laburtz 2016 年 4 月 23 日
I replaced my variable names for the most part. For the difference equation that I gave. I was just given a transfer function which was
H(z)=(1-p)/(1-pz^(-1)) when (0 < p < 1)
So I just solved for the difference equation of this transfer function. y should be the output and x the input I believe, the n is the current pixel being passed through. in my code n == element
Image Analyst
Image Analyst 2016 年 4 月 23 日
I still don't quite understand it. Is pz really p*z? So pz^(-1) is really p/z? Whatever, sounds like you got it solved.
Steven Laburtz
Steven Laburtz 2016 年 4 月 23 日
It's all right, I will talk to my professor about this some more. Thanks for all the help you have provided!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by