Question

In: Computer Science

I am trying to do edge detection using matlab. I have posted code here. It does...

I am trying to do edge detection using matlab. I have posted code here. It does not give any error but it's not running it at all. So please help me to fix it and also exaplin each line of this code pls. Thanks!

i = imread('C:\Users\Amanda\Desktop");
I = rgb2gray(1i);
BW1 = edge(I,'prewitt');
BW2= edge(I,'sobel');
BW3= edge(I,'roberts');
subplot (2,2,1);
imshow(I);
title('original');
subplot(2,2,2);
imshow(BW1);
title('Prewitt');
subplot(2,2,3);
imshow(BW2);
title('Sobel');
subplot(2,2,4);
imshow(BW3);
title('Roberts');

Solutions

Expert Solution

I have fixed the code which you posted, there are basically two errors.

  1. The name of the initial image file.
  2. Use of that 'i' in the second line.

Resolution

  1. There are two solutions for the first error.
    1. just paste the image in the same folder as that of the script and directly use the name of image as I have done below.
    2. Otherwise, add the name of the file after the location of the folder it is present in. LIKE: "C://Users//Amanda//Desktop//RGB.png" if the name of the file is RGB.png
  2. The second error solution is to simply make the "1i" to "i" (Without quotes)

Following is the updated code

i = imread('RGB.png'); % This is reading the image from the file location specifies

I = rgb2gray(i); % Converting the image from RGB to Gray image

BW1 = edge(I,'prewitt'); % This is finding the edge in the image with prewitt as the method

BW2= edge(I,'sobel'); % This is finding the edge in the image with Sobel as the method

BW3= edge(I,'roberts'); % This is finding the edge in the image with roberts as the method

subplot (2,2,1); % This is making the plot in the area of 2*2 i.e 4 plots and this is the first(1) plot

imshow(I); % This will show the plot, whose space is aquired above, in the above line

title('original'); % Title for the above plot

subplot(2,2,2); % Acquiring space for the second plot

imshow(BW1); % Printing the second one in the space

title('Prewitt'); % Title for the above plot

subplot(2,2,3); % Making the space for the third plot

imshow(BW2); % Printing the third plot, whose space is allocated above.

title('Sobel'); % Title for the above plot

subplot(2,2,4); % Fourth plot Space

imshow(BW3); % Printing the plot

title('Roberts'); % Title for the same.

Following is the snippet of the output.

That was a nice question to answer
Friend, If you have any doubts in understanding do let me know in the comment section. I will be happy to help you further.
Please like if you think effort deserves like.
Thanks

Figure 1 x + original Pre witt Sobel Roberts


Related Solutions

This is Using MATLAB: I am trying to store the solution of this matrix because I...
This is Using MATLAB: I am trying to store the solution of this matrix because I want to do something with the result like find the norm of that answer however I am stuck and cannot seem to be able to. Help would be appreciated! --------------------------------------------- MATLAB CODE: close all clear clc A = [1 -1 2 -1; 2 -2 2 -3; 1 1 1 0; 1 -1 4 5]; b = [-8 -20 -2 4]'; x = gauss_elim(A,b) function...
What I am trying to do is to design a Butterworth Bandpass filter using Matlab, High...
What I am trying to do is to design a Butterworth Bandpass filter using Matlab, High frequency must equal to 16 Hz and lower frequency must be 10Hz (passBand). and the input signal must be a white noise signal. here is my code : mu=0; sigma=2; X= sigma*randn(500,1)+mu; %Generating White Noise signal Fs=500;%Sampling Frequency Fh= 16; Fl=10; order=6; [b,a]=butter(order,[Fh Fl]/(Fs/2),'bandpass');%Butterworth BandPass filter XX=filtfilt(b,a,X);%filter the signal both forward and backword in time Actually, I am not sure about Fs value that...
I am trying to integrate a Singleton Pattern into this code I had previously made. Here...
I am trying to integrate a Singleton Pattern into this code I had previously made. Here is my code to a previous project: radius = float(input("Please enter the radius: ")) area = 3.14 * radius**2; print("The area is ", area, "square units.") For this project it must be coded in python. Here are the instructions for the project for reference. Implementing Design Patterns with Python Software Design Patterns may be thought of as blue prints or recipes for implementing common...
Face detection code in Matlab
Face detection code in Matlab
This is my code for python. I am trying to do the fourth command in the...
This is my code for python. I am trying to do the fourth command in the menu which is to add an employee to directory with a new phone number. but I keep getting error saying , "TypeError: unsupported operand type(s) for +: 'dict' and 'dict". Below is my code. What am I doing wrong? from Lab_6.Employee import * def file_to_directory(File): myDirectory={}       with open(File,'r') as f: data=f.read().split('\n')    x=(len(data)) myDirectory = {} for line in range(0,199):      ...
Here is my fibonacci code using pthreads. When I run the code, I am asked for...
Here is my fibonacci code using pthreads. When I run the code, I am asked for a number; however, when I enter in a number, I get my error message of "invalid character." ALSO, if I enter "55" as a number, my code automatically terminates to 0. I copied my code below. PLEASE HELP WITH THE ERROR!!! #include #include #include #include #include int shared_data[10000]; void *fibonacci_thread(void* params); void parent(int* numbers); int main() {    int numbers = 0; //user input....
I am trying to create my own doubly linkedlist class and here is what I have...
I am trying to create my own doubly linkedlist class and here is what I have so far. my addfirst is adding elements forever and ever, and I could use some help. This is in C++. Please help me complete my doubly linkedlist class. the addfirst method is what I would like to complete. #ifndef DLLIST_H #define DLLIST_H #include "node.h" #include using namespace std; template class DLList { private:     Node* head = nullptr;     Node* tail = nullptr;    ...
Using Python, I am trying to integrate 'iloc' into the line of code below? This line...
Using Python, I am trying to integrate 'iloc' into the line of code below? This line is replacing all the '1' values across my .csv file and is throwing off my data aggregation. How would I implement 'iloc' so that this line of code only changes the '1's integers in my 'RIC' column? patient_data_df= patient_data_df.replace(to_replace=[1], value ="Stroke") Thank you:)
Matlab code problems I have to write a code using functions to find out if a...
Matlab code problems I have to write a code using functions to find out if a year is a leap year. I'm on the write track i feel like but I keep getting an error message and matlab isnt helping to troubleshoot. The issue is on line 30. Here is my code: function project_7_mfp() %   PROJECT_7_ABC   project_7_abc() creates a function that prompts the user %   enter a year after 1582 It then determines if it is a leap year %...
I am trying to plot a difficult function in MATLAB, however I need to understand the...
I am trying to plot a difficult function in MATLAB, however I need to understand the basics first. I am trying to plot n=0 for x=0:0.01:2pi n=n+1 y(n)=sin(x) end I beleive what this says, is that I want to plot sin(x) over a full period hence from o to 2pi, and I beleive the 0.01 is the incremenation along the x-axis. I am not sure what my n is doing Could smeone please graph this for me with the MATLAB...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT