problem displaying image in axes

7 views (last 30 days)
Rao
Rao on 22 Jun 2012
I am currently working on a gui which have :
  • 1 push button to load image and 1 axes to display it.
  • 1 push button to convert the loaded rgb image to ycbcr and an axes to display it.
  • 1 push button to apply k means to the ycbcr image and then convert it back to rgb and an axes to display it.
upto conversion of the image to ycbcr (i.e upto 2nd point) it is working fine .
problem is that when i press 3rd push button to apply k means still i got no problem but it shows a blank white image in 3rd axes instead of showing the image on which i applied k means.
i have also checked my k means code in command window and it working fine and displaying the desired image but when i transfer it to gui im having problems..
please help guys !!
  1 Comment
Walter Roberson
Walter Roberson on 22 Jun 2012
It might be useful for you to read http://www.mathworks.com/matlabcentral/answers/22208-show-figure

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 22 Jun 2012
Check the class and ranges of your variables. Make sure they're all legal. In particular if you display a double image it must be in the range 0-1 unless you use the [] option in imshow.
imshow(doubleImage, []);
  3 Comments
Image Analyst
Image Analyst on 22 Jun 2012
show your code using a standard MATLAB demo image.
Rao
Rao on 22 Jun 2012
function varargout = imsec(varargin)
% IMSEC MATLAB code for imsec.fig
% IMSEC, by itself, creates a new IMSEC or raises the existing
% singleton*.
%
% H = IMSEC returns the handle to a new IMSEC or the handle to
% the existing singleton*.
%
% IMSEC('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMSEC.M with the given input arguments.
%
% IMSEC('Property','Value',...) creates a new IMSEC or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before imsec_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to imsec_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help imsec
% Last Modified by GUIDE v2.5 22-Jun-2012 21:15:33
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @imsec_OpeningFcn, ...
'gui_OutputFcn', @imsec_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before imsec is made visible.
function imsec_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to imsec (see VARARGIN)
% Choose default command line output for imsec
set(handles.axes1,'Visible','off');
%set(handles.axes9,'Visible','off');
set(handles.axes10,'Visible','off');
set(handles.axes11,'Visible','off');
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes imsec wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = imsec_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,PathName] = uigetfile({'*.*'},'Load Image File');
if (FileName==0) % cancel pressed
return;
end
handles.fullPath = [PathName FileName];
[a, b, Ext] = fileparts(FileName);
availableExt = {'.bmp','.jpg','.jpeg','.tif','.png','.gif'};
FOUND = 0;
for (i=1:length(availableExt))
if (strcmpi(Ext, availableExt{i}))
FOUND=1;
break;
end
end
if (FOUND==0)
h = msgbox('File type not supported!','Error','error');
return;
end
%set(handles.sliderRotate, 'Enable', 'on');
%set(handles.sliderBright, 'Enable', 'on');
%set(handles.sliderContrast, 'Enable', 'on');
%set(handles.editPath, 'Visible', 'on');
%set(handles.editSize, 'Visible', 'on');
%set(handles.editComment, 'Visible', 'on');
%info = imfinfo(handles.fullPath);
%if (~isempty(info.Comment))
% save current image comment (to be used later in image save)
% handles.currentImageComment = info.Comment{1};
%else
% handles.currentImageComment = '';
%end
%set(handles.editSize, 'String', sprintf('SIZE (W x H) : %d x %d', info.Width, info.Height));
%set(handles.editComment, 'String', sprintf('COMMENT: %s', handles.currentImageComment));
%set(handles.editPath', 'String', handles.fullPath);
RGB = imread(handles.fullPath);
handles.RGB = RGB;
handles.RGB2 = RGB;
handles.fileLoaded = 1;
handles.fileLoaded2 = 0;
%set(handles.axes1,'Visible','off'); set(handles.axes2,'Visible','off');
%set(handles.axesHist1,'Visible','off'); set(handles.axesHist2,'Visible','off');
%set(handles.textHist1, 'Visible', 'off');
%axes(handles.axesHist2); cla;
%set(handles.textHist2, 'Visible', 'off');
axes(handles.axes1); cla; imshow(RGB);
axes(handles.axes10); cla;
axes(handles.axes11); cla;
%handles = updateHistograms(handles);
guidata(hObject, handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.rgb=imread('C:\Users\Rao\Desktop\unused icons\backgrounds\birdie.png');
[handles.indexed,handles.indmap]=rgb2ind(handles.rgb,8);
axes(handles.axes9);
cla;
imagesc(handles.indexed);
colormap(handles.axes9,handles.indmap);
set(handles.axes9,'Visible','off');
axis image;
guidata(hObject, handles);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
YCBCR = rgb2ycbcr(handles.RGB);
axes(handles.axes10);
cla;
imshow(YCBCR);
set(handles.axes10,'Visible','off');
axis image;
handles.YCBCR = YCBCR;
guidata(hObject, handles);
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%inImgname = 'birdie';%Input Image name
%ext = '.png';%File Extension of Input Image
noOfColors = 16;%Number of colors to be present in the output
%Warning
%The program execution time will be high, if noOfColors is greater than 64.
%Input Image name
%inImgPath = [inImgname, ext];
%Read Input Image
%[ImgMat, inMap] = imread('handles.indexed');
s_img = size(handles.YCBCR);
%s_map = size(handles.indmap);
%if(s_map(1) == 0)
%sRGB Color Image
% inImg = ImgMat;
%else
%Indexed Color Image
%inImg = ind2rgb(ImgMat, inMap);
%inImg = round(inImg .* 255);
%end
inImg = handles.YCBCR;
%K-Means
y = inImg(:,:,1);
cb = inImg(:,:,2);
cr = inImg(:,:,3);
inputImg = zeros((s_img(1) * s_img(2)), 3);
inputImg(:,1) = y(:);
inputImg(:,2) = cb(:);
inputImg(:,3) = cr(:);
inputImg = double(inputImg);
disp('K-Means Processing Started');
[idx, C] = kmeans(inputImg, noOfColors, 'EmptyAction', 'singleton');
disp('K-Means Processing Completed');
palette = round(C);
%Color Mapping
idx = uint8(idx);
outImg = zeros(s_img(1),s_img(2),3);
temp = reshape(idx, [s_img(1) s_img(2)]);
for i = 1 : 1 : s_img(1)
for j = 1 : 1 : s_img(2)
outImg(i,j,:) = palette(temp(i,j),:);
end
end
rgbimage=ycbcr2rgb(uint8(outImg));
axes(handles.axes11);
cla;
handles.outImg = outImg;
imshow(outImg,'handles.YCBCR');
%hObject = imshow(outImg);
set(handles.axes11,'Visible','off');
axis image;
guidata(hObject, handles);
%Writting Output Image file
%outFilename = [inImgname, '_', int2str(noOfColors), ext];
%imwrite(uint8(outImg), outFilename);
%Writting Color Palette as a CSV file
%OutCSVName = [inImgname, '_', int2str(noOfColors), '_Palette' '.csv'];
%writeCSV(palette, OutCSVName);

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!