The how of bitmap images

I’m new to Kicad , linux and photoshop but not PCBs (altium) and so i’m floundering a bit. I also bought the ebook “Kicad like a pro” that has the V7 update but what I want to do is sparsely covered.

My objective is to reverse engineer a 4 layer PCB to create a schematic. I realise that while Kicad has some support for this (bitmap images), it is a new addition and probably not a priority feature.

I have scanned the physical sanded depopulated PCB and have loaded the 4 layer images into Kicad.

Well, that is the background covered.

Are there any advantages or disadvantages picking which layers i put the bitmaps on or are they much the same as each other?

I noticed that the images i made were not very good and needed sizing, cropping etc prior to Kicad but as a first try i was happy, but i’m having difficulty moving the images into some aligned state over each other. I don’t seem to me able to pick a reference point on the image and move it stepwise successfully using the keyboard.

I put this part of the project on the back burner due to frustration and moved onto making the BOM in Excel.

Could someone please tell me why i’m having problems?
Is it me or is bitmap image positioning immature at this stage and I need to wait some time.

I realise i have rambled on somewhat but here is the crux

I have 4 images on different layers. Each has a common feature (mounting hole) how do i move the images to be aligned at that feature? Please understand i know that I will have to remake the bitmaps externally to be the correct size etc and reload them but what us the point if i cannot move them around properly.

Bob

This feature of KiCad is not something I can advise on, while waiting for someone who can this might be a solution or at least a help.

If you have Photoshop you can load all your 4 images in to one image in Photoshop on different layers, then you can individually align and scal the layers so they line up sufficiently well to be used. Then crop all layers together and export the layers one by one to different images.

You will the have your 4 layers registered and scale the same . . . that must make them easier to work with in KiCad

Now that is funny. I was postponing a response because I already saw someone else was making a response.

What do you mean with “not very good”. The quality of your pictures is a mayor point in a reverse-engineering project. The best option is to use a flatbed scanner because it produces the least distortion over the area of the pictures, the next best thing is to use a (decent) camera and make the pictures from a long physical distance to reduce perspective errors and lens distortions. But cameras also introduce other errors. Shadows, reflections and such are also mayor things to avoid. Making suitable pictures is a (small) art in itself and needs practice. So spend some time on it, and make new pictures if they do not look clear on your PC.

This seems like a waste of time to me. In KiCad, the schematic is the reference. I would start with putting schematic symbols on the schematic, and assigning footprints to them. After that you can draw wires on the schematic, and copper tracks on the PCB. And once you are ready, just export the BOM to whatever format suits you. Also, if you put all the footprints on the PCB over the pictures, you get a quite nice overview of the missing footprints.

You are right in that loading a background picture is a new and not well developed feature. Reverse engineering is also a niche part of PCB design, and it’s not a high priority for the KiCad developers (Among the 1900 open issues on gitlab, there are 552 “feature-requests”)

I have done it a few times (with mostly simple PCB’s such as breadboard breakout boards for a single ic), and I am also still figuring out the workflow that works best. The last time I put the pictures on User.1 and User.2 and I renamed those layers in the board setup to TOP_JPG and BOTTOM_JPG. This gives you independent control over showing the pictures.

Scaling can be done accurately in KiCad. First, you can select the picture, and drag one of the small squares in the corners to get it roughly correct. After that you can press e to edit the properties of the picture, and enter a number for the scale in the Image tab.

Positioning can be done accurately in KiCad, by first measuring the distance you want to move the picture, then right click on the picture and use Positioning Tools / Move Exactly, Move with Reference or one of the other positioning tools. It is a bit annoying that as soon as a picture is selected, it gets pulled to the front and opacity is set to 0 so you can’t see anything else while moving the picture. (So Move Exactly with previously noted coordinates works probably best). Another and simpler way to position the picture is to just edit the properties of the bitmap and modify the X and Y coordinates.

I do not know how big and complex your 4 layer PCB is, but the right preprocessing can save a lot of work. I am not very good with pixel programs, but can do a few simple things in Gimp. I have not done this yet, but I think it would be beneficial (for a more complex project) to first get “somewhat decent” background pictures in KiCad, then draw the outline of your PCB and a bunch of reference point as a star map across it’s surface. Via’s are good to use, because they go through all layers. After that you can export or “Print to File” the PCB and open it as a layer in some graphical program, and you can use it as a reference to do corrections to the pictures to reverse distortions. And then of course put the better pictures in KiCad. If your pictures are very good and free of distortions, retracing them in KiCad becomes easier too. I also like RaptorUK’s idea of cropping all pictures together in a pixel program, so location and scale factor will be the same for all of them in KiCad.

