Thread Subject: combine image parts

Subject: combine image parts

From: us2

Date: 24 Jul, 2009 09:32:00

Message: 1 of 16

I have NxM sized image and divide it into let's say 4 different parts. I want to see these parts in a figure with a blank between them.

I mean that the new image figure must include all the parts but it must be seen as divided. When I convert the new image into binary, I want to see 4 different partitions separately

how to do this?

Subject: combine image parts

From: ImageAnalyst

Date: 24 Jul, 2009 11:05:27

Message: 2 of 16

On Jul 24, 5:32 am, "us2 " <u...@yahoo.com> wrote:
> I have NxM sized image and divide it into let's say 4 different parts. I want to see these parts in a figure with a blank between them.
>
> I mean that the new image figure must include all the parts but it must be seen as divided. When I convert the new image into binary, I want to see 4 different partitions separately
>
> how to do this?

------------------------------------------------------------
One way:
1. crop your image into 4 separate images.
2. indicate the axes with subplot(2,2,1). last arg would be 1, 2, 3,
or 4.
3. display image with image, imshow, or imagesc.
4. repeat steps 2 and 3 until all four parts have been displayed.

Subject: combine image parts

From: nor ki

Date: 24 Jul, 2009 11:10:17

Message: 3 of 16

"us2 " <us2@yahoo.com> wrote in message <h4bv2g$ac0$1@fred.mathworks.com>...
> I have NxM sized image and divide it into let's say 4 different parts. I want to see these parts in a figure with a blank between them.
>
> I mean that the new image figure must include all the parts but it must be seen as divided. When I convert the new image into binary, I want to see 4 different partitions separately
>
> how to do this?

hi,

many solutions are possible:

the one which comes closest to your requirements:
help subplot

show image and plot a line between the parts;
help line

create a new image which contaings a gap between the parts you want to be divided

hth
kinor

Subject: combine image parts

From: Brian J.

Date: 25 Jul, 2009 17:45:03

Message: 4 of 16

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <701f52c0-8ab6-4b0a-ac88-7dec944aa8ce@n11g2000yqb.googlegroups.com>...
> On Jul 24, 5:32?am, "us2 " <u...@yahoo.com> wrote:
> > I have NxM sized image and divide it into let's say 4 different parts. I want to see these parts in a figure with a blank between them.
> >
> > I mean that the new image figure must include all the parts but it must be seen as divided. When I convert the new image into binary, I want to see 4 different partitions separately
> >
> > how to do this?
>
> ------------------------------------------------------------
> One way:
> 1. crop your image into 4 separate images.
> 2. indicate the axes with subplot(2,2,1). last arg would be 1, 2, 3,
> or 4.
> 3. display image with image, imshow, or imagesc.
> 4. repeat steps 2 and 3 until all four parts have been displayed.

My problem is similar to this question. I have divided my original image into 4 parts and now, I have to combine them so that when we convert the combined image to binary image then we must see the 4 white region and black background in the binary image.
how to do this?

Subject: combine image parts

From: us

Date: 25 Jul, 2009 18:18:01

Message: 5 of 16

"Brian J." <brian0945@gmail.com> wrote in message <h4fgav$k3q$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <701f52c0-8ab6-4b0a-ac88-7dec944aa8ce@n11g2000yqb.googlegroups.com>...
> > On Jul 24, 5:32?am, "us2 " <u...@yahoo.com> wrote:
> > > I have NxM sized image and divide it into let's say 4 different parts. I want to see these parts in a figure with a blank between them.
> > >
> > > I mean that the new image figure must include all the parts but it must be seen as divided. When I convert the new image into binary, I want to see 4 different partitions separately
> > >
> > > how to do this?
> >
> > ------------------------------------------------------------
> > One way:
> > 1. crop your image into 4 separate images.
> > 2. indicate the axes with subplot(2,2,1). last arg would be 1, 2, 3,
> > or 4.
> > 3. display image with image, imshow, or imagesc.
> > 4. repeat steps 2 and 3 until all four parts have been displayed.
>
> My problem is similar to this question. I have divided my original image into 4 parts and now, I have to combine them so that when we convert the combined image to binary image then we must see the 4 white region and black background in the binary image.
> how to do this?

