Fill the image with RGB colors based on user specified color value. Instead of Flood fill algorithm I am using bwlabel function in MATLAB to paint the image.
This is very simple comparing to the previous application.
This is very simple comparing to the previous application.
function colorglobal BW L A colorv rgb originalcolor undocolor point filename;scz=get(0,'ScreenSize');
figure('Position',[round(scz(1,3)/4) round(scz(1,4)/8) 700 500],'MenuBar','None','NumberTitle','off','Name','Paint Application','Resize','off');originalcolor=[0;0;0;];ax=axes('Position',[0 0 .7 1],'xtick',[],'ytick',[]);directory=dir('*.png');files={directory.name}';uicontrol('Style','popupmenu','position',[535 430 160 30],'Value',1,'String',files,'Callback',@displayfile);
uicontrol('Style','text','position',[495 400 35 20],'String','RED');
R=uicontrol('Style','slider', 'position',[535 400 160 20],'min', 0.0, 'max',1.0,'Callback',@colorvalue);
uicontrol('Style','text','position',[495 360 35 20],'String','GREEN');G=uicontrol('Style','slider', 'position',[535 360 160 20],'min', 0.0, 'max',1.0,'Callback',@colorvalue);
uicontrol('Style','text','position',[495 320 35 20],'String','BLUE');B=uicontrol('Style','slider', 'position',[535 320 160 20],'min', 0.0, 'max',1.0,'Callback',@colorvalue);
uicontrol('Style','text','position',[495 280 35 20],'String','Color');colorv(25,80,1:3)=0;
uicontrol('Style','pushbutton','position',[600, 470, 40,20],'String', 'UNDO','Callback',@options);uicontrol('Style','pushbutton','position',[645, 470, 40,20],'String', 'SAVE','Callback',@options);uicontrol('Style','pushbutton','position',[540 280 80 30]);
Function ‘colorvalue’ will show the color on the pushbutton.
function colorvalue(obj,event)
R1=get(R,'value');G1=get(G,'value');B1=get(B,'value');rgb=[ceil(R1*255); ceil(G1*255); ceil(B1*255);];colorv(:,:,1)=R1;colorv(:,:,2)=G1;colorv(:,:,3)=B1;uicontrol('Style','pushbutton','position',[540 280 80 30],'String','color','CDATA',colorv);originalcolor=rgb;trypaintme;catchoriginalcolor='null';endend
%User selects the image
function displayfile(obj,event)ptr=get(obj,'value');filename=char(files(ptr));A=imread(filename);[BW,L]=bwlabel(im2bw(A),8);imshow(BW);end
function paintmewhile(originalcolor==rgb)getpoints;endend
%To save the image or to go back to the previous point
function options(obj,event)fn=get(obj,'String');if(strcmp(fn,'SAVE')==1)fname=strcat('my',filename);msg=strcat('File name:',fname);msgbox(msg,'FILE SAVED');elseif(strcmp(fn,'UNDO')==1)rgb=undocolor;colorfill(point(1),point(2));rgb=originalcolor;endend
%Get the point in the image.
function getpointstrywaitforbuttonpress;f=get(ax,'CurrentPoint');x=round(f(1,2));y=round(f(1,1));if(x< size(A,1) && y < size(A,2))%Check whether x and y are less than the image sizepoint(1)=x;point(2)=y;undocolor=[A(x,y,1); A(x,y,2); A(x,y,3);];colorfill(x,y);endcatchoriginalcolor='null';endend
%Fill the image with the RGB value
function colorfill(x,y)label=BW(x,y);[r c]=find(BW==label);for i=1:size(r,1)A(r(i,1),c(i,1),:)=rgb;endimshow(A);endend
Watch the video: Painting the image using MATLAB.
GET THE SAMPLE IMAGE AT:http://www.clker.com/clipart-jumping-horse-outline.html