Write a function that takes 4 arguments (integer, integer, picture, string). Thi
ID: 3703886 • Letter: W
Question
Write a function that takes 4 arguments (integer, integer, picture, string). This function should be able to be used on any picture. This means you should not use specific numbers to determine how to manipulate the image. You should turn the left half of the picture to grey scale. Next you should change the green value of the top right half of the picture to the first integer argument. Finally, you should change the blue value of the bottom right half of the picture to the second integer argument. Now you should display your new picture and save it to the path that was passed as the string argument.
Explanation / Answer
-------------------------------------------Code---------------------------------------------
function [ ] = prac3( a, b, img, str )
% converting half of the image in grayscale
imgG = rgb2gray(img);
[r, c, ~] = size(img);
c = round(c/2);
imgS = img;
for i = 1:3
imgS([1:r],[1:c],i) = imgG([1:r],[1:c]);
end
figure, imshow(imgS);
% Changing the top right coor of green matrix
[a1, a2, a3] = size(imgS);
tr = uint8(a1/2); %half of the row
tc = uint8(a2/2); %half of the col
imgS = double(imgS);
for i = 1:1:tr
for j = tc+1:1:a2
imgS(i,j,2) = a; % %imgS(,,3) = green part
end;
end;
% Changing the bottom rigth of blue part of image
for i = tr+1:1:a1
for j = tc+1:1:a2
imgS(i,j,3) = b; %imgS(,,3) = blue part
end;
end;
figure, imshow(imgS); %displaying image
%imwrite to store the image
imwrite(imgS,str,'jpg');
end
-------------------------------------------------------CODE---------------------------------------
Done all the work....
Please provide positive feedback
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.