last day (3453 days later) » 
14:00 - 21:0021:00 - 23:00

14:57
Hey!
Seulement nous lol... but that's ok.
kkuilla wanted to know how permute works... and I couldn't put that into a comment... better if I make a chat room for that.
Good afternoon @Dan :)
15:24
@AnderBiguri - Make me breakfast with MATLAB :P
@rayryeng load ingredients; Brkf=permute(ingredients(1:3))
hahahahaha
aaah a very simple breakfast :(
well... not necessarily.
ingredients = {'heuvos rancheros', 'chocolate con churros', buñuelos};
then yes, that will be definitely nice.
not so simple!
@thewaywewalk - Guten Tag :) @MohsenNosratinia - Welcome!
Yes! Haha. Nice you created this chatroom.
15:28
I'm surprised why no one else has thought of it. We've been around for how long?
How does it work? will it stay active, like, forever?.
very long!
yes it will, so long as SOMEONE messages lol
I'm the only room owner for now, but I'd like to make those that are currently in the top of the MATLAB tags owners too... so you, and pretty much everyone here.
Ouch! Another distraction from my PhD!
;)
15:45
So, if this is to talk Matlab related topics I will trow the first question. Im working now with a code that takes long time and the longest thing is squeeze(stuff). Stuff is always (1x1xN). A better way of squeezing those dimensions?
*faster!
@AnderBiguri Maybe shiftdim(stuff, 2)?
My tests show 5x speed up
16:09
Why don't you try unrolling?
stuff(:)
@AnderBiguri
16:20
@diegoaguilar - I've edited my answer. Check it out. Don't use histogram. Use bar with the histc flag.
@Daniel - Guten Tag!
16:40
Thanks @rayryeng
Are you a MATLAB enthusiast?
Yes
Also check here: kopy.io/zLLgf
I've edited it slightly.
Sorry this link: kopy.io/xELNe
Just make the image fill up the bottom two grids.
great
thanks
Hmm I have another minor doubt, using #bar
the x axis still shows a range up to 300
of course there's nothing plotted there
how can I trim it to 255
xlim([0,255]);
or, you can do axis tight;
16:50
Let me know if that works.
it worked :)
I also used ylimit
know something better than this?
`ylim([0, max(histogram_values) + 75]);`
that could work.
you're just given it some breathing room for the y axis.
I think what you did is totally fine.
great
Im starting using MATLAB as I've commited to an independent dev group
That's great! I'm glad you're doing that.
I wouldn't say I'm a MATLAB enthusiast... I actually don't use MATLAB where I work lol.
but I've used it quite extensively in the past that it's the language I know the best.
we will try to generate some distributed algorithm for fingerprint database
AND, honestly
16:54
Oh! Let me know how it goes.
I dont see us using MATLAB in production but for research
I agree.
I only use MATLAB for prototyping.
I want to do it all in Python, opencv
Yup... that's what I use at work
I use Python and OpenCV.
sometimes you'll catch me answering some Python/OpenCV questions
So I have a general background in Opencv and general starting point background for image processing
I never did it before, just tests for fun
but nobody said "me" for research and image processing :P
16:55
The OpenCV tutorials are great.
so I did
the Python ones.
hahahaha. nice
hmm, you know I actually have a question on stackoverflow
its actually more opencv's than image processing per se
direct me to it. I'll have a look.
0
Q: How to properly obtain 3 channel histogram with OpenCV?

diegoaguilarI need to compute in one single Mat the color histogram for an image. I know there could be 3 different Mat instances for each channel's histogram but I wonder how correct this approach would be: Mat histogram = new Mat(); MatOfInt histSize = new MatOfInt(256,256,256); MatOfFloat ranges=new MatO...

16:57
Ahhh
it's Java as they asked me to check android support
and I tried that
but I'm not sure it's correct
That code looks like it's computing each colour channel's histograms independently.
If you want a single histogram that consolidates RGB tuples.... check out this post for inspiration
5
A: Content-Based Image Retrieval and Precision-Recall graphs using Color Histograms in MATLAB

rayryengThe code that you have written is comparing the histogram between images, provided that they're grayscale. If you want to do this for RGB images, you need to determine how many bins you want per plane. Once you do this, for each RGB colour triplet that you have, you would determine a linear 1D...

