Thu 01 Sep 2016 06:00:55 AM UTC, comment #5:
Give the attached variation on your script file a try. As a comparison, I'll first reduce the image size:
So that is a factor of fifty times faster? I note that the two histograms do not match in the last places:
and the reason is because in your formula:
img(i,j) is an uint8 and the largest value an uint8 can be is 255. img(i,j)+1 is also an uint8, hence
img(i,j)=254 results in img(i,j)+1=255
img(i,j)=255 results in img(i,j)+1=255
i.e.,
So, let me run the larger image in just the new histro2.m script:
2.2 seconds. That's pretty fast.
I'll also note that if you are passing in an image that has three planes, I don't see how that comes out to be a "Gray Image" histogram. Both of these histogram scripts include every element of every plane.
(file #38399)
|
Tue 30 Aug 2016 05:19:39 AM UTC, comment #2:
Freezing the OS isn't good, but that might be an OS problem as a program going outside its memory space or something as bad shouldn't be a problem with modern operating systems. (If you can identify a crash though and any sort of message right before it happens, that would be good.)
Anyway, what you are doing violates some of the main tenants of interpreted language processing.
1) Pre-assign memory. If your count vector C() (a matrix really seeing the image has three color planes) is not pre-assigned, every time an image value greater than previous appears the whole vector has to be reallocated to a bigger memory space to make room. And if you have an 8-bit image with 3 planes, statistically speaking that could be a lot of reallocations. And this sort of memory exercising might be what is testing your OS. For what it's worth, Matlab used to be slow at this too, but improved over the years. (I think there are ways internally that could improve this, and it's been discussed at OctConf sessions, but no one's implemented it.) In any case, pre-allocate memory.
2) Avoid indexing as much as possible. That has to be interpretted and is about ten times slower than inherent indexing through matrix multiplication, sorting routines, logical indexing, etc. There is a lot to learn about the efficient ways of using the language. As AW suggests, look for pre-existing functions that are already optimized.
|
Mon 29 Aug 2016 05:54:19 PM UTC, original submission:
I tried manually created histogram function to process images with
only two loops. It take more than 15 minutes to get results from
octave and sometimes it freezes the OS. However i tried same in Matlab
and it gives results quickly.
used image is unit8 1600x2560x3 image.
part of the code is:
[m,n] = size(img);
for i = 1:m
for j= 1:n
C(img(i,j)+1) = C(img(i,j)+1)+1;
K = K+1;
end
end
|