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

回答(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 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by