Image processing with difference equation
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Steven Laburtz
il 23 Apr 2016
Commentato: Steven Laburtz
il 23 Apr 2016
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
0 Commenti
Risposta accettata
Image Analyst
il 23 Apr 2016
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 Commenti
Image Analyst
il 23 Apr 2016
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.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!