It's written in MATLAB, but the output will give you a single 1D histogram
each unique colour tuple maps to a single index to be incremented into the histogram
however, you definitely need to quantize each colour channel.
doing the full 256 colours per channel would result in a 256^3 colour histogram
and that is too much memory to occupy for a single histogram
it's also too fine for any discriminatory analysis
usually when you have objects of a certain colour, they have a certain variance associated to them.
like some parts of an object look lighter green and darker green in other areas.
quantizing each colour channel will account for this variability.
sure
I understand
I tried with simple gray scale histopgram
but I was having multiple "confusions"
17:00
I understand.
plus, I was just taking one single histogram sample
Could you update an asnwer for the question?
I'll have a look later on today.
I really appreciate stackoverflow's contribution
I don't have much exposure to the Java API for OpenCV.
sure, thanks
17:01
so let me play around with the code, and I can integrate what I wrote in MATLAB into a solution.
not a problem.
well it's Android, hmm I can share you my Android code, it's really not that long
I basically take a sample histogram, store it and then when trying to detect, I iterate each histogram and try to compare
with grayscale it works, let's say a B note
except for some cases
I guess with color histogram I could achieve a B+ or A note
ok
Are you comparing images by looking at histograms?
thanks @rayryeng
yep, I know there are several approaches
but we decided to test over some pictures
art pieces
which defintelly get a fingerprint histogram
now for testing I test a post it on wall, some wine botter over table (same wall behind)
that's why there's some fake positives/negatives
18:04
What's matlab alternative for opencv threshold function
I need to pass like threshold(image, 127)
im2bw
However, you need to make sure that the threshold is normalized with respect to the data type
if your image is uint8, then you would do: out = im2bw(image, 127/255);
However, this will give you a binary image, so if you want to convert back to uint8, simply do: out = 255*uint8(out);
Alternatively, you can just use logical operators
out = 255*uint8(image > 127);
I'm trying imshow(255*uint8(im2bw(image, threshold_value/255)))
@rayryeng schönen Abend
@Daniel - Thanks! Not evening yet lol.
18:13
That's german?
YTes
Yes*
He said good evening
Buenas tardes
Well, "buenas noches"
ah yes :)
It's the infamous MATLAB master @gnovice - Welcome!
18:15
Hey, how's it going?
can't complain. just taking a lunch break.
I actually made this room because I wanted to explain to somebody how permute works.... then I thought to myself that we actually don't have a MATLAB room.
Decided to make one.
@beaker - Welcome!
Not a bad idea
I figured it'd be a space to discuss things that are off-topic but related to MATLAB... or things that can't span a single comment.
What about IRC
18:17
Hello all, hi @rayryeng, thanks for the invite :)
I wish there could be a way to mix IRC, Slack / Stackoverflow room
@beaker - Hello!
@beaker thanks for coming!
@diegoaguilar that wouldn't be a bad idea.
all are great
there's also Gitter but they're like one per repository
I'm actually surprised it took this long to make this room... we've been around for quite some time.
so this room was just created after that comment in my question?
18:20
@rayryeng Mixed something up, thought you where the guy from Austria.
Knedlsepp? Yeah I haven't seen him in a while lol.
@diegoaguilar Yes funny enough.
I should send him an invite too. Thanks Daniel.
Ah, yes.
Hey I'm reading an image on image processing and I'm not sure on something due to language difference
there's something we call "función potencia"
Im know sure if thats gamma correction
18:22
yes you're correct.
that literally translates to "power function"
which can be achieved by imadjust in MATLAB by imadjust
Correc.t
If you want to do it from first principles, you can normalize the image to [0,1], apply a gamma / power operation on that image, then rescale the image back to [0,255], but imadjust is suitable.
I'd like to lear the algorithm
but I dont know how hard canbe to code it
I've been testing some algorithms and got a 100% match for each against matlab functions from image box
it's very simply: out = 255*uint8(im2double(image).^gamma);
however, that assumes that the full range of the intensities spans from [0,255].
and 8 bit depth iamge
18:27
then what I wrote should work
I saw some code on internet for which they use imadjust
but I dont understand why they pass in 4 distinct arguments
The second argument tells MATLAB what the expected input dynamic range is
The third argument tells MATLAB what the expected output dynamic range is
Basically, you can use imadjust without the fourth argument... which is the gamma.
imadjust by default performs a contrast stretching that maps a set of intensities from one range to another range.
for example, you may have an image with low contrast where it's between... say [32,60]
and you want to contrast stretch this image so that 32 maps to 0, and 60 maps to 200 let's say
and everything is scaled in between
so you would do: out = imadjust(im, [32,60]/255, [0,200]/255);
the fourth parameter optionally performs a gamma power transformation on the contrast stretched result.
In that snippet they do it like: gamG=imadjust (potencia, [0 x], [y z]);
that means the input image has an expected dynamic range from [0,x] and they wish to remap it to [y,z].
FWIW, it's all very clear in the documentation: mathworks.com/help/images/ref/imadjust.html
MATLAB documentation is probably one of the best documented languages I've ever used.
MATLAB*
When I was trying to display an indexed image array of pixel values earlier I was wondering what the difference between using a display range with imshow() and actually changing the contrast was. Would this have to do with the gamma function?
18:38
Yes, imshow does that under the hood, but doesn't mutate the image.
it only shows you that, but doesn't modify the image at all. It's simply for visual inspection.
So technically it does imadjust when you specify a range as the second parameter to imshow, but it doesn't mutate the image. It only shows you the modified contrast range.
@RafaelMonteiro - Bom Dia!
Nice to see you here :) Thanks for coming!
@RafaelMonteiro - I remember seeing you around when I started answering questions... and you corrected me most of the time lol.
I haven't seen you around for a while, but it's nice to see that you are back :)
18:55
@ray
@RafaelMonteiro - Yes?
@rayryeng Yeah, lol. I've been working a lot. Actually I'm at work now, and I have to go. Just entered here out of curiosity. See you guys later, bye. :)
@RafaelMonteiro - No problem :) Take care!
19:46
@rayryeng Are you available?
19:56
@kkuilla - Yup!
@kkuilla - So you're having problems understanding permute?
Don't worry... I couldn't figure it out for the longest time.
Let me know when you're ready. BTW, welcome.
Yes. Ready...
Lets take your anwer as an example.
7
A: Image histogram implementation with Matlab

