Iterate through Image histogram data for getting each pixel frequency individually
Afficher commentaires plus anciens
Hi. I am new to matlab. I have created an image histogram using imhist function. Now I want to further process this imhist data.
1. I want to get the frequency(counts) of each pixel.
2. I want to store that frequency value against its pixel location into a new image.
I tried this code:
clc
clear all
close all
x=(im2double(imread('1.jpg')));
I = rgb2gray(x);
[counts,binLocations] = imhist(I)
stem(binLocations,counts);
binN = size(binLocations)
[m,n,r]=size(x);
newimg_l = zeros(m,n);
for ii=1:size(I,1)
for jj=1:size(I,2)
% get pixel value
pixel=I(ii,jj)
disp(pixel)
% check pixel value and assign new value
for n=1:binN;
temp = binLocations(n)
if(pixel == temp)
new_pixel = counts(n)
end
end
% save new pixel value in thresholded image
newimg_l(ii,jj)=new_pixel;
end
end
Please help. Thanks in advance!
Réponses (1)
KALYAN ACHARJYA
le 11 Fév 2019
Modifié(e) : KALYAN ACHARJYA
le 11 Fév 2019
1. I want to get the frequency(counts) of each pixel.
No need of too many loops
count_pixel=length(image_gray(image_gray==pixel_value));
Now apply the single for loop for pixel_value=0:255 and do proper indexing, avoid count_pixel(0)
2. I want to store that frequency value against its pixel location into a new image.
Question 1 gives you, counts the pixel frequency wrt respective pixel value as counts(pixel value)
counts(1)=some value
counts(2)= some value
..........
Sorry I cant undestant the second question, but it seems easy.
Catégories
En savoir plus sur Region and Image Properties dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!