Calculating average intensity value of BW image using Matlab - matlab

I have a BW image. I have to calculate the average intensity of that image. For this I have to store individual intensity value of all pixels of that image then calculate average intensity. In this calculation I have to count only the non zero pixel's intensity value (full black pixel i.e. intensity value zero should not take in calculation). How can I do that?

You can try this, but this doesn't work if any columns of the image are all 0!
im=imread('imageBW.jpg');
intensity=mean(sum(im)./sum(im~=0));

Related

How to calculate linear index of fuzziness of an image?

i am trying to calculate linear index of fuzziness of an image using this formula:
i have to see a positive y value according to the paper. But i see a negative value, so i think i am doing something wrong. here is my try. and my output_image
q=(pi/2)*(1-output_image/255); %I is output image and 255 is maximum gray level. output_iamge is 288*384 double and grayscale image
y= sum(sum(min(q,1-q)))/(width*height); %M*N is width*height

center pixel of a group neighbored of pixels in a sparse image

I want to do in matlab the following: I have a sparse image that have some values representing an elliptic region. I want to find the center pixel of these valued pixels. I can't use any ellipse or circle equation in that as the region is not regular, but all pixels are adjacent.

How to search a gray scale image?

I have 10 gray scale images<2559*3105>. These images are taken from X-ray reflectivity measurement. Each image has two spots except first, showing intensity of X-ray. First image has one highest intensity spot. From second to tenth image each has two spots first one is same as in the first image but second one differs with respect to the location and intensity value. I want to search and crop these spots. The problem is when i apply a condition that find() maximum intensity point in the image, it always points to the spot which is common in all images.
here's some basic image processing code that allows you to select the indices of the spots
%# read the image
im=rgb2gray(imread('a.jpg'));
%# select only relevant area
d=im(5:545,5:660);
%# set a threshold and filter
thres = (max([min(max(d,[],1)) min(max(d,[],2))])) ;
filt=fspecial('gaussian', 7,1);
% reduce noise threshold and smooth the image
d=medfilt2(d);
d=d.*uint8(d>thres);
d=conv2(double(d),filt,'same') ;
d=d.*(d>thres);
% find coonected objets 1
L = bwlabel(d);
%# or also
CC = bwconncomp(d);
Both L and CC have information about the indices of the 2 blobs, so you can now select only that part of the image using them

Distribution of pixel intensity in percentage plot

I am trying to plot the pixel intensity in percentage of a gray scale image. I have done the preprocessing part of scaling and equalization of the gray image.
I know he histogram plot gives the pixel intensity distribution along the Y axis but i want that in percentage.
Any help is appreciated.
The code i used is here
clc;
close all;
clear all;
I=imread('sand5.jpg');
j=rgb2gray(I);
figure,imshow(j);
J=scale_image(j,1);
figure,imshow(J);
K=histeq(J);
figure,imshow(K);
I need the plot for Pixel intensity distribution in percentage VS pixel intensity values(0-255) along x axis for the gray scale image.
You need to compute the histogram
nn = hist( K(:), 0:255 ); % histogram for 0..255 bins
Now nn counts the number of pixels at each bin. To get the percentage you only need to divide by the total number of pixels (numel(K)) and multiply by 100.
figure;
bar( 0:255, nn*numel(K)/100 );
title('pixel intensity distribution (%)');
xlabel('intensity level');
ylabel('%');

Matlab - Replace successive pixel with pixel from the left

So, I've quantized a grayscale image with four quantized values. I'm trying to maintain the first pixel of each row of the quantized image and replace each successive pixel with the difference from the pixel to its left.
How would you code this in matlab and can someone explain this to me conceptually?
Also, my concern is that because the image is relatively uniform because of the quantization of the dynamic range, most of the image would appear black, no? It seems to me that only the transition areas and the edges will have some difference in quantized values.
To create the difference to the pixel on the left, all you have to do is subtract the pixels in columns 1,2,3... from the columns 2,3,4...
%# create a random image with four values
randomImage = randi(4,[100,90]); %# use different numbers of rows and cols so we know which is which
%# catenate the first column of the image with the difference from the pixel to the left
%# for all pairs of columns in the image
differenceImage = [randomImage(:,1),randomImage(:,1:end-1)-randomImage(:,2:end)];
Yes, you'd expect quite a few uniform patches (which will be gray, since unless you plot the absolute value of the differences, there will be some that are negative).