Please help me?? Recolor letter on image.
4 views (last 30 days)
Show older comments
So i'm very lost in matlab , god i even struggle installing the damn thing. Anyway i'm trying to load an image with white background and black letters, and change the color of those letters according to the values of some RGB sliders. I understand that i have to work with the RGB matrix But i can't do it. :(
I already managed to load the image into axes2 and to get the sliders working and putting the selected color into an axes control (axes1), now i don't know how to do the rest.
Can you complete the code PLEASE?
This is the code that loads the file into axes 2:
function Untitled_2_Callback(hObject, eventdata, handles)
global a;
[archivo ruta]=uigetfile({'*.gif';'*.jpg'},'abrir imagen');
if isequal(archivo,0)%si el usuario no eleige ningun archivo
return
else
a=imread(strcat(ruta,archivo));
axis(handles.axes2);
imshow(a);
msgbox('Se abrio con exito','mensaje');
end
And this is the button that currently loads the color into axes1 and should change also the color of the letter in the image in axes2:
function pushbutton2_Callback(hObject, eventdata, handles)
r=get(handles.Slider_red,'value');
g=get(handles.Slider_green,'value');
b=get(handles.Slider_blue,'value');
set(handles.axes1,'Color',[ r g b]);
This is the project in dropbox: https://www.dropbox.com/sh/iofwdez4wiwlfay/AAAHyV0gruX5cvcdv5TJgxUla?dl=0
0 Comments
Answers (1)
Image Analyst
on 3 Nov 2014
Since you have essesntially a monochrome image, I'd convert to grayscale with rgb2gray() if necessary.
grayImage = rgb2gray(rgbImage);
imshow(grayImage);
Then apply a color map, such as hsv(256).
colorMap = hsv(256);
colormap(colorMap);
Then your scrollbar can use circshift() to rotate the colormap and then use colormap() to apply the new, shifted colormap to the image.
2 Comments
Image Analyst
on 3 Nov 2014
Look at this demo:
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
hFig = figure;
grayImage = imread('cameraman.tif');
imshow(grayImage);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Apply a color map, such as hsv(256).
colorMap = hsv(256);
colormap(colorMap);
colorbar;
% k = round(get(handles.scrollbar1, 'value'));
% No scroll bar in demo, so use a for loop instead to illustrate what to do.
for k = 1 : 2 : 256
colorMap = circshift(colorMap, k, 1);
colormap(colorMap);
% colorbar;
promptMessage = sprintf('Do you want to Continue,\nor Cancel?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
end
close(hFig);
Of course, you would not have a for loop, you'd just get the scrollbar value like it says. rgbImage would be your global variable.
See Also
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!