필터 지우기
필터 지우기

How to get pixel values in matrix form?

조회 수: 16 (최근 30일)
Avinash Bhatt
Avinash Bhatt 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 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
KALYAN ACHARJYA 2019년 5월 26일
편집: KALYAN ACHARJYA 2019년 5월 26일
Those pixels are less than 80, what you do.?

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

답변 (2개)

KALYAN ACHARJYA
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
Avinash Bhatt
Avinash Bhatt 2019년 5월 26일
this code is displaying all the values greater than 80 in the command window whereas only one value in the workspace which is the last value
KALYAN ACHARJYA
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
Avinash Bhatt 2019년 5월 26일
Sir,
This is the snapshot of what I am trying to do
when I am invoking for loop for extracting the pixels greater than 80 then in command window I have
83
82
84
while in workspace I get only 84 but I need the result in matrix as X=[83 82 84] for further processingUntitled.png
  댓글 수: 1
KALYAN ACHARJYA
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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by