How to get pixel values in matrix form?

11 ビュー (過去 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 Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by