MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# To find energy of each pixel from an image

Asked by susithra dhanavel on 14 Feb 2013

Hi...iI have two images: one is original image(input image) another is gradient image. Then I found energy of each pixel from the gradient image using the formula E=R^2+G^2+B^2.

Then I want to find max energy for that I used code E_max=max(max(E));

only those pixels whose energy larger than a predefined percentage of E_max want to be selected...the threshold values 90%, 80%, 70% from E_max were used for testing....then the pixels which passed the X% threshold were retained from the original image...

```I=original image
GP=gradient image.^2; % for finding energy
```
```E_max=max(max(GP));   % for finding max energy
T=0.8*E_max;          % 80% threshold of max energy
```
```index=find(GP>T);
for k=1:size(index,1)
end
```

## 1 Comment

susithra dhanavel on 15 Feb 2013

plz any one help me.. whether the above code is correct or not???

## Products

No products are associated with this question.

Answer by Image Analyst on 15 Feb 2013

The image itself is the energy so I'm not sure why you have that definition. But anyway, your code does what you say up until you get to the find() line. T is your binary mask image of what pixels meet that criteria. But I don't really know what you want to do after that. What does "retain" mean to you? If you just want a 1D vector of all pixels from the original image meeting that criteria, you can do

```thePixels1D = originalImage(T);
```

if you want to zero out pixels notmeeting that criteria, and get a 2D image with other pixels intact, you can do

```outputImage = originalImage; % Make copy of original.
outputImage(~T) = 0; % Blacken pixels not meeting criteria.
```

Image Analyst on 15 Feb 2013

retain means keep. keep and replace are opposites. Please explaing what you want to do. You have in input image. Then you have a binary image that maps out which pixels meet and do not meet your criteria. And you have an output image. What do you want in your output image in the regions that meet the criteria, and for which your binary image is true? What do you want in your output image in the regions that do not meet the criteria, and for which your binary image is false? Please explain clearly this time.

susithra dhanavel on 27 Feb 2013

ya I have to keep only that pixels which meet that criteria in the original image...thanks for your help..

Image Analyst on 27 Feb 2013

```outputImage = originalImage; % Make copy of original.