What is Glassy Effect in MATLAB?
Last Updated :
22 Oct, 2022
MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. With the help of this software, we can also give the glassy effect to an image. It is done by replacing each pixel value in the image with a random value from one of its
neighbors, including self, in an m by n window.
The Glassy effect is a filter that is used to give a blurry or real-looking glass surface image.
Steps:
Steps to create a glassy effect image using MATLAB Software.
- Read the original image using imread and show it with the title ‘Original Image’.
- Now we’ll define a window of size m by n.
- Now we’ll use nested for loops and select a random pixel value from its neighbors.
- In the last step, we’ll save the image with the glassy effect and show it with the title Blurry Image.
Example 1:
Matlab
original=imread( 'image.png' );
imshow(original);title( 'Original Image' );
m=6;
n=7;
BlurredImage = uint8(zeros([size(original,1)-m,size(original,2)-n,3]));
for i = 1:(size(original,1)-m)
for j = 1:(size(original,2)-n)
temp = original(i:i+m-1 , j:j+n-1, :);
newX = ceil(rand(1)*m);
newY = ceil(rand(1)*n);
BlurredImage(i,j,:) = temp(newX, newY, :);
end
end
figure, imshow(BlurredImage); title( 'Blurry Image' );
imwrite(BlurredImage, 'Blurry Image.png' );
|
Output:
Sample image:
Output Image:
Share your thoughts in the comments
Please Login to comment...