I a trying to plot the area of the connected components at a specific threshold against their intensity level in grayscale.

The code I came up with tries to accomplish this by first converting a text image to binary at a selected threshold, and find the area using `regionprops`, convert this image back to grayscale. I then found the intensity levels using `hist`. then plot the intensity versus the area. This basically gives me an intensity vector of roughly 6000 elements and the connected components are only 513. When I try `plot` I get the following error:

> 
> ??? Error using ==> plot
>  Vectors must be the same lengths.
> 
> 
> 

Here is my code

```
 img = rgb2gray(imread('urdu.jpg'));

for k = 0:0.01:1
    bw_normal = im2bw(img, k);
    bw = imcomplement(bw_normal);
    [label,n] = bwlabel(bw);
    stats = regionprops(label, 'Area');
    gray = double(bw_normal);
    h = hist(gray);
    h = h(:);
    plot([stats.Area],h);
    %axis([0 350 0 1.1])
    hold on;
end

```

So as you can tell I am trying to find the area of connected component at increments of threshold.

Is my implementation of the challenge wrong? Can this be done any other way? 

Just to make it clear, the end product is supposed to look like this:

![enter image description here](https://i.stack.imgur.com/JFfcX.jpg)