one of the solutions

     img=1+ceil(100*rand(8)); % <- the image
     i1=img(1:4,1:4); % <- the subimages...
     i2=img(1:4,5:8);
     i3=img(5:8,1:4);
     i4=img(5:8,5:8);
     del=zeros(4,1); % <- delimiter between subimages...
     ic=[i1,del,i2;del.',0,del.';i3,del,i4]; % <- img with delimiters...
     imagesc(ic);
     axis image;
     colormap([[0,0,0];jet(100)]);
     colorbar;

us

Subject: combine image parts

From: Brian J.

Date: 25 Jul, 2009 18:47:01

Message: 6 of 16

"us " <us@neurol.unizh.ch> wrote in message <h4fi8p$msr$1@fred.mathworks.com>...
> "Brian J." <brian0945@gmail.com> wrote in message <h4fgav$k3q$1@fred.mathworks.com>...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <701f52c0-8ab6-4b0a-ac88-7dec944aa8ce@n11g2000yqb.googlegroups.com>...
> > > On Jul 24, 5:32?am, "us2 " <u...@yahoo.com> wrote:
> > > > I have NxM sized image and divide it into let's say 4 different parts. I want to see these parts in a figure with a blank between them.
> > > >
> > > > I mean that the new image figure must include all the parts but it must be seen as divided. When I convert the new image into binary, I want to see 4 different partitions separately
> > > >
> > > > how to do this?
> > >
> > > ------------------------------------------------------------
> > > One way:
> > > 1. crop your image into 4 separate images.
> > > 2. indicate the axes with subplot(2,2,1). last arg would be 1, 2, 3,
> > > or 4.
> > > 3. display image with image, imshow, or imagesc.
> > > 4. repeat steps 2 and 3 until all four parts have been displayed.
> >
> > My problem is similar to this question. I have divided my original image into 4 parts and now, I have to combine them so that when we convert the combined image to binary image then we must see the 4 white region and black background in the binary image.
> > how to do this?
>
> one of the solutions
>
> img=1+ceil(100*rand(8)); % <- the image
> i1=img(1:4,1:4); % <- the subimages...
> i2=img(1:4,5:8);
> i3=img(5:8,1:4);
> i4=img(5:8,5:8);
> del=zeros(4,1); % <- delimiter between subimages...
> ic=[i1,del,i2;del.',0,del.';i3,del,i4]; % <- img with delimiters...
> imagesc(ic);
> axis image;
> colormap([[0,0,0];jet(100)]);
> colorbar;
>
> us

many many thanks ..
best wishes..

Subject: combine image parts

From: Brian J.

Date: 26 Jul, 2009 13:42:01

Message: 7 of 16

"Brian J." <brian0945@gmail.com> wrote in message <h4fjv5$d7q$1@fred.mathworks.com>...
> "us " <us@neurol.unizh.ch> wrote in message <h4fi8p$msr$1@fred.mathworks.com>...
> > "Brian J." <brian0945@gmail.com> wrote in message <h4fgav$k3q$1@fred.mathworks.com>...
> > > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <701f52c0-8ab6-4b0a-ac88-7dec944aa8ce@n11g2000yqb.googlegroups.com>...
> > > > On Jul 24, 5:32?am, "us2 " <u...@yahoo.com> wrote:
> > > > > I have NxM sized image and divide it into let's say 4 different parts. I want to see these parts in a figure with a blank between them.
> > > > >
> > > > > I mean that the new image figure must include all the parts but it must be seen as divided. When I convert the new image into binary, I want to see 4 different partitions separately
> > > > >
> > > > > how to do this?
> > > >
> > > > ------------------------------------------------------------
> > > > One way:
> > > > 1. crop your image into 4 separate images.
> > > > 2. indicate the axes with subplot(2,2,1). last arg would be 1, 2, 3,
> > > > or 4.
> > > > 3. display image with image, imshow, or imagesc.
> > > > 4. repeat steps 2 and 3 until all four parts have been displayed.
> > >
> > > My problem is similar to this question. I have divided my original image into 4 parts and now, I have to combine them so that when we convert the combined image to binary image then we must see the 4 white region and black background in the binary image.
> > > how to do this?
> >
> > one of the solutions
> >
> > img=1+ceil(100*rand(8)); % <- the image
> > i1=img(1:4,1:4); % <- the subimages...
> > i2=img(1:4,5:8);
> > i3=img(5:8,1:4);
> > i4=img(5:8,5:8);
> > del=zeros(4,1); % <- delimiter between subimages...
> > ic=[i1,del,i2;del.',0,del.';i3,del,i4]; % <- img with delimiters...
> > imagesc(ic);
> > axis image;
> > colormap([[0,0,0];jet(100)]);
> > colorbar;
> >
> > us
>
> many many thanks ..
> best wishes..

