To obtain a painting-like effect , define a small window matrix of size m by n. Copy the original image pixel values into the matrix and find the histogram of each value. Find the maximum occurring pixel value and replace the current position with the maximum occurrence value.
MATLAB CODE:
A=imread('aish.jpg');
%Define the matrix size of your convience.
m=5;
n=6;
Image=uint8(zeros([size(A,1)-m,size(A,2)-n,3]));
%Calculate the histogram for each RGB value.
for v=1:3
for i=1:size(A,1)-m
for j=1:size(A,2)-n
mymask=A(i:i+m-1,j:j+n-1,v);
h=zeros(1,256);
for x=1:(m*n)
h(mymask(x)+1)=h(mymask(x)+1)+1;
end
%Maximum occurring value and the position is obtained
[maxvalue,pos]=max(h);
Image(i,j,v)=pos-1;
end
end
end
figure,imshow(Image);
SEE ALSO : Swirl effect Cone effect Glassy effect Tiling effect Paint application(coloring)

![]() |
Original Image |
![]() |
Oil Paint Effect |
MATLAB CODE:
A=imread('aish.jpg');
%Define the matrix size of your convience.
m=5;
n=6;
Image=uint8(zeros([size(A,1)-m,size(A,2)-n,3]));
%Calculate the histogram for each RGB value.
for v=1:3
for i=1:size(A,1)-m
for j=1:size(A,2)-n
mymask=A(i:i+m-1,j:j+n-1,v);
h=zeros(1,256);
for x=1:(m*n)
h(mymask(x)+1)=h(mymask(x)+1)+1;
end
%Maximum occurring value and the position is obtained
[maxvalue,pos]=max(h);
Image(i,j,v)=pos-1;
end
end
end
figure,imshow(Image);
SEE ALSO : Swirl effect Cone effect Glassy effect Tiling effect Paint application(coloring)
Reference:
- Algorithms for Graphics and Image Processing
- Beyond photography: The Digital Darkroom
4 comments:
this code is working but no oil paint effect was applied
what should i do plz help :(
@SADAF
Try changing the values of m and n.
inspite of changing the values of m and n
no change apperas in image
plz guide me wt cud be the suitable values for m and n??
ok i have change the values n nw its working thanx
but i have another issue
actuallyi want this code in my project where m nt using imread function rather using load funtion, which can take any user specified image at run time
then wat changes should i made to this code to set path of image??
m beginner in matlab n want dis help for my final project
plz help :(
Enjoyed Reading? Share Your Views