Cell array of images like Matlab

219 views
Skip to first unread message

Drew Mahedy

unread,
Sep 7, 2016, 7:28:00 PM9/7/16
to julia-users
I'm just wondering if there is a way to load several RGB .jpg images into a 4-D array like can be done in MATLAB using cell array. I have the Images package installed but concatenating 2 images in the 3rd or 4th dimension says that 'only two-dimensional images are supported in assert2d' when I try.

Uwe Fechner

unread,
Sep 7, 2016, 10:24:14 PM9/7/16
to julia-users
Could you post code, that reproduces the problem?

Drew Mahedy

unread,
Sep 9, 2016, 8:01:39 PM9/9/16
to julia-users
Here is what the code looks like in MATLAB:

AA = cell( size(trimcoorddir,1), 1 );

figpathdir2 = dir( strrep( figpath2, '\', filesep ) );
fignames2 = {figpathdir2.name};

for i = 1:length(trimcoorddir);

    if all( strcmp( fignames2, trimcoord{i}.filename ) == 0 );
        A = imread( strrep( [figpath, '\', trimcoord{i}.filename], '\', filesep ) );
        AA{i} = rgb2gray( A );
        AA{i} = 255 - medfilt2( AA{i}, [25 25] ) + AA{i};  %Time Consuming!
        AA{i} = imadjust( AA{i}, [0.96 1], [0 1], 1.0 );
        
        imwrite( AA{i}, strrep( [figpath2, '\', trimcoord{i}.filename], '\', filesep ) );
    else
        AA{i} = imread( strrep( [figpath2, '\', trimcoord{i}.filename], '\', filesep ) ); 
    end

end
Message has been deleted

Drew Mahedy

unread,
Sep 9, 2016, 8:19:19 PM9/9/16
to julia-users
In Julia, if I try and concatenate two images together of type:

Array{ColorTypes.Gray{FixedPointNumbers.UFixed{UInt8,8}},2} via

cat( 3, img, img ),

I get the following error:

Only two-dimensional images are supported

On Wednesday, September 7, 2016 at 7:24:14 PM UTC-7, Uwe Fechner wrote:

El suisse

unread,
Sep 9, 2016, 11:41:24 PM9/9/16
to julia...@googlegroups.com

julia version???

julia>versioninfo()

Uwe Fechner

unread,
Sep 10, 2016, 2:22:55 AM9/10/16
to julia-users
Sorry, but this is not a complete example that I could run to reproduce the problem.

Matt Bauman

unread,
Sep 10, 2016, 2:35:29 AM9/10/16
to julia-users
I cannot reproduce that error, and I know that the lead author of Images uses stacked image arrays quite frequently.

julia> using TestImages, Images
       src
= testimage("mandrill")
       arr
= convert(Array{ColorTypes.Gray{FixedPointNumbers.UFixed{UInt8,8}},2}, src)
       cat
(3, arr, arr)
512x512x2 Array{ColorTypes.Gray{FixedPointNumbers.UFixed{UInt8,8}},3}:
...

julia
>img = Image(arr)
       cat
(3, img, img)
Gray Images.Image with:
  data
: 512x512x2 Array{ColorTypes.Gray{FixedPointNumbers.UFixed{UInt8,8}},3}

Are you doing this in an IJulia notebook?  It may be that the error you're seeing is simply that IJulia doesn't know how to display a stack of images.

On another note, the Julia equivalent to a cell array is an `Any[]` array, which is quite different from concatenating the images together in a higher dimension.  You can even use the Matlab-like `cell( size(trimcoorddir,1) )` to initialize an array that can hold anything like a cell array.

Tim Holy

unread,
Sep 10, 2016, 7:40:50 AM9/10/16
to julia...@googlegroups.com
Try putting a semicolon at the end of that line.

Thanks for the bug report! https://github.com/timholy/Images.jl/issues/554

--Tim

On Friday, September 9, 2016 5:18:45 PM CDT Drew Mahedy wrote:
> In Julia, if I try and concatenate two images together of type:
>
> Array{ColorTypes.Gray{FixedPointNumbers.UFixed{UInt8,8}},2} via
>
> cat( 3, img, img ),
>
> I get the following error:
>
> Only two-dimensional images are supported
>
Reply all
Reply to author
Forward
0 new messages