I have 256x256 sized image and want to divide this image into 64x64 sized blocks (then there will be 16 equal sized block) and combine them. So, to be able to generalize the above codes for this purpose, I have written that;

X1=1; k=1;
for j=1:4
    Y2=0;
    for i=1:4
        X2=64*j;
        Y1=Y2+1;
        Y2=64*i;
        r(k)=p(X1:X2, Y1:Y2); k=k+1;
    end
    X1=X2+1;
end

 del=zeros(64,1); % <- delimiter between subimages...
 
ic=[r(1),del,r(2),del,r(3),del,r(4); del.',0,del.',0,del.',0,del.';r(5),del,r(6),del,r(7),del,r(8); del.',0,del.',0,del.',0,del.'; r(9),del,r(10),del,r(11),del,r(12); del.',0,del.',0,del.',0,del.';r(13),del,r(14),del,r(15),del,r(16)];

But , I am getting this error:

??? In an assignment A(I) =B, the number of elements in B and I must be the same.
I think, there is a problem with this code:
                                     r(k)=p(X1:X2, Y1:Y2); k=k+1;

What must I do?

Subject: combine image parts

From: us

Date: 26 Jul, 2009 15:02:03

Message: 8 of 16

"Brian J."
> What must I do?

one of the solutions is outlined below
- this requires the image proc tbx(!)...
- use MONTAGE on delimiter enhanced subimages...

     n=64;
     m=16;
     img=reshape(1:n*n,[n,n]); % <- the big image...
     img=img+5000*rand(size(img)); % <- ...with a bit of noise...
     ix=1:m; % <- the index template...
     ni=n/m; % <- add error check: must be INT...
     simg=zeros(m+1,m+1,1,ni*ni);
     del=-100*ones(1,m);
     k=0;
% create 4D subimages with dels...
for i=1:ni
     xv=(i-1)*m+ix;
for j=1:ni
     k=k+1;
     yv=(j-1)*m+ix;