rayryengIn terms of calculating the histogram, the computation of the frequency per intensity is correct though there is a slight error... more on that later. Also, I would personally avoid using loops here. See my small note at the end of this post. Nevertheless, there are three problems with your co...

So this, yes?
Wow. seven votes already...
mat = bsxfun(@eq, permute(0:255, [1 3 2]), im);
h = reshape(sum(sum(mat, 2), 1), 256, 1);
haha it's funny. I didn't think that answer deserved 7 bvotes.
I've created answers that needed more effort, and never got a vote.
I know. I have seen them....
19:59
thanks :)
ok... so let's examine how permute works.
the position vector.. the second element works like so
Each position in this output vector dictates the OUTPUT.
The number at each position tells you from which dimension you are sampling from for the INPUT
Yep, I got that,
In this case, doing [1 3 2] means that I desire a modified output where the first dimension of the output is the first dimension of the input
the second dimensions of the output is the third dimension of the input
but wht [1 3 2] and not [1 2 3] for example?
and the third dimension of the output is the second dimension of the input
the reason why [3 2 1] is not correct is because the input is not a column vector.
if we did permute((0:255).', [3 2 1]); you are indeed correct
also take note that permute(0:255, [3 1 2]); is also correct
this is because in this case, the third dimension and first dimension are both singletons.
[3 2 1] in this case means we are swapping the first and third dimensions.
the first dimension is a bunch of rows, while the second dimension is just 1 column
and why do you want to swap them?
20:02
ok, so now this leads to the next part
if we did permute(0:255, [3 1 2]); or permute(0:255, [1 3 2]);
I would like to have a single 3D vector of size 1 x 1 x 255
So this is a 3D matrix that occupies 1 row and 1 column and has 256 slices, (sorry not 255)
so this is the same as saying:

out(:,:,1) =

0

out(:,:,2) =

1

...

...

out(:,:,255)
out(:,:,256) =

255 sorry
so that 3D vector is what I desire... make sense?
[3 1 2] makes sense. [1 3 2] does not. [1 3 2] would give a [m x 1 x m] array, wouldn't it>
?
I'm doing this on a single 1D vector
not the 2D matrix
if it was a 2D matrix, then yes it doesn't make sense.
Ah, I see. I expected it to a a 2D image.. Ok.
yup lol.
Next question.
20:06
so doing 0:255 gives us a 1 x 256 x 1 vector in 3D
Why do you want a 1x1xn matrix?
so permuting [1 3 2] or [3 1 2] gives us 1 x 1 x 256
What trick are you using?
Yep. got that...
ok
are you familiar with how bsxfun works?
Yes.
20:07
with the way it broadcasts data?
You mean singleton expansion>
ok, so let's start with a single value
let's say my image was stored in im
if I did this: out = bsxfun(@eq, 0, im);
What would this do? This would create a temporary matrix that is the same size as im, but full of zeroes.
and we would find the equality element-wise.
bsxfun can easily extend to 3 dimensions.
so doing bsxfun with a single 3D vector... and a 2D image
it would broadcast automatically into a 3D matrix
it's actually called broadcasting, but yes singleton expansion is correct.
bsxfun was inspired by numpy and how it does its operations.
numpy in Python.
OK... so imagine we had a 2 element 3D vector
20:09
0 for the first element, 1 for the second element
if we did bsxfun on this 2 element 3D vector, and a single image... this means that we have a 1 x 1 x 2 vector and our image is... say 500 x 500
in order for bsxfun to work, both inputs must be broadcasted so that they match in size.
to compromise, both inputs need to be 500 x 500 x 2.
so what will happen is that im will be replicated for as many elements in 3D as we have in the vector.
so im would be duplicated twice... once per slice.
and the 3D vector would be broadcasted such that it becomes a 3D matrix where the first slice is all 0s, the second slice is all 1s.
so we now have two matrices of compatible dimensions such that:
Ah, ok. I think I get it,,,
A(:,:,1) =

im

A(:,:,2) =

im

B(:,:,1) =

0 0 0 0 .....
0 0 0 0 .....

B(:,:,2) =
1 1 1 1 ...
the way broadcasting rules work in MATLAB is to place each of the input dimensions side by side... starting from left to right
so for our vector, and matrix we have:

1 x 1 x 2
500 x 500
Yes, column major..
any singleton dimensions get expanded to as many elements as there are for the other matrix
so this is technically
1 x 1 x 2
500 x 500 x 1
so the 1 and 1 of the singleton vector get expanded to 500 x 500, and the third dimension of 1 gets expanded to 2.
so hence, they both match 500 x 500 x 2 when singleton expanded
Ah, ok. That makes sense...
20:15
for the image, because the third dimension is expanded, to fill up the matrix, we copy the image for as many times as we have slices... so in this particular case, we have 2.
For the vector, the first and second dimensions need to be expanded to 500 x 500, and so for each element, we create a 500 x 500 matrix of a single number per slice.
and that explains the A and B matrices above.
the last thing that we do now... is use the eq function.
doing this element-wise means that for each slice, we check to see what elements are equal to the number that is dictated for that slice.
this will give us a 500 x 500 x 256 matrix where each slice is logical and tells you which locations are equal to the number dictated by that slice.
so the first slice of 500 x 500 gives you all the locations of the 0s.
the next slice of 500 x 500 gives you all of the locations of the 1s... all the way to the end of 255.
if you want to compute the histogram, you simply need to add up all of the values in each slice individually.
which is why I do a horizontal and vertical sum per slice.
The result is now still a 1 x 1 x 256 vector because we compressed each slice down to a single number.
which is why I reshaped it back to a single 1D vector.
It's pretty funny... those two lines of code required 15 minutes of explanation lol.
that's why I couldn't do it in a comments block. I had to bring you to a room for that.
hehe, That is true. I probably need to play a bit with it but I get the gist though... Creating a 1x1xn matrix, is that one of the common uses of permute?
correct.
it's one of the only few ways
another way is to do it by a for loop
Something like:

out = zeros(1,1,256);
for idx = 1 : 256
out(1,1,idx) = idx-1;
end
yeah I just kept playing around with permute until I got the hang of it. One of Divakar's answers permuted in 7 dimensions.... it's crazy.
but yes, knowing how bsxfun expands dimensions is how I managed to compute the histogram in two lines of code.
Loops? Yikes. Anyway I think your explanation covered it. I am going to play with permute to understand the details. I think you have covered it all. Thank you for the explanation,,
Remember that for those dimensions that are singleton (1), the temporary matrix that is created is expanded to match the other matrix's dimensions of that particular one.
whenever an expansion happens, the values are copied over for as many elements as there are in that dimension.
so for example, if we did bsxfun(@eq 0, rand(256,256));
the first input is 1 x 1, the second input is 256 x 256... so the first input needs to be expanded to 256 x 256
wow, i step away for a few minutes and miss a whole tutorial ;)
20:24
and so the 0 gets copied over 256 rows and 256 columns.
you're welcome :)
@beaker lol yes. @kkuilla wanted an explanation of how I computed an image's histogram.
I did it with bsxfun, permute, reshape and sum.
And I sure got one..... Thanks a lot...
Can I bookmark this conversation or get a permalink?
Yup.
Let me see if I can get a link

Explanation of computing an image's histogram vectorized

41 mins ago, 39 minutes total – 125 messages, 3 users, 0 stars

Bookmarked 9 secs ago by rayryeng

This gives you a transcript of our conversation.
if you want to know how to do this yourself, go up to the top of the page, and click on full transcript
this will spawn a new window, and on the right.. there's a link that says "bookmark a conversation"
you choose the day that the conversation happened... then click on the link to bookmark
it will ask you to click the starting message and ending message of the conversation
you then give it a title, and it will give you a permalink with the conversation in between those two messages.
Brilliant. I think the transcript worked because we were only two. If there are other irrelevant conversations, then they will be captured to. I had a look at todays' chat previously and I got all conversations.
It might be worth adding that link to the answer itself?
20:31
Yup. I'll do that right now.
done. thanks!
yes I'm glad it was just us lol
Great. Yes, It could get a bit messy. I think your last message summarises it very well...
I am going to step away now,. Thanks for your help though...
great.
no problem at all. Good luck!
20:49
@AnderBiguri - Try unrolling the vector
in(:)
14:00 - 21:0021:00 - 23:00

  last day (3453 days later) »