Jump to content

Counting filled cells in column


Recommended Posts

I have a method for converting a black and white image into instructions for folding a book into the image (method is here http://www.instructables.com/id/Book-Art-How-to-Fold-a-Book-into-a-Word/).  To do this I count filled pixels by column if a zoomed in image.  Is there a way to generate a count of filled and unfilled spaces in an image.  This would speed up one of the more tedious parts of the process.  Thank you for any help.

Link to comment
Share on other sites

The fastest way I can think of for doing this is to zoom in and select the column with the magic wand tool and look at the info bar at the bottom to see how tall the selection is.

 

what I do all summer Emote Cursor Pack 'noob gallery

No, Paint.NET is not spyware...but, installing it is an IQ test. ~BoltBait

Blend modes are like the filling in your sandwich. It's the filling that can change your experience of the sandwich. ~Ego Eram Reputo

Link to comment
Share on other sites

Hi,

 

attached is a plugin called PixelCounter - install it as you would any plugin- it will appear under the effects.

Create a folder under the C:\ root folder called "count" just lowercase "count"

 

Make your black and white text, hit escape, run PixelCounter (again it's under effects, at the bottom)

 

press ok.

 

look under the C:\count folder and you'll find a file called "pixelcount". open it with Notepad.

 

I've attached an example of the word "Test"

 

The Plugin considers anything that's not white a pixel so you may want to turn off anti-aliasing.

 

Also you can use it to make images in the books. Just a thought.

 

https://www.dropbox.com/s/hp9jep7p2t1408y/pixelcount.txt?dl=0

pixelcounter.zip

Edited by TechnoRobbo
  • Like 1

Go out there and be amazing. Have Fun, TR
TRsSig.png?raw=1
Some Pretty Pictures Some Cool Plugins

Link to comment
Share on other sites

cool

 

for any programmer out there curious about the code:

Hidden Content:

 

// Name: PixelCounter
// Title: PixelCounter

#region UICode 
bool Amount1 = true; // [0,1] 
#endregion 

void Render(Surface dst, Surface src, Rectangle rect)
{
     if (Amount1){
           Rectangle sel = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
          dst.CopySurface(src, sel.Location,sel);
         //========================= 
          Amount1=false;
          try {
                System.IO.StreamWriter pc = new System.IO.StreamWriter(@"C:/count/pixelcount.txt",false);
                pc.WriteLine("Begin Count:");
                pc.WriteLine();
                pc.Close();
                for (int x = sel.Left; x< sel.Right; x++){
                    int toppix=0;
                    int pixlength=0;
                    
                    for (int y= sel.Top; y< sel.Bottom;y++){
                        ColorBgra CP= src.GetBilinearSample(x,y);
                        int total = CP.R + CP.G + CP.B;
                        if (toppix ==0){
                            if (total<765){
                                toppix=y;
                                pixlength=1;
                            }
                        }else{
                            if (total<765){
                                pixlength++;
                            }else{
                                System.IO.StreamWriter pcr = new System.IO.StreamWriter(@"C:/count/pixelcount.txt",true);
                                pcr.WriteLine("Column" + x + " Top=" + toppix + " Length=" + pixlength);
                                pcr.WriteLine();
                                pcr.Close();
                                toppix=0;
                                pixlength=0;
                            }
                        }
                    }
                }
                System.IO.StreamWriter pce = new System.IO.StreamWriter(@"C:/count/pixelcount.txt",true);
                pce.WriteLine(":End Count");
                pce.WriteLine();
                pce.Close();
                
            }catch(Exception e){}
     }else{
      //======= next code is a keep alive for dialog box 
     //so users know its working. 
            ColorBgra CP=dst[0,0];
            dst[0,0]=CP;
     }
}
 

Edited by TechnoRobbo

Go out there and be amazing. Have Fun, TR
TRsSig.png?raw=1
Some Pretty Pictures Some Cool Plugins

Link to comment
Share on other sites

  • 3 months later...

I installed the pixelcounter plugin and used it under the effects however when I look in the "count" folder I made in the c:/program files/paintnet folder I cant find the txt file.  the count folder is empty.  I even ran a search for a pixelcount.txt or anything pixelcount and find nothing.  Can you help?  Thanks!  I am using Windows 7.

Link to comment
Share on other sites

You made the folder in the wrong location. You need it to be in this location C:/count/

See @TechnoRobbo's post above where he says:
 

Create a folder under the C:\ root folder called "count" just lowercase "count"

  • Upvote 1
Link to comment
Share on other sites

got it working...thanks!  Now can I ask for help in using it?  Sorry to be so tech illiterate.  I found the pixel count text and see that it shows the beginning and length in pixels.  How do I then understand this in terms of centimeters to use as my word template? Does each pixel stand for a centimeter?  Or when the text says column 295 top 456 length 12......top starts at 4.5 cent and is 12 cent long?

Link to comment
Share on other sites

Gosh I've never folded a book, but from the Instructables by TeFrerrel...

 

http://www.instructables.com/id/Book-Art-How-to-Fold-a-Book-into-a-Word/

 

I see he uses a scale of 10 per pixel inch (2.53 cm).

 

I'm confused as to how one could use Word since one would have to wrestle with the kerning and justification.

 

Pixel Primer

The output file is in pixels (Picture Elements). On a computer graphic pixels are arranged in columns and rows like an Excel spreadsheet cell. Different font sizes achieve a different pixel count.

 

countexample.PNG

 

The output file tells you the pixel location in the the terms of  how many rows from the top and how many columns from the left margin. The length is how far to the right of that location the pixel extends.

 

 

 

I think TeFerrel scales depending on the dimensions of the book (or the number of pages). The word "Love" would require much less pixels for a paperback novel than it would in the monstrous textbook TeFerrel used.  My "test" example is only 12 pixels wide. If the book has is 2 inches wide then  I assume 6 pixels per inch (2 pixels per cm) or less is appropriate..

Edited by TechnoRobbo

Go out there and be amazing. Have Fun, TR
TRsSig.png?raw=1
Some Pretty Pictures Some Cool Plugins

Link to comment
Share on other sites

  • 1 month later...

The pixel count worked great on my first try but recently when using it there are some problems.  around column 40 the count is waaaay off, like 24 pixels longer than it should be.  When checking back to the image in paintnet, the image looks correct and I have no idea why it would do this.  I am deleting the plugin and reinstalling to see if that helps.  Anyone else have this problem?

Link to comment
Share on other sites

  • 4 weeks later...

I am hoping someone can pinpoint a problem I am having with the pixelcount plugin.  If I have multiple layers it seems to create problems with the count.  Also I recently imported an image and after preparing it and running the pixelcount plugin it ignored pixels that were in the lower half of the image.  If someone can help with this I can email the pdn file since I can't figure out how to attach it here.  Thanks!

Link to comment
Share on other sites

I am having trouble with the pixelcounter plugin and after posting under the topic "counting filled cells" and not getting responses and asking for help in the facebook group I was advised to post here.

Normally when running the plugin after using only text I have no problem however when importing an image (in this case the map of Michigan) the pixelcounter ignored the lower half of the pixels in the image.  I am hoping someone might be able to explain why.....maybe the creator of the plugin?

 

I cant upload the pdn file here but I have attached the pixelcount text as well as the original image used.  I have also attached an example of the folded books.  Thanks!

pixelcount michigan.txt

post-133291-0-74044700-1392417544_thumb.

post-133291-0-46201300-1392417984_thumb.

Link to comment
Share on other sites

I've merged these threads together to keep this discussion in one place.

I'm sure TechnoRobbo will be along shortly to give you some guidance :)

Link to comment
Share on other sites

I'm sorry I've been extremely busy. I'll have a look.

 

pixelcounter relies on white bordering the image - Go to the image menu - select canvas size,  add 2 pixels to the height and width, anchor in the middle and everything will workout fine.

Capture%20%281%29.PNG?raw=1

 

 

Edited by TechnoRobbo

Go out there and be amazing. Have Fun, TR
TRsSig.png?raw=1
Some Pretty Pictures Some Cool Plugins

Link to comment
Share on other sites

pdnoob:  the section you have highlighted is an area that I change based on the sheets of pages in the book as well as the height of the book.  Say a book is 23.5 cm tall and has 279 sheets the pixel width would be 279 and the pixel height would the 23.5 multiplied by 12.   Should I shrink the image to fall under these dimensions?

Link to comment
Share on other sites

I added 2 pixels to pixel size under the Canvas Size Dialog to add a white border to the image

 

you can send the file to this temporary account: heather@technorobbo.com

 

I'll delete it when I receive the file.

Edited by TechnoRobbo

Go out there and be amazing. Have Fun, TR
TRsSig.png?raw=1
Some Pretty Pictures Some Cool Plugins

Link to comment
Share on other sites

Canvas Size Dialog

My bad. I took a screenshot of the wrong window.

Either way, it's still the "pixels" part of the canvas size dialog that you're supposed to change.

 

what I do all summer Emote Cursor Pack 'noob gallery

No, Paint.NET is not spyware...but, installing it is an IQ test. ~BoltBait

Blend modes are like the filling in your sandwich. It's the filling that can change your experience of the sandwich. ~Ego Eram Reputo

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...