Thread Subject: CLAHE-error

Subject: CLAHE-error

From: Poh Choo

Date: 16 Nov, 2009 13:59:18

Message: 1 of 21

i receive an error stated 'Index exceeds matrix dimensions'.

Error in ==> ind2rgb at 27
r = zeros(size(a)); r(:) = cm(a,1);
what is wrong?how to fix it?

My command is:
clc
[X,map] = imread('C:\Documents and Settings\pohchoo\My Documents\wbc.bmp');

RGB = ind2rgb(X,map);

% Convert image to L*a*b* color space
cform2lab = makecform('srgb2lab');
LAB = applycform(RGB, cform2lab);

% Scale values to range from 0 to 1
L = LAB(:,:,1)/100;

% Perform CLAHE
LAB(:,:,1) = adapthisteq(L,'NumTiles',...
                         [8 8],'ClipLimit',0.005)*100;

% Convert back to RGB color space
cform2srgb = makecform('lab2srgb');
J = applycform(LAB, cform2srgb);

% Display the results
figure, imshow(RGB);
figure, imshow(J);

Hope 2 get your reply soon.
Thank you.

Subject: CLAHE-error

From: Steve Eddins

Date: 16 Nov, 2009 14:38:09

Message: 2 of 21

Poh Choo wrote:
> i receive an error stated 'Index exceeds matrix dimensions'.
>
> Error in ==> ind2rgb at 27
> r = zeros(size(a)); r(:) = cm(a,1);
> what is wrong?how to fix it?
>
> My command is:
> clc
> [X,map] = imread('C:\Documents and Settings\pohchoo\My Documents\wbc.bmp');
>
> RGB = ind2rgb(X,map);
>
> % Convert image to L*a*b* color space
> cform2lab = makecform('srgb2lab');
> LAB = applycform(RGB, cform2lab);
>
> % Scale values to range from 0 to 1
> L = LAB(:,:,1)/100;
>
> % Perform CLAHE
> LAB(:,:,1) = adapthisteq(L,'NumTiles',...
> [8 8],'ClipLimit',0.005)*100;
>
> % Convert back to RGB color space
> cform2srgb = makecform('lab2srgb');
> J = applycform(LAB, cform2srgb);
>
> % Display the results
> figure, imshow(RGB);
> figure, imshow(J);
>
> Hope 2 get your reply soon.
> Thank you.

Your subject line says "CLAHE-error" but the error message says the
problem occurred several lines before you call adapthisteq. Hmm.

Anyway, the error message suggests to me that you might have a bad image
file. Specifically, the colormap contained in the file might have too
few colors for the image.

You can check to see whether this is true:

X_max = max(X(:));
num_colors = size(map, 1);
bad_image_file = X_max >= num_colors

---
Steve Eddins
http://blogs.mathworks.com/steve/

Subject: CLAHE-error

From: Freyssineta

Date: 12 May, 2011 06:59:04

Message: 3 of 21

"Steve Eddins" wrote in message <hdro4i$qgu$1@fred.mathworks.com>...
> Poh Choo wrote:
> > i receive an error stated 'Index exceeds matrix dimensions'.
> >
> > Error in ==> ind2rgb at 27
> > r = zeros(size(a)); r(:) = cm(a,1);
> > what is wrong?how to fix it?
> >
> > My command is:
> > clc
> > [X,map] = imread('C:\Documents and Settings\pohchoo\My Documents\wbc.bmp');
> >
> > RGB = ind2rgb(X,map);
> >
> > % Convert image to L*a*b* color space
> > cform2lab = makecform('srgb2lab');
> > LAB = applycform(RGB, cform2lab);
> >
> > % Scale values to range from 0 to 1
> > L = LAB(:,:,1)/100;
> >
> > % Perform CLAHE
> > LAB(:,:,1) = adapthisteq(L,'NumTiles',...
> > [8 8],'ClipLimit',0.005)*100;
> >
> > % Convert back to RGB color space
> > cform2srgb = makecform('lab2srgb');
> > J = applycform(LAB, cform2srgb);
> >
> > % Display the results
> > figure, imshow(RGB);
> > figure, imshow(J);
> >
> > Hope 2 get your reply soon.
> > Thank you.
>
> Your subject line says "CLAHE-error" but the error message says the
> problem occurred several lines before you call adapthisteq. Hmm.
>
> Anyway, the error message suggests to me that you might have a bad image
> file. Specifically, the colormap contained in the file might have too
> few colors for the image.
>
> You can check to see whether this is true:
>
> X_max = max(X(:));
> num_colors = size(map, 1);
> bad_image_file = X_max >= num_colors
>
> ---
> Steve Eddins
> http://blogs.mathworks.com/steve/

