tree with white decoration

So, we were given this picture of a tree that had a white line around it . We are asked to isolate the pixels of it in (x,y) cooridinates , then find the Fourier series coefficients based on those coordinates . I explain in the picture, y[n]=y coordinates of the white decoration and x[n]=x coordinates of the white decoratives. So I have found x,y, but I don't know how to find the Fourier Series coefficients and we are also asked to use the first 50 of them to reform the shape only of the white decoratives. I also have to say that when I plotted x,y my shape was not properly oriented (picture2)
Can anyone please give me an example code for those 2 questions , ? We have to use fft() function.
also since my shape is not properly oriented does that mean my y,x are wrong?
Also my deadline is very close ..........

8 Comments

not properly oriented- i mean 90 degrees to the left
Any help would be appreciated...
I think you attached the wrong photo. There is no picture of a tree with decorations attached.
Did you do
ftx = fft(x);
ftx(51:end-50) = 0; % erase frequencies higher than the first 50 of them.
x2 = ifft(ftx);
% Same for y.
Actually its a black background where I drew the white line of the tree decoration but the original is 90 degrees to the right of the camscanner above. I used bwtraceboundary and find().
how do I answer the first question with the coefficients?
After that how do I use imshow with x,y?
Here is what I see for the first image:
and the second image is:
Which one of those is the tree with decorations?
You would not use imshow() with x and y. You could use imshow() to display an image, then use hold on, and call plot(x,y) to display the cirve above the image in the overlay.
Once you've segmented the white decorations, you can get the boundaries (x,y) coordinates like this:
% Plot the borders of all the blobs in the overlay above the original grayscale image
% using the coordinates returned by bwboundaries().
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
imshow(originalImage); % Optional : show the original image again. Or you can leave the binary image showing if you want.
% Here is where we actually get the boundaries for each blob.
boundaries = bwboundaries(mask);
% boundaries is a cell array - one cell for each blob.
% In each cell is an N-by-2 list of coordinates in a (row, column) format. Note: NOT (x,y).
% Column 1 is rows, or y. Column 2 is columns, or x.
numberOfBoundaries = size(boundaries, 1); % Count the boundaries so we can use it in our for loop
% Here is where we actually plot the boundaries of each blob in the overlay.
hold on; % Don't let boundaries blow away the displayed image.
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k}; % Get boundary for this specific blob.
x = thisBoundary(:,2); % Column 2 is the columns, which is x.
y = thisBoundary(:,1); % Column 1 is the rows, which is y.
plot(x, y, 'r-', 'LineWidth', 2); % Plot boundary in red.
end
hold off;
caption = sprintf('%d Outlines, from bwboundaries()', numberOfBoundaries);
fontSize = 15;
title(caption, 'FontSize', fontSize);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
In the next question we are asked to rebuild the original shape using the first M+1 coefficients of the discrete Fourier series and we are ought to use specifically the function imshow().
As for the originall image I'm not sure if I should post it ,since it is our professor's image ( I mean without his permission...)
I see. You could always grab one off the internet, but I don't think your professor would like you using our code. Aren't you supposed to write your own code?

Sign in to comment.

Answers (0)

Products

Release

R2021b

Asked:

on 20 Feb 2022

Commented:

on 20 Feb 2022

Community Treasure Hunt

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

Start Hunting!