Question: matlab to python Please change this MATLAB code to Python code (You only need to change the functional part.) clear all %READ THE RGB IMAGE

matlab to python

Please change this MATLAB code to Python code (You only need to change the functional part.)

clear all

%READ THE RGB IMAGE

I = imread('peppers.png');

A = imnoise(I,'Salt & pepper',0.1);

figure,imshow(A);title('IMAGE WITH SALT AND PEPPER NOISE');

%DEFINE THE WINDOW SIZE MXN

M=3;

N=3;

%PAD THE MATRIX WITH ZEROS ON ALL SIDES

modifyA=padarray(A,[floor(M/2),floor(N/2)]);

B = zeros([size(A,1) size(A,2)]);

med_indx = round((M*N)/2); %MEDIAN INDEX

for i = 1:size(modifyA,1)-(M-1)

for j = 1:size(modifyA,2)-(N-1)

temp = modifyA(i:i+(M-1),j:j+(N-1),:);

%RED,GREEN AND BLUE CHANNELS ARE TRAVERSED SEPARATELY

for k = 1:3

tmp = temp(:,:,k);

B(i,j,k) = median(tmp(:));

end

end

end

%CONVERT THE IMAGE TO UINT8 FORMAT.

B = uint8(B);

figure,imshow(B);

title('IMAGE AFTER MEDIAN FILTERING');

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!