Hello,
I am trying to save the pixel color values of an image in a matrix after uploading it on GUI.
First I choose the image with the browser button. I wrote a function, that firtst converts the image in gray and then saves using a for loop all pixel values in the Matrix pixelValues.
I receive the error "Index exceeds matrix dimensions."
Here is my code for the browser button
% --- Executes on button press in browser.
function browser_Callback(hObject, eventdata, handles)% hObject handle to browser (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[a b] = uigetfile({'*.jpg';'*.png';'*.bmp'},'File Selector');image = imread([b a]);axes(handles.axes)imshow(image)axis onyLimits = get(gca,'YLim'); %# Get the y axis limits
yTicks = yLimits(2)-get(gca,'YTick'); %# Get the y axis tick values and
%# subtract them from the upper limit
set(gca,'YTickLabel',num2str(yTicks.')); %'# Convert the tick values to strings
%# and update the y axis labels
A = savePixelValues(image);
And here is the function :
function [pixelValues] = savePixelValues(image)[x,y,z] = size(image);I = rgb2gray(image);v = zeros(1,3);A = zeros(y,x);for i=1:y for j=1:x v = squeeze(I(i,j,:)); pixelValues(i,j) = v(1); endendend
Can someone help me please?
Best Answer