I also got an error when execute runCLAHE.m
The error is "Subscript indices must either be real positive integers or logicals"
what should i do?
I didn't allowed to use tool adapthisteq with my lecturer. so I must make code manually.
Any suggestion guys?

Subject: CLAHE-error

From: ImageAnalyst

Date: 12 May, 2011 10:42:22

Message: 4 of 21

On May 12, 2:59 am, "Freyssineta " <pinklover_161...@yahoo.com> wrote:
> I also got an error when execute runCLAHE.m
> The error is "Subscript indices must either be real positive integers or logicals"
> what should i do?
> I didn't allowed to use tool adapthisteq with my lecturer. so I must make code manually.
> Any suggestion guys?

-------------------------------------------------------------------------------------------
I guess you should use the debugger. Does that sound reasonable?
You probably have a real number with a fractional part as one of your
indexes.
You can't have the 123.456th index - it has to be 123 or 124, not some
fractional amount.

Subject: CLAHE-error

From: juli qwer

Date: 12 May, 2011 10:58:05

Message: 5 of 21

I faced a similar problem. I found the answer here-<a href="http://essaywritingservices.org/essay-writing.php">help with essays</a>

Subject: CLAHE-error

From: ImageAnalyst

Date: 12 May, 2011 12:16:05

Message: 6 of 21

On May 12, 6:58 am, "juli qwer" <lopezmar...@yahoo.com> wrote:
> I faced a similar problem. I found the answer here-<a href="http://essaywritingservices.org/essay-writing.php">help with essays</a>
-----------------------------------
Then you're an absolute idiot.

Subject: CLAHE-error

From: Steven_Lord

Date: 12 May, 2011 13:18:15

Message: 7 of 21



"ImageAnalyst" <imageanalyst@mailinator.com> wrote in message
news:e1299e50-ce2b-441d-acc5-7d705587e5e6@j13g2000pro.googlegroups.com...
> On May 12, 6:58 am, "juli qwer" <*snip*> wrote:
>> I faced a similar problem. I found the answer here-*snip URL*
> -----------------------------------
> Then you're an absolute idiot.

No need to advertise for what appears to be a link spammer. Don't forget to
use the power of the *snip*

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: CLAHE-error

From: Freyssineta

Date: 13 May, 2011 17:05:08

Message: 8 of 21

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <6a554d72-e553-4290-ad4b-16752579fd33@f11g2000vbx.googlegroups.com>...

> -------------------------------------------------------------------------------------------
> I guess you should use the debugger. Does that sound reasonable?
> You probably have a real number with a fractional part as one of your
> indexes.
> You can't have the 123.456th index - it has to be 123 or 124, not some
> fractional amount.

I've use round function to make it a real number and there is no error anymore. But the image result becomes all white. I thougt that something wrong with the code.
anyone know what should i change with that code?

Subject: CLAHE-error

From: Freyssineta

Date: 13 May, 2011 17:06:02

Message: 9 of 21

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <6a554d72-e553-4290-ad4b-16752579fd33@f11g2000vbx.googlegroups.com>...

> -------------------------------------------------------------------------------------------
> I guess you should use the debugger. Does that sound reasonable?
> You probably have a real number with a fractional part as one of your
> indexes.
> You can't have the 123.456th index - it has to be 123 or 124, not some
> fractional amount.

