How to get pixel values in matrix form?

13 views (last 30 days)
Avinash Bhatt
Avinash Bhatt on 26 May 2019
Edited: KALYAN ACHARJYA on 26 May 2019
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 Comment
KALYAN ACHARJYA
KALYAN ACHARJYA on 26 May 2019
Edited: KALYAN ACHARJYA on 26 May 2019
Those pixels are less than 80, what you do.?

Sign in to comment.

Answers (2)

KALYAN ACHARJYA
KALYAN ACHARJYA on 26 May 2019
Edited: KALYAN ACHARJYA on 26 May 2019
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 Comments
Avinash Bhatt
Avinash Bhatt on 26 May 2019
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 on 26 May 2019
Edited: KALYAN ACHARJYA on 26 May 2019
@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?

Sign in to comment.


Avinash Bhatt
Avinash Bhatt on 26 May 2019
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 Comment
KALYAN ACHARJYA
KALYAN ACHARJYA on 26 May 2019
Edited: KALYAN ACHARJYA on 26 May 2019
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!

Sign in to comment.

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!