Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

Getting error in Matlab while try to plot the values from a row of the image

I want to write a code in Matlab. There is a picture of size (258, 320). It is a color picture. I want to show the image using one color channel. Try to plotting the values from a row of the image.

% Color planes
img = imread('fruit.png');
imshow(img);

disp(size(img));

% TODO: Select a color plane, display it, inspect values from a row
img_blue = img(:,:,2);
imshow(img_blue);
plot(img_blue(150,0));

I got this error error: img_blue(_,0): subscripts must be either integers 1 to (2^31)-1 or logicals error: execution exception in main.m

Can anyone please help m to overcome the problem.

question from:https://stackoverflow.com/questions/65894818/getting-error-in-matlab-while-try-to-plot-the-values-from-a-row-of-the-image

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your problem is the fact that you're using the indexing from, I guess, Python (as in between 0 and N-1) while Matlab uses indexes starting from 1.

So if you want to plot the first plane, it will be plot(img_blue(150, 1)); instead of plot(img_blue(150, 0));. Similarly, blue is the third main color, so it will actually be img_blue = img(:, :, 3); instead of img_blue = img(:, :, 2);.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...