필터 지우기
필터 지우기

How to figure a colour based on a matrice of 1-by-3

조회 수: 1 (최근 30일)
arman Yaraee
arman Yaraee 2011년 10월 20일
This is my code:
%%In this part we just find the coordinates of the required colours
im = imread('Lighthouse.jpg');
n = 4;
figure, imshow(im)
[x,y] = ginput(n);
x = floor(x);
y = floor(y);
%colour(length(x),3);
for i=1:length(x)
for j=1:3
colour(i,j) = im(y(i),x(i),j);
end
end
image(colour)
when I run it, and slect a point on the image it doesn't show me the colour I selected!! it figures a red colour!! why is that? the variable colour is [195,213,223]
how can I visualize that RGB colour?

채택된 답변

Image Analyst
Image Analyst 2011년 10월 20일
Well you messed up in a couple of places. Try this:
im = imread('peppers.png');
n = 4;
figure, imshow(im)
[x,y] = ginput(n);
x = floor(x);
y = floor(y);
%colour(length(x),3);
colour = zeros(length(x), 1, 3, 'uint8');
for i=1:length(x)
for j=1:3
colour(i,1, j) = im(y(i),x(i),j);
end
end
image(colour)
  댓글 수: 1
arman Yaraee
arman Yaraee 2011년 10월 21일
yes my friend thank you. I figured it out last night! my problem was making colour 2-D array. I should make it a 3-D array in order to make this work!
Also thanks a lot. your way is better than mine.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

the cyclist
the cyclist 2011년 10월 20일
Divide by 255. MATLAB uses the convention of RGB values from (0,1). This was discussed on this forum a few weeks ago, but for some reason I can't find it.
  댓글 수: 1
arman Yaraee
arman Yaraee 2011년 10월 20일
sorry I didn't undrestand the word u just said! I am new to matlab. I tried dviding it by 255. it become a matrice from 0-1. this is the amount of brightness. my question is how to visualize the matrice colour as a color so I can see it works!

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 10월 20일
Before the loop, initialize
colour = zeros(length(x),3, 'uint8');
You will then not need to do the division by 255 that The Cyclist refers to.
  댓글 수: 2
arman Yaraee
arman Yaraee 2011년 10월 20일
Thank you very much myfriend. tanks for pointing out the bug. but my problem still there! still when I call
image(colour);
I don't get the colour I selected. I see 3 bars of colors. sometimes, blue, yellow red or just one of these with different brightness!
Walter Roberson
Walter Roberson 2011년 10월 20일
You are selecting 4 points so you should be getting 4 colors.
You need to check whether your file is RGB (truecolor) or an indexed image (2D but you have to read in the colormap as well.)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by