How to get pixel values in matrix form?
조회 수: 12 (최근 30일)
이전 댓글 표시
I am using the following code to obtain the values of an image which are greater than 80 using 3X3 window scanning :
clc
clear all
close all
X=imread('Test.jpg');
iwn=rgb2gray(X);
ind = 0 ;
for ind1 = 1:3
for ind2 = 1:3
if iwn(ind1,ind2)>80
ind = ind + 1 ;
pix_cor(ind,1) = ind1 ;
pix_cor(ind,2) = ind2 ;
%disp([pix_cor(ind,1) pix_cor(ind,2)])
X=pix_val(iwn(pix_cor(ind,1),pix_cor(ind,2)));
disp(X);
end
end
end
In command window X is displayed as
83
82
84
while in the workspace X is displayed as X=84
but I want X as an array i.e X=[83,82,84] in the workspace.
Please help me in achieving this
댓글 수: 1
KALYAN ACHARJYA
2019년 5월 26일
편집: KALYAN ACHARJYA
2019년 5월 26일
Those pixels are less than 80, what you do.?
답변 (2개)
KALYAN ACHARJYA
2019년 5월 26일
편집: KALYAN ACHARJYA
2019년 5월 26일
I am using the following code to obtain the values of an image which are greater than 80
Just do the following one:
image1=imread('Test111.jpg');
grayImage=rgb2gray(image1);
mask=grayImage>80;
result_pixels=grayImage(mask)
댓글 수: 2
KALYAN ACHARJYA
2019년 5월 26일
편집: KALYAN ACHARJYA
2019년 5월 26일
@Avinash Which pixel value you are looking for? No in workspace it shows the size of result_pixels. Doble click on the file you get the all pixels value which are greter than 80 in variables file.
Is it clear?
Avinash Bhatt
2019년 5월 26일
댓글 수: 1
KALYAN ACHARJYA
2019년 5월 26일
편집: KALYAN ACHARJYA
2019년 5월 26일
Are you folloing my code or yours? In my code there id no for loop? I have written the code as per your question description. Share the code, which you have tried.
You have one image? Please note its alreadt in matrix form
Select only those pixels greter than 80
Then extracting the those pixels only which are greater than 80. Now the result cant have the same size matri, because you thrown all those elemnts which having less than 80.
Therefore you get the result in matrix (vector) having size 13878x1.
You can reshape the matrix.
Hope its helps!
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!