I've use round function to make it a real number and there is no error anymore. But the image result becomes all white. I thougt that something wrong with the code.
anyone know what should i change with that code?

Subject: CLAHE-error

From: ImageAnalyst

Date: 13 May, 2011 17:30:04

Message: 10 of 21

On May 13, 1:06 pm, "Freyssineta " <pinklover_161...@yahoo.com> wrote:
> I've use round function to make it a real number and there is no error anymore. But the image result becomes all white. I thougt that something wrong with the code.
> anyone know what should i change with that code?
------------------------------------------------------------
Freyssineta :
Why do you say the image is all white? Did you check the values in
the variable editor? Did you take the histogram? Did you check the
min and max values and see that they are identical? What does it say
when you do this

minValue = min(min(imageArray))
maxValue = max(max(imageArray))
What does it put into the command window?
Maybe it just *appears* all white because you have a floating point
image and you're doing
imshow(imageArray);
instead of
imshow(imageArray, []);

If you do it the first way, then imshow() assumes that your image will
be in the range 0-1 and anything over 1 will be clipped and show up as
white.
Check those things out and get back to me.
ImageAnalyst

Subject: CLAHE-error

From: Freyssineta

Date: 23 May, 2011 18:55:20

Message: 11 of 21

> ------------------------------------------------------------
> Freyssineta :
> Why do you say the image is all white? Did you check the values in
> the variable editor? Did you take the histogram? Did you check the
> min and max values and see that they are identical? What does it say
> when you do this
>
> minValue = min(min(imageArray))
> maxValue = max(max(imageArray))
> What does it put into the command window?
> Maybe it just *appears* all white because you have a floating point
> image and you're doing
> imshow(imageArray);
> instead of
> imshow(imageArray, []);
>
> If you do it the first way, then imshow() assumes that your image will
> be in the range 0-1 and anything over 1 will be clipped and show up as
> white.
> Check those things out and get back to me.
> ImageAnalyst

Hey now the image result isn't all white anymore. it's like these photo http://www.flickr.com/photos/55371092@N08/5751446749/ and the histogram is http://www.flickr.com/photos/55371092@N08/5751446853/
but i think it's already something wrong with the code because the image is different between my code with adapthisteq in matlab.
If i use the adapthisteq in matlab the result will be like this http://www.flickr.com/photos/55371092@N08/5752018148/in/photostream and the histigram is http://www.flickr.com/photos/55371092@N08/5751473147/in/photostream

In This below i post the code of CLAHE that i use

------------------------------------------------------------------------------------------------------------------------
function [CEImage] = runCLAHE(image,XRes,YRes,Min,Max,NrX,NrY,NrBins,Cliplimit)

% "Contrast Limited Adaptive Histogram Equalization"
% by Karel Zuiderveld, karel@cv.ruu.nl
% in "Graphics Gems IV", Academic Press, 1994
% (Ported to Matlab by Leslie Smith)
%
% These functions implement Contrast Limited Adaptive Histogram
% Equalization.
% The main routine (CLAHE) expects an input image that is stored contiguously in
% memory; the CLAHE output image overwrites the original input image and has the
% same minimum and maximum values (which must be provided by the user).
% This implementation assumes that the X- and Y image resolutions are an integer
% multiple of the X- and Y sizes of the contextual regions. A check on various other
% error conditions is performed.
%
%
% Image - The input/output image
% XRes - Image resolution in the X direction
% YRes - Image resolution in the Y direction
% Min - Minimum greyvalue of input image (also becomes minimum of output image)
% Max - Maximum greyvalue of input image (also becomes maximum of output image)
% NrX - Number of contextial regions in the X direction (min 2, max uiMAX_REG_X)
% NrY - Number of contextial regions in the Y direction (min 2, max uiMAX_REG_Y)
% NrBins - Number of greybins for histogram ("dynamic range")
% Cliplimit - Normalized cliplimit (higher values give more contrast)
% The number of "effective" greylevels in the output image is set by uiNrBins; selecting
% a small value (eg. 128) speeds up processing and still produce an output image of
% good quality. The output image will have the same minimum and maximum value as the input
% image. A clip limit smaller than 1 results in standard (non-contrast limited) AHE.

 [XRes,YRes]=size(image);
