arokem / python-matlab-bridge

A simple Python => MATLAB(R) interface and a matlab_magic for ipython
BSD 2-Clause "Simplified" License
335 stars 96 forks source link

imshow() does not show picture #35

Closed GKA103 closed 9 years ago

GKA103 commented 10 years ago

Hi,

I was trying some image recognition but now imshow does not show the picture. No figure window opens, the program runs smoothly, no errors, imhist() works fine. It worked a couple of hours ago until Matlab R2013a crashed, I guess because calculations were a bit too complicated. It does "show" the number array in the command window if imshow(I) is called there...

Many thanks for your help!

arokem commented 10 years ago

Your message implies that this used to work in some previous version of pymatbridge ("...but now..."). Is that the case? When (what commit) did it break?

On Wed, Jan 15, 2014 at 4:20 AM, GKA103 notifications@github.com wrote:

Hi,

I was trying some image recognition but now imshow does not show the picture. No figure window opens, the program runs smoothly, no errors, imhist() works fine. It worked a couple of hours ago until Matlab R2013a crashed, I guess because calculations were a bit too complicated.

Many thanks for your help!

— Reply to this email directly or view it on GitHubhttps://github.com/arokem/python-matlab-bridge/issues/35 .

GKA103 commented 10 years ago

Its the same version only the program froze. I think because it was overloaded with complicated calculations. Afterwards the problem occured, might be coincidence. I restartet the computer multiple times, did not reinstal Matlab though.

Thanks for your help!

arokem commented 10 years ago

I am still not understanding fully: did imshow ever work for you? What operating system are you on?

GKA103 commented 10 years ago

It is Windows 7. imshow worked fine in the beginning, it showed the images as it was supposed to. Then the programm window froze (probably because of too many calculations). I quit it via task manager-->stop process. After this imshow will not show pictures anymore. All other commands (that I use) work fine. I restarted Matlab and the copmuter multiple times with no change in the result. imshow still does not show anything, nor do any windows open.

GKA103 commented 10 years ago

OK, I tried this (Code #1):

I = imread('D:\1.tif') imshow(I);

It works. Then I run another set of code which is below (Code #2) has imshow as well and imshow does not work. Then I run the code #1 again and it does not work anymore. If I close Matlab and restart code#1 works again...

PS: the other image is there, if I just copy the path and open it via command it shows up... Code #2:

%Loading the image

%InputFolder = 'Input folder'; %ImageNumber = 1; %ImageName = Num2Str(ImageNumber);
%ImageFormat = 'tif';

%Image = imread(strcat(InputFolder, ImageName, '.', ImageFormat)); I = imread('Another path.jpg'); imshow = (I); %imwrite(I, 'Another path.tif');

% Convert picture

% BackgroundSquares = 200; %Sets size of squares the background is averaged over % ImageBackground = imerode(I, strel('square',BackgroundSquares)); %Calculates background for substraction % ImageLeveled = double(I) - double(ImageBackground); %Substracts background % ImageLeveled = uint8((ImageLeveled - min(ImageLeveled(:)))/(max(ImageLeveled(:)) - min(ImageLeveled(:))) * 255); %Converts back to 8bit image % manual_threshold = 10; %Sets threshold manually for conversion % BWImage = ImageLeveled > manual_threshold; % BWInverted = ~BWImage; %Inverts image % BWDilated = imdilate(BWInverted,strel('square',5)); %Dilates pixels % imshow(BWDilated); % imwrite(BWDilated, strcat(InputFolder, ImageName, '_bearbeitet.', ImageFormat));

%Find circles

%[centers, radii, metric] = imfindcircles(I,[100, 150],'Sensitivity',0.99); %centersStrong5 = centers(1:1,:); %radiiStrong5 = radii(1:1); %metricStrong5 = metric(1:1); %viscircles(centersStrong5, radiiStrong5,'EdgeColor','b'); % ImageNumber = ImageNumber + 1; %Goes to next image in For-loop

%BW2 = bwareaopen(J3,10)
%imshow(BW2)
%BW3 = imfill(BW2,'holes');
%imshow(BW3)

%I_leveled = I_leveled + 100;
%imshow(I_leveled,[]);
arokem commented 10 years ago

Hmm - I have to apologize, but I am not that great with Windows. Was there any apparent error messages in the Matlab session? Did anything work after running #2, or did the Matlab session crash altogether?

On Fri, Jan 17, 2014 at 7:03 AM, GKA103 notifications@github.com wrote:

OK, I tried this (Code #1https://github.com/arokem/python-matlab-bridge/issues/1 ):

I = imread('D:\1.tif') imshow(I);

It works. Then I run another set of code which is below (Code #2https://github.com/arokem/python-matlab-bridge/pull/2) has imshow as well and imshow does not work. Then I run the code #1https://github.com/arokem/python-matlab-bridge/issues/1again and it does not work anymore. If I close Matlab and restart code#1 works again...

Code #2 https://github.com/arokem/python-matlab-bridge/pull/2:

%Loading the image

%InputFolder = 'X:\05 Projects\05 PG Lab-on-a-Chip\412601 ANGELab @ EU-FP7\10 Simulation\03 Image recognition\2014-01-15 Playing with Matlab\TestPictures'; %ImageNumber = 1; %ImageName = Num2Str(ImageNumber);

%ImageFormat = 'tif';

%Image = imread(strcat(InputFolder, ImageName, '.', ImageFormat)); I = imread('Another path.jpg'); imshow = (I); %imwrite(I, 'Another path.tif');

% Convert picture

% BackgroundSquares = 200; %Sets size of squares the background is averaged over % ImageBackground = imerode(I, strel('square',BackgroundSquares)); %Calculates background for substraction % ImageLeveled = double(I) - double(ImageBackground); %Substracts background % ImageLeveled = uint8((ImageLeveled - min(ImageLeveled(:)))/(max(ImageLeveled(:)) - min(ImageLeveled(:))) * 255); %Converts back to 8bit image % manual_threshold = 10; %Sets threshold manually for conversion % BWImage = ImageLeveled > manual_threshold; % BWInverted = ~BWImage; %Inverts image % BWDilated = imdilate(BWInverted,strel('square',5)); %Dilates pixels % imshow(BWDilated); % imwrite(BWDilated, strcat(InputFolder, ImageName, '_bearbeitet.', ImageFormat));

%Find circles

%[centers, radii, metric] = imfindcircles(I,[100, 150],'Sensitivity',0.99); %centersStrong5 = centers(1:1,:); %radiiStrong5 = radii(1:1); %metricStrong5 = metric(1:1); %viscircles(centersStrong5, radiiStrong5,'EdgeColor','b'); % ImageNumber = ImageNumber + 1; %Goes to next image in For-loop

%BW2 = bwareaopen(J3,10) %imshow(BW2) %BW3 = imfill(BW2,'holes'); %imshow(BW3)

%I_leveled = I_leveled + 100; %imshow(I_leveled,[]);

— Reply to this email directly or view it on GitHubhttps://github.com/arokem/python-matlab-bridge/issues/35#issuecomment-32612657 .

GKA103 commented 10 years ago

Hi Arokem,

thanks for all the help. The (apparent!?) error in #2 is the imshow = (I), the "=" is too much and Matlab seems to recognize imshow as a variable and then imshow stops working in its regular function.

Thanks for all the help!

blink1073 commented 9 years ago

Closing as fixed.