Matlab to C# conversion
-
i am sending matlab code,can some one help me to convert this code into C#, imagex=imread('D:\MS_courses\ece655\Project\test_images\test_image3.jpg'); %RGB2GRAY converts RGB images to grayscale by eliminating the %hue and saturation information while retaining the luminance. %im2double takes an image as input, and returns an image of class double. f = im2double(rgb2gray(imagex)); %f=[.1,.2,.3;.4,.5,.6;.7,.8,.9]; %Storing the number of rows and columns in separate output variables [sizeM, sizeN] = size(f); %Counter is used just to check the status of the program at all times. counter = 0; %for k=1:1:256 %gvalue_f(k) = 0; %gvalue_N(k) = 0; %end %-------------------------------------------------------------------------- %This loops makes a window of 3*3 and scans over the image from left to %right and top to bottom to get those pixel values that are most probably %a function of Impulse, called Nimp. for x=2:1:(sizeM-1) for y=2:1:(sizeN-1) k = x; l = y; x1 = f(k-1, l-1); x2 = f(k-1, l); x3 = f(k-1, l+1); x4 = f(k, l-1); x5 = f(k, l); x6 = f(k, l+1); x7 = f(k+1, l-1); x8 = f(k+1, l); x9 = f(k+1, l+1); W = [x1,x2,x3,x4,x5,x6,x7,x8,x9]; x_sum = 0; count = 0; x_temp = 0; wind(1,1) = W(1); wind(1,2) = W(2); wind(1,3) = W(3); wind(2,1) = W(4); wind(2,2) = W(5); wind(2,3) = W(6); wind(3,1) = W(7); wind(3,2) = W(8); wind(3,3) = W(9); for m=1:1:3 for n=1:1:3 x_temp = wind(m,n); if((x_temp == min(W)) | (x_temp == max(W)))% | (x_temp <= 10) | (x_temp >= 230)) Nimp_sub(m, n) = x_temp; else count = count + 1; x_sum = x_sum + x_temp; Nimp_sub(m, n) = 0; end end end %Nimp=size(f); Nimp(k-1:k+1,l-1:l+1) = Nimp_sub; counter = counter + 1 end end %for k=2:1:sizeM-1 % for k=2:1:sizeN-1 % gvalue_f(f(k, l)) = gvalue_f(f(k, l)) + 1; % Nimp_db = im2uint8(Nimp(k, l)) + 1; % gvalue_N(Nimp_db(k, l)) = gvalue_N(Nimp_db(k, l)) + 1; %end %end %Calculating the histograms of input image and Nimp (those pixels in the image %which are most probably members of impulse noise). temp_hist_f = hist(f, 256); temp_hist_imp = hist(N
-
i am sending matlab code,can some one help me to convert this code into C#, imagex=imread('D:\MS_courses\ece655\Project\test_images\test_image3.jpg'); %RGB2GRAY converts RGB images to grayscale by eliminating the %hue and saturation information while retaining the luminance. %im2double takes an image as input, and returns an image of class double. f = im2double(rgb2gray(imagex)); %f=[.1,.2,.3;.4,.5,.6;.7,.8,.9]; %Storing the number of rows and columns in separate output variables [sizeM, sizeN] = size(f); %Counter is used just to check the status of the program at all times. counter = 0; %for k=1:1:256 %gvalue_f(k) = 0; %gvalue_N(k) = 0; %end %-------------------------------------------------------------------------- %This loops makes a window of 3*3 and scans over the image from left to %right and top to bottom to get those pixel values that are most probably %a function of Impulse, called Nimp. for x=2:1:(sizeM-1) for y=2:1:(sizeN-1) k = x; l = y; x1 = f(k-1, l-1); x2 = f(k-1, l); x3 = f(k-1, l+1); x4 = f(k, l-1); x5 = f(k, l); x6 = f(k, l+1); x7 = f(k+1, l-1); x8 = f(k+1, l); x9 = f(k+1, l+1); W = [x1,x2,x3,x4,x5,x6,x7,x8,x9]; x_sum = 0; count = 0; x_temp = 0; wind(1,1) = W(1); wind(1,2) = W(2); wind(1,3) = W(3); wind(2,1) = W(4); wind(2,2) = W(5); wind(2,3) = W(6); wind(3,1) = W(7); wind(3,2) = W(8); wind(3,3) = W(9); for m=1:1:3 for n=1:1:3 x_temp = wind(m,n); if((x_temp == min(W)) | (x_temp == max(W)))% | (x_temp <= 10) | (x_temp >= 230)) Nimp_sub(m, n) = x_temp; else count = count + 1; x_sum = x_sum + x_temp; Nimp_sub(m, n) = 0; end end end %Nimp=size(f); Nimp(k-1:k+1,l-1:l+1) = Nimp_sub; counter = counter + 1 end end %for k=2:1:sizeM-1 % for k=2:1:sizeN-1 % gvalue_f(f(k, l)) = gvalue_f(f(k, l)) + 1; % Nimp_db = im2uint8(Nimp(k, l)) + 1; % gvalue_N(Nimp_db(k, l)) = gvalue_N(Nimp_db(k, l)) + 1; %end %end %Calculating the histograms of input image and Nimp (those pixels in the image %which are most probably members of impulse noise). temp_hist_f = hist(f, 256); temp_hist_imp = hist(N