% - add del...
     simg(:,:,1,k)=[img(xv,yv),del.';del,-100];
end
end
% - adjust colormap...
     simg=255*simg./max(img(:));
     simg(simg<0)=-1;
     cmap=[
          [1,1,0] % <- del
          gray(255)
     ];
% - set IMSHOW prop...
     imod=iptgetpref('ImshowInitialMagnification');
     iptsetpref('ImshowInitialMagnification','fit');
     montage(simg,cmap,'size',[ni,ni]);
     iptsetpref('ImshowInitialMagnification',imod);

us

Subject: combine image parts

From: Brian J.

Date: 26 Jul, 2009 16:58:01

Message: 9 of 16

"us " <us@neurol.unizh.ch> wrote in message <h4hr5a$7vl$1@fred.mathworks.com>...
> "Brian J."
> > What must I do?
>
> one of the solutions is outlined below
> - this requires the image proc tbx(!)...
> - use MONTAGE on delimiter enhanced subimages...
>
> n=64;
> m=16;
> img=reshape(1:n*n,[n,n]); % <- the big image...
> img=img+5000*rand(size(img)); % <- ...with a bit of noise...
> ix=1:m; % <- the index template...
> ni=n/m; % <- add error check: must be INT...
> simg=zeros(m+1,m+1,1,ni*ni);
> del=-100*ones(1,m);
> k=0;
> % create 4D subimages with dels...
> for i=1:ni
> xv=(i-1)*m+ix;
> for j=1:ni
> k=k+1;
> yv=(j-1)*m+ix;
> % - add del...
> simg(:,:,1,k)=[img(xv,yv),del.';del,-100];
> end
> end
> % - adjust colormap...
> simg=255*simg./max(img(:));
> simg(simg<0)=-1;
> cmap=[
> [1,1,0] % <- del
> gray(255)
> ];
> % - set IMSHOW prop...
> imod=iptgetpref('ImshowInitialMagnification');
> iptsetpref('ImshowInitialMagnification','fit');
> montage(simg,cmap,'size',[ni,ni]);
> iptsetpref('ImshowInitialMagnification',imod);
>
> us

Dear "us", thanks a lot, but when I use img=phantom(256); then I could not see the result :((

Subject: combine image parts

From: us

Date: 26 Jul, 2009 17:04:01

Message: 10 of 16

"Brian J."
> Dear "us", thanks a lot, but when I use img=phantom(256); then I could not see the result :((

you must learn to be a bit more ML-self-contained, as well...
eg, what do you get with these

     size(img)
     r=[min(img(:)),max(img(:))]
% compare the results with those obtained from the IMG created in the solution...

us

Subject: combine image parts

From: Brian J.

Date: 26 Jul, 2009 18:10:02

Message: 11 of 16

"us " <us@neurol.unizh.ch> wrote in message <h4i2a1$r36$1@fred.mathworks.com>...
> "Brian J."
> > Dear "us", thanks a lot, but when I use img=phantom(256); then I could not see the result :((
>
> you must learn to be a bit more ML-self-contained, as well...
> eg, what do you get with these
>
> size(img)
> r=[min(img(:)),max(img(:))]
> % compare the results with those obtained from the IMG created in the solution...
>
> us

I am very thankful to you. It was impossible to solve this problem without you, thanks a lot.

The last thing about this is binarization. I have tried to solve it by myself but the error is very different so again I need you. When I write the following code:

     binaryImage=im2bw(simg, graythresh(simg)); figure(2); imshow(binaryImage);

then I am getting the following error:

??? Error
using ==>
imageDisplayValidateParams>validateCData
at 114 Unsupported dimension

Error in ==>
imageDisplayValidateParams
at 31
common_args.CData=validateCData(common_args.CData,image_type);

Error in ==>
imageDisplayParseInputs
at 79
common_args =imageDisplayValidateParams(common_args);

Error in ==>
imshow at 199
  [common_args,specific_args]
  = ...

Error in ==>
 binaryImage=im2bw(simg, graythresh(simg));
 figure(2); imshow(binaryImage);

Subject: combine image parts

From: Brian J.

Date: 26 Jul, 2009 18:18:01

Message: 12 of 16

"us " <us@neurol.unizh.ch> wrote in message <h4i2a1$r36$1@fred.mathworks.com>...
> "Brian J."
> > Dear "us", thanks a lot, but when I use img=phantom(256); then I could not see the result :((
>
> you must learn to be a bit more ML-self-contained, as well...
> eg, what do you get with these
>
> size(img)
> r=[min(img(:)),max(img(:))]
> % compare the results with those obtained from the IMG created in the solution...
>
> us

Let's assume that

img=imread('cameraman.tif'); or i mg=phantom(64);
then we divide this image with the above code. And then when we add the following code to binarization;

binaryImage=im2bw(simg, graythresh(simg));
figure; imshow(binaryImage);

then we are getting error which is very strange, we could not solve this error :(

Subject: combine image parts

From: us

Date: 26 Jul, 2009 18:38:01

Message: 13 of 16

"Brian J."
> The last thing about this is binarization. I have tried to solve it by myself but the error is very different so again I need you. When I write the following code:
>
> binaryImage=im2bw(simg, graythresh(simg)); figure(2); imshow(binaryImage);
>
> then I am getting the following error:
>
> ??? Error
> using ==>
> imageDisplayValidateParams>validateCData
> at 114 Unsupported dimension

well, yes - and - of course...
- you add stuff, which you did not mention in your OPs...
- this starts to make things a bit tedious...

now, look at the code snippet, again, and look at what i said

% pre-allocation section
     simg=zeros(m+1,m+1,1,ni*ni); % <- a 4-D matrix for MONTAGE(!)...
% in the loop section
     simg(:,:,1,k)=[img(xv,yv),del.';del,-100]; % <- note the SINGLETON(!)...
% this is necesssary to get MONTAGE to work
     help montage;

if you want to add some sort of ...binarization..., you should do it in the loop using your original subimage IMG(XV,YV) data...

us

Subject: combine image parts

From: Brian J.

Date: 26 Jul, 2009 19:38:01

Message: 14 of 16

"us " <us@neurol.unizh.ch> wrote in message <h4i7q9$5hf$1@fred.mathworks.com>...
> "Brian J."
> > The last thing about this is binarization. I have tried to solve it by myself but the error is very different so again I need you. When I write the following code:
> >
> > binaryImage=im2bw(simg, graythresh(simg)); figure(2); imshow(binaryImage);
> >
> > then I am getting the following error:
> >
> > ??? Error
> > using ==>
> > imageDisplayValidateParams>validateCData
> > at 114 Unsupported dimension
>
> well, yes - and - of course...
> - you add stuff, which you did not mention in your OPs...
> - this starts to make things a bit tedious...
>
> now, look at the code snippet, again, and look at what i said
>
> % pre-allocation section
> simg=zeros(m+1,m+1,1,ni*ni); % <- a 4-D matrix for MONTAGE(!)...
> % in the loop section
> simg(:,:,1,k)=[img(xv,yv),del.';del,-100]; % <- note the SINGLETON(!)...
> % this is necesssary to get MONTAGE to work
> help montage;
>
> if you want to add some sort of ...binarization..., you should do it in the loop using your original subimage IMG(XV,YV) data...
>
> us

Dear "us", you are right. I should say the main goal at the begining. The goal is to do connected component labeling for each segmented region of the original image and to use region properties. For this purpose, the codes that I have tried to add (but could not do) to above codes are;

  labeledImage = bwlabel(binaryImage); % Label each region to do do calc on it
  regionMeasurements = regionprops(labeledImage, 'all');

for k = 1 : numberOfregions % Loop through all regions.
thisregionPixels = regionMeasurements(k).PixelIdxList; % Get list of pixels in current region.
meanGL = mean(originalImage(thisregionPixels)); % Find mean intensity in original image
regionCentroid = regionMeasurements(k).Centroid;
end

Subject: combine image parts

From: Brian J.

Date: 27 Jul, 2009 05:14:01

Message: 15 of 16

"Brian J." <brian0945@gmail.com> wrote in message <h4ibap$3f0$1@fred.mathworks.com>...
> "us " <us@neurol.unizh.ch> wrote in message <h4i7q9$5hf$1@fred.mathworks.com>...
> > "Brian J."
> > > The last thing about this is binarization. I have tried to solve it by myself but the error is very different so again I need you. When I write the following code:
> > >
> > > binaryImage=im2bw(simg, graythresh(simg)); figure(2); imshow(binaryImage);
> > >
> > > then I am getting the following error:
> > >
> > > ??? Error
> > > using ==>
> > > imageDisplayValidateParams>validateCData
> > > at 114 Unsupported dimension
> >
> > well, yes - and - of course...
> > - you add stuff, which you did not mention in your OPs...
> > - this starts to make things a bit tedious...
> >
> > now, look at the code snippet, again, and look at what i said
> >
> > % pre-allocation section
> > simg=zeros(m+1,m+1,1,ni*ni); % <- a 4-D matrix for MONTAGE(!)...
> > % in the loop section
> > simg(:,:,1,k)=[img(xv,yv),del.';del,-100]; % <- note the SINGLETON(!)...
> > % this is necesssary to get MONTAGE to work
> > help montage;
> >
> > if you want to add some sort of ...binarization..., you should do it in the loop using your original subimage IMG(XV,YV) data...
> >
> > us
>
> Dear "us", you are right. I should say the main goal at the begining. The goal is to do connected component labeling for each segmented region of the original image and to use region properties. For this purpose, the codes that I have tried to add (but could not do) to above codes are;
>
> labeledImage = bwlabel(binaryImage); % Label each region to do do calc on it
> regionMeasurements = regionprops(labeledImage, 'all');
>
> for k = 1 : numberOfregions % Loop through all regions.
> thisregionPixels = regionMeasurements(k).PixelIdxList; % Get list of pixels in current region.
> meanGL = mean(originalImage(thisregionPixels)); % Find mean intensity in original image
> regionCentroid = regionMeasurements(k).Centroid;
> end

here, the binaryImage refers to binary form of the segmented image

Subject: combine image parts

From: ahmed

Date: 4 Sep, 2009 20:28:02

Message: 16 of 16

I think my problem is similar to this problem so that i attached my question here

when i want to load an image of size 256x256 pixles into DSP processor but i know that the transfer should not exceeds 32KB which corresponds to loaded image of size 180x180 pixles. who can help me to write a code in matlab to overcome this obstcale?

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
linear indexing us 26 Jul, 2009 11:04:07
iptgetpref us 26 Jul, 2009 11:04:07
iptsetpref us 26 Jul, 2009 11:04:07
montage us 26 Jul, 2009 11:04:07
colorbar us 25 Jul, 2009 14:19:04
colormap us 25 Jul, 2009 14:19:04
axis us 25 Jul, 2009 14:19:04
imagesc us 25 Jul, 2009 14:19:04
code us 25 Jul, 2009 14:19:04
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com