1 Like

Actually there’s a more effective way, and this reminds me that this should be a built-in feature which would make it intuitive and easy.

First, the image scale should be 1. Then use the ruler tool to measure some distance in the image of which you know what it should be in the physical board, for example a distance between two mounting holes or width or length of the board or distance between two known component pins. It is now something else in the image. But the scale can be easily calculated: [real physical dimension]/[measured dimension in the KiCad canvas]. That should give you the new scale value.

It would be handy if this would be supported directly in the UI, at least the values input and calculation. Currently the dialog doesn’t even support math calculation like many other input widgets in KiCad.

This could also be supported interactively in the drawing canvas, but it would require being able to lock some point of the image to some coordinate point in the canvas. Now when you drag the image larger/smaller you can’t keep the reference point to match it with for example a dimension item of KiCad.

At least in v7.99 this is easier. Put the cursor to the correct location of the selected image, press M to move it, move the cursor – only a thin frame is moved and other things in the layout are visible, and the image can originally be located far from other items. You can move the wanted point of the image to the wanted point in the design easily.

I commented on pcbnew bitmap image scaling makes it hard to produce an aligned image (#8488) · Issues · KiCad / KiCad Source Code / kicad · GitLab.

This does not work very well because of image distortions (when made by a camera). It may work when a flatbed scanner is used.

I have also done a few image calibrations in FreeCAD, and my experience, it works best if you are able to average out a bunch of references. For example draw (exact, measured) the PCB outline and a few other references (IC’s, fiducials, via’s, whatever) and mark them on the PCB, and then use iterative corrections to get the scale of your bitmap pictures right. I am quite content with the scaling and position corrections as offered by KiCad. The only annoying thing is the picture getting pulled to the front as soon as it gets selected, so you can’t drag and scale to match other references.

This also does not work well when trying to average out multiple references.
Unfortunately I am having trouble with the Nightlies, (they are stuck on 2023-06-12. Linux Mint won’t update beyond that) so I can’t look at a current nightly now.

But overall I Like RaptorUK’s method better. Make sure the pictures all have the exact same scale in some external program, then import them, and re-create the PCB in KiCad in whatever location the pictures end up.

A small script in KiCad may also be useful. You can have a few saved offsets, depending on whether you are working on the upper left corner or the lower right corner of the PCB, and then shift the images accordingly to correct for distortions.

1 Like

I can understand this is a practical, complex problem and KiCad users can’t assure the image is already perfect. However, should KiCad still help with situations when the image actually is “perfect” for its purpose except for scaling? The question can be compared with complex board outlines – who is responsible, KiCad, 3rd party SW, the end user, two or three of them? I would say that image distortion should be corrected by the end user with a 3rd party SW if it’s not a simple task, and be supported by KiCad if it’s simple enough.

For reference, see GIMP’s 4.8. Lens Distortion and 4.8. Perspective. In my opinion it’s enough if KiCad supports simple scaling in an easy way, but I wouldn’t oppose adding simple support for “average scaling” where the end user could give several measured values from different locations (from the middle and from the far edges of the image) and KiCad would scale according to the average. But KiCad shouldn’t support complex image manipulation functions.

IMO it would be enough if KiCad supported scaling otherwise “perfect” images. Pure scaling according to “real” DPI is a specialized function which would be relatively simple in KiCad programmatically and UI wise, but for certain reasons not an everyday task for non-specialists or even specialists who handle photos. Photography specialists, on the other hand, deal with distortions, perspective and rotation all the time, but – maybe surprisingly – don’t care about scaling or DPI.

(EDIT: by “scaling” I mean for purposes of KiCad, not pixel size scaling in image manipulation which affects the pixel resolution of the image file.)

I don’t understand how it would be better if you criticize my approach for not being good for distorted images. The only thing better in the other method, if I understand this correctly, is that it imports several images which then don’t have to be changed individually in KiCad. But someone has to edit them beforehand. It doesn’t change much if they are not good for KiCad after editing.

Maybe this whole problem needs a tutorial with GIMP or something like that if KiCad isn’t and can’t be enough?

I agree the difference would be small.

There are a lot of things you can do with pixel programs to aid with the reverse-engineering. From contrast enhancement to deleting background colors wit transparency, and using “local” deformations to compensate for picture distortions. You will also need a pixel program to mirror the bottom layers.

There are a few (Youtube among others) tutorials of pre-processing images before doing the reverse-eingineering part. Having some knowledge of one of those pixel progams sure is an advantage for a thing like this.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.