% CEimage = Image;
CEImage = zeros(XRes,YRes);
if Cliplimit == 1
    return
end

NrBins=max(NrBins,128);
XSize = round(XRes/NrX);
YSize = round(YRes/NrY);
NrPixels = XSize*YSize;
XSize2 = round(XSize/2);
YSize2 = round(YSize/2);

if Cliplimit > 0
    ClipLimit = max(1,Cliplimit*XSize*YSize/NrBins);
else
    ClipLimit = 1E8;
end

LUT=makeLUT(Min,Max,NrBins);
% avgBin = NrPixels/NrBins;

convert2double = double(image) + 1;
%convert2uint = (uint8(convert2double.*double(image)));
Bin= 1+ LUT(convert2double);

Hist = makeHistogram(Bin,XSize,YSize,NrX,NrY,NrBins);
if Cliplimit > 0
    Hist = clipHistogram(Hist,NrBins,ClipLimit,NrX,NrY);
end
Map=mapHistogram(Hist,Min,Max,NrBins,NrPixels,NrX,NrY);

%convert2uint=(uint8(Bin.*double(image)));
% Interpolate
xI = 1;
for i = 1:NrX+1
    if i == 1
        subX = XSize/2;
        xU = 1;
        xB = 1;
    elseif i == NrX+1
        subX = XSize/2;
        xU = NrX;
        xB = NrX;
    else
        subX = XSize;
        xU = i - 1;
        xB = i;
    end
    yI = 1;
    for j = 1:NrY+1
        if j == 1
            subY = YSize/2;
            yL = 1;
            yR = 1;
        elseif j == NrY+1
            subY = YSize/2;
            yL = NrY;
            yR = NrY;
        else
            subY = YSize;
            yL = j - 1;
            yR = j;
        end
        UL = Map(xU,yL,:);
        UR = Map(xU,yR,:);
        BL = Map(xB,yL,:);
        BR = Map(xB,yR,:);
        subImage = Bin(xI:xI+subX-1,yI:yI+subY-1);
        subImage = interpolate(subImage,UL,UR,BL,BR,subX,subY);
        CEImage(xI:xI+subX-1,yI:yI+subY-1) = subImage;
        yI = yI + subY;
    end
    xI = xI + subX;
end
------------------------------------------------------------------------------------------------------------------------

I need your help guys. Big Big thanks before :)

Subject: CLAHE-error

From: ImageAnalyst

Date: 23 May, 2011 19:33:17

Message: 12 of 21

Off the top of my head I'd say it's a class issue. Like you're having
something be a uint8 when it should be a double and so you're getting
clipping, or you're displaying a double with imshow and it's not in
the range 0-1, or something like that.

Subject: CLAHE-error

From: Freyssineta

Date: 24 May, 2011 02:14:04

Message: 13 of 21

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <38c61d14-54f0-4b94-8c09-1249585ef7eb@j31g2000yqe.googlegroups.com>...
> Off the top of my head I'd say it's a class issue. Like you're having
> something be a uint8 when it should be a double and so you're getting
> clipping, or you're displaying a double with imshow and it's not in
> the range 0-1, or something like that.

so what should I do sir? I've stuck with this problem for a month and I really confused.

Subject: CLAHE-error

From: ImageAnalyst

Date: 24 May, 2011 02:20:18

Message: 14 of 21

Well give us some code we can run. If I call
[CEImage] =
runCLAHE(image,XRes,YRes,Min,Max,NrX,NrY,NrBins,Cliplimit)
then what are all those values that you're using?

Come on, make it easy for me. Just give me something I can copy and
paste to illustrate your errors.

