Hi Guillermo,
Glad you have progress! A quick change that will compute a bit less is to
change:
$image->where($sub_image > 0) .= $sub_image->where($sub_image > 0);
to:
my $inds = $sub_image > 0;
$image->where($inds) .= $sub_image->where($inds);
The algorithm you're using looks like it takes, for each pixel channel, the
last (highest-n) non-zero pixel channel value. There isn't a "first non-zero"
(which you could use with a slice("-1:0")) operation that I know of, but if
there were, it would operate over the whole image-stack in one go, which would
probably be optimally quick, especially since it would shortcut. Also with the
miracle of auto-pthreading and broadcasting, it could use POSIX threads.
Any volunteers to write a "firstnonzeroover" xform for Ufunc?
Best regards,
Ed
________________________________
From: Guillermo P. Ortiz <[email protected]>
Sent: 25 October 2024 5:29 PM
To: Ed . <[email protected]>
Cc: David Mertens <[email protected]>; [email protected]
<[email protected]>; [email protected]
<[email protected]>
Subject: Re: [Pdl-devel] project ordered sequence image
Thanks to Ingo, David, Ed,
After some minor modification to the David help, and using:
use PDL::NiceSlice;
my $image = $imn(,,,(0));
for my $layer (1 .. $imn->dim(3)-1) {
my $sub_image = $imn(,,,($layer));
$image->where($sub_image > 0) .= $sub_image->where($sub_image > 0);
}
works fine to solve my problem, but yes it is some slow thinking in hundreds of
these
operations. Nevertheless, it does not impact the overall computation cost.
The change I made is $image->dim(3) => $imn->dim(3)-1, because $image is
(3,x,y) and the number of layer is
in $imn->dim(3)
Regards
El vie, 25 oct 2024 a las 9:42, Ed .
(<[email protected]<mailto:[email protected]>>) escribió:
A thing I didn't think of before: to add to David's thought, you might consider
adding a fourth value to make your images RGBA, where the A is "alpha", i.e.
opacity. Then you would only add each pixel (or channel value) to the final
image where its numerical value * the alpha value was >0 (or, if you're doing
addition or "or"-ing, just add/or the value * the alpha, which if 0 does
nothing).
Best regards,
Ed
________________________________
From: David Mertens <[email protected]<mailto:[email protected]>>
Sent: 25 October 2024 11:10 AM
To: Ed . <[email protected]<mailto:[email protected]>>
Cc: Guillermo P. Ortiz <[email protected]<mailto:[email protected]>>;
[email protected]<mailto:[email protected]>
<[email protected]<mailto:[email protected]>>;
[email protected]<mailto:[email protected]>
<[email protected]<mailto:[email protected]>>
Subject: Re: [Pdl-devel] project ordered sequence image
Hello Guillermo,
You said something interesting. You discussed a sub-image with "a red circle"
and another with "a blue rectangle". But what you have are full images: an
image with a red circle is an image with a red circle and a black background.
It sounds like you want to treat that background color as transparent, then
"layer" the images by overwriting the non-transparent pixels.
If I had to do this myself, I can only think of a way to do this using a Perl
loop. If you find that this loop is too slow, then think of ways to rewrite
using a PDL expression, but only if you actually deem it to be too slow. It
would go something like this:
use PDL::NiceSlice;
my $image = $imn(,,,(0));
for my $layer (1 .. $image->dim(3)) {
my $sub_image = $imn(,,,($layer));
$image->where($sub_image > 0) .= $sub_image->where($sub_image > 0);
}
This isn't perfect: if you have a pixel in your sub-image that is pure red,
it'll copy the red channel to the final image, but not the green or blue.
That's as much as I can put into it for now, thouogh, and hopefully it's enough
to get you started.
David
On Thu, Oct 24, 2024 at 3:30 PM Ed .
<[email protected]<mailto:[email protected]>> wrote:
Hi Guillermo,
That will depend on how you want to combine each pixel. If you can deal
independently with each R/G/B value, then to just add the values together,
you'd do:
$im = $imn->mv(-1,0)->sumover;
Otherwise you'll have to spell out a bit more what you mean by sorting. Another
operation that might be useful is "borover" (bitwise or, on each R/G/B value
along the sequence of images).
Best regards,
Ed
________________________________
From: Guillermo P. Ortiz <[email protected]<mailto:[email protected]>>
Sent: 24 October 2024 4:52 PM
To: Ed . <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]>
<[email protected]<mailto:[email protected]>>;
[email protected]<mailto:[email protected]>
<[email protected]<mailto:[email protected]>>
Subject: Re: [Pdl-devel] project ordered sequence image
Hello again, thanks to Ed for show me a typo error
in my example. Where I wrote
$im=$imn->reduce('op',2);
it must say
$im=$imn->reduce('op',3);
But, the question remain in how to do an 'op' that
result in a sorted overlapping between all the sub images
In other words. Suppose you have n=0 sub image with
a red circle and in n=1 a sub image with a blue rectangle.
Some pixeles of both images are in common.
Then, what I want is to get a composed image that shows
the red circle overlapping the blue rectangle. The same
idea for many subimages with sorted overlapping.
Regards,
El jue, 24 oct 2024 a las 9:57, Guillermo P. Ortiz
(<[email protected]<mailto:[email protected]>>) escribió:
Hello Ed,
thanks for your reply.
That I trying to mean with 'reduce' is some of
projection operation (op) like in PDL::Reduce module
that performs "(op)over" to reduce to N-1
dimension after some operation over the set of
(3,x,y, n) to (3,x,y) rgb images. I mean
a composed rgb image from a set of (layer) n rgb images.
For example:
$imn-> info : pdl D [3,nx,ny,n]
$im=$imn->reduce('op',2);
$im-> info : pdl D [3,nx,ny]
Then, maybe I need to introduce some "sort"
operation in order that when I reduce to one
composed $im image each layer in $imn overlap
the following layer. But, I did not realize how to do that
using some pdl trick.
Thanks a lot for your help
Regards
El jue, 24 oct 2024 a las 9:12, Ed .
(<[email protected]<mailto:[email protected]>>) escribió:
Hi Guillermo,
I believe the situation you're describing is you have effectively a series of
(3,x,y) images. You mention "reducing", but you haven't said what you mean by
that - would it turn that series of images into one image?
wpic is intended to write out a single image, so an ndarray with multiple
images won't work with that. To write out a series of images as a movie you
could use wmpeg, or just to store the data you could use
https://metacpan.org/pod/PDL::IO::FastRaw and specifically writefraw. Otherwise
to write each image in its own file you could use something like:
$_->wpic(sprintf "img%03d.png", $count++) for $pdl->dog;
Does that help?
Best regards,
Ed
________________________________
From: Guillermo P. Ortiz <[email protected]<mailto:[email protected]>>
Sent: 23 October 2024 4:42 PM
To: [email protected]<mailto:[email protected]>
<[email protected]<mailto:[email protected]>>;
[email protected]<mailto:[email protected]>
<[email protected]<mailto:[email protected]>>
Subject: [Pdl-devel] project ordered sequence image
Hello everyone,
I have created a pdl with structure (3,size_x,size_y,np)
in order to manage different layer features to compose an rgb
image.
The idea that I can not connect yet is how to "reduce" over dim 3
to project to 3 X s_x X s_y rgb image in ordered fashion sequence. For example,
suppose that for np=0, 1 and 2, in the resulting image is only view of 2 that
is allowed by 1 and 0 layers, in that order.
I am trying to use wpic command from PDL::IO::Pic module
to convert via for example pnmtopng using options for it.
There are hashes like {FLAGS => options} used for options
{CONVERTER => 'pnmtopng'} indicating which conversor to use.
But is seems to be intended of rgb 3(4) X s_x X s_y
Thanks for your attention in advance
Regards
--
Dr. Guillermo P. Ortiz
Electromagnetismo Aplicado
Dto. Física, Facultad de Ciencias Exactas
Universidad Nacional del Nordeste
Avda Libertad 5460, Campus UNNE.
W3404AAS Corrientes, Argentina.
(+54) 379-4424678 interno 4613
gortiz at unne edu ar
_______________________________________________
pdl-devel mailing list
[email protected]<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/pdl-devel
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." -- Brian Kernighan
_______________________________________________
pdl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-devel