By the way, it's very very bad to use image as an input name argument
- doing that overrides the built-in image function.

Subject: CLAHE-error

From: Freyssineta

Date: 24 May, 2011 03:22:02

Message: 15 of 21

okay i have been uploaded all function that I use for CLAHE code in http://www.mediafire.com/?q7f95k2w3i512zj

thanks before :)

Subject: CLAHE-error

From: Freyssineta

Date: 4 Jun, 2011 02:10:05

Message: 16 of 21

hey anyone know the solution?
i didn't find the solution till now
please help
thank you

Subject: CLAHE-error

From: ImageAnalyst

Date: 4 Jun, 2011 02:24:44

Message: 17 of 21

On Jun 3, 10:10 pm, "Freyssineta " <pinklover_161...@yahoo.com> wrote:
> hey anyone know the solution?
> i didn't find the solution till now
> please help
> thank you

---------------------------------------------------------------
I asked you to make it easy. Sorry, but I don't seem to have any
program on my computer that knows anything about rar files, and I
don't want to go searching for one and install a new program on my
computer just to help you. Can you upload the original files, or
upload a .zip file?

Subject: CLAHE-error

From: Freyssineta

Date: 4 Jun, 2011 02:55:20

Message: 18 of 21

> ---------------------------------------------------------------
> I asked you to make it easy. Sorry, but I don't seem to have any
> program on my computer that knows anything about rar files, and I
> don't want to go searching for one and install a new program on my
> computer just to help you. Can you upload the original files, or
> upload a .zip file?

okay, i've uploaded .zip file in here http://www.mediafire.com/?j2iik99nclc6chi
sorry if i didn't posted the code here because there are a lot of code so my post will be so long.

Subject: CLAHE-error

From: ImageAnalyst

Date: 4 Jun, 2011 03:51:11

Message: 19 of 21

It ran fine for me and displayed fine for me. I suspect you ignored
what I told you in a much earlier response and that was to display
your image like this:
 imshow(CEImage, []);

This is what I did and it displayed a good image. If you ignore what
I said and just do this:
 imshow(CEImage)
then it will show as black and white because that expects the image to
be in the range 0-1. Recall that I said earlier:

"Maybe it just *appears* all white because you have a floating point
image and you're doing
imshow(imageArray);
instead of
imshow(imageArray, []);

If you do it the first way, then imshow() assumes that your image will
be in the range 0-1 and anything over 1 will be clipped and show up as
white.
Check those things out and get back to me."

So if there's still something wrong that my response of May 13 doesn't
fix, let me know what it is.

Subject: CLAHE-error

From: Freyssineta

Date: 4 Jun, 2011 04:56:04

Message: 20 of 21

ouch, sorry sir because i don't understand what do you mean before.
i applied your suggestion to run imshow(CEImage, []);
yeah it look fine but the problem now, the result is different if i use adapthisteq in matlab even i use same inputs/parameters.
what's wrong with my code sir?

Subject: CLAHE-error

From: ImageAnalyst

Date: 4 Jun, 2011 13:02:43

Message: 21 of 21

On Jun 4, 12:56 am, "Freyssineta " <pinklover_161...@yahoo.com> wrote:
> ouch, sorry sir because i don't understand what do you mean before.
> i applied your suggestion to run imshow(CEImage, []);
> yeah it look fine but the problem now, the result is different if i use adapthisteq in matlab even i use same inputs/parameters.
> what's wrong with my code sir?

---------------------------------------------------------------------
Well they were written by different people, so it's possible that
there may be slight differences in the exact values. Sorry but I
don't have time to go over the code with a fine toothed comb. Even if
I did, I don't believe I have the adapthisteq source code. Sometimes
they give a little bit but often when you drill down too deep, MATLAB
ends up call in a DLL and you can't dig any further.

Just pick whichever one you think does the best job for your images.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
clahe error Freyssineta 12 May, 2011 02:59:07
rssFeed for this Thread

Contact us